Communication
Some concepts going over how the XBee modules communicate with the Make Controller.
The XBee modules have two modes of operation:
- Transparent serial port mode. This mode is the simplest - you send data over a Make Controller's serial port to an XBee module which sends that data wirelessly to another XBee module, also presumably connected to a Make Controller, which can then read the data from the serial port. So, it's like a big, wireless serial connection between the two Make Controllers, hence the name. Clever, eh?
- Packet mode. If you want to actually send messages to the XBee module itself, however, you need a way to distinguish that from data that should be sent transparently. There are a few different kinds of packets, but we'll most concern ourselves here with IO packets and command packets. IO packets are what an XBee module sends when it has sampled its inputs. Command packets are used to set some configuration option for the module itself. Packet mode is nice because then we get to see a bunch of important information about each packet - who it came from, the signal strength, and things like that.
Receiving Packets
For the most part, incoming packets aren't too interesting if they just show up at your XBee module - unless they're directly controlling its output pins, for example. Otherwise, you'll want to get the info in the incoming packet to the Make Controller and/or up to your computer. If you're doing this in firmware, all you need is the XBee_GetPacket( ) function. Over OSC, however, you have a couple options:- You can periodically send the Make Controller a request for new packets. If any have arrived, since you last asked they'll be sent back to you. Unfortunately, the problem with this is that the Make Controller only has room to hang onto a couple of packets at a time - any packets that arrive after it's full will be lost. To get around this,
- You can use the autosend capability. The Make Controller itself will constantly be checking for new packets and when one arrives, it will send it out automatically. To do this, turn autosend on by sending the message
/xbee/autosend 1
Then, you need to set how often you want the Make Controller to check for new messages, and whether to send it over Ethernet (Udp) or USB.
/system/autosend-interval 10
/system/autosend-usb 1So we just set it to check for new messages every 10 milliseconds (100 times a second) and to send those messages over USB. If we wanted them to be sent over Ethernet, we would send the message
/system/autosend-udp 1

