Hardware Reference
In-Depth Information
Directed Messages
The more common way to use sessionless protocols is to send directed messages to
the object to which you want to speak. You saw this in action already in Chapter 6, when
you programmed your microcontrollers to speak to each other using XBee radios. Each
radio had a source address (which you read and set using the ATMY command) and a
destination address (which you read and set using the ATDL command). One radio's
destination was another's source, and vice versa. Though there were only two radios
in that example, you could have included many more radios, and decided which one to
address by changing the destination address on the fly.
Sending Directed UDP Datagrams
In the example at the beginning of this chapter, you sent
UDP datagrams between Processing and Arduino. The
Processing sketch sent a broadcast packet, and the
Arduinos sent a directed packet in response, by extracting
the sender's address from the packet. As long as you know
the address to which you want to send a datagram , it's
really that simple.
If you've got more than one Ethernet-connected device
(besides your personal computer), you can try this out
with the following Processing sketch. It's an expansion on
the broadcast sketch, allowing you to send both broadcast
and directed messages. Using the same Arduino UDP
query responder from before, try it on all the receiving
Arduino Ethernet-connected devices. When you type a , all
the receiving devices will respond. When you type b or c ,
only the one with that address will respond.
This sketch, along with
the Arduino UDP query
responder sketch, is a useful way to
test whether your network devices
are all working. It's a good idea to do
something simple like this to make
sure the network connections are good
before you try more complex sketches.
Send It
/*
UDP directed or broadcast query sender/receiver
Context: Processing
*/
// import the UDP library:
import hypermedia.net.*;
UDP udp; // initialize the UDP object
void setup() {
udp = new UDP( this, 43770 ); // open a UDP port
udp.listen( true ); // listen for incoming messages
}
void draw()
{
}
ยป
 
Search WWH ::




Custom Search