Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup()
- {
- // Start the serial ports ...
- Serial.begin( 9600 );
- while( !Serial ){;} // Wait for serial port (for Leonardo only).
- xbeeSerial.begin( 9600 );
- // ... and set the serial port for the XBee radio.
- xbee.setSerial( xbeeSerial );
- // Set a non-zero frame id to receive Status packets.
- xbee.setAcknowledgement(true);
- }
- void loop()
- {
- // Each SimpleZigBeeRadio instance contains two
- // SimpleZigBeePacket instances, one for storing incoming
- // messages and one for preparing outgoing messages.
- // This example will not send any messages to the network.
- // Rather, the coordinator will receive messages and display
- // the contents to the hardware serial port.
- // While data is waiting in the XBee serial port ...
- while( xbee.available() )
- {
- // ... read the data.
- xbee.read();
- // If a complete message is available, display the contents
- if( xbee.isComplete() ){
- Serial.print("nIncoming Message: ");
- printPacket( xbee.getIncomingPacketObject() );
- }
- }
- delay(10); // Small delay for stability
- // That's it! The coordinator is ready to go.
- }
- // Function for printing the complete contents of a packet //
- void printPacket(SimpleZigBeePacket & p)
- {
- Serial.print( START, HEX );
- Serial.print(' ');
- Serial.print( p.getLengthMSB(), HEX );
- Serial.print(' ');
- Serial.print( p.getLengthLSB(), HEX );
- Serial.print(' ');
- // Frame Type and Frame ID are stored in Frame Data
- uint8_t checksum = 0;
- for( int i=0; i<p.getFrameLength(); i++){
- Serial.print( p.getFrameData(i), HEX );
- Serial.print(' ');
- checksum += p.getFrameData(i);
- }
- // Calculate checksum based on summation of frame bytes
- checksum = 0xff - checksum;
- Serial.print(checksum, HEX );
- Serial.println();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement