Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. void setup()
  2. {
  3. // Start the serial ports ...
  4. Serial.begin( 9600 );
  5. while( !Serial ){;} // Wait for serial port (for Leonardo only).
  6. xbeeSerial.begin( 9600 );
  7. // ... and set the serial port for the XBee radio.
  8. xbee.setSerial( xbeeSerial );
  9. // Set a non-zero frame id to receive Status packets.
  10. xbee.setAcknowledgement(true);
  11. }
  12.  
  13. void loop()
  14. {
  15. // Each SimpleZigBeeRadio instance contains two
  16. // SimpleZigBeePacket instances, one for storing incoming
  17. // messages and one for preparing outgoing messages.
  18. // This example will not send any messages to the network.
  19. // Rather, the coordinator will receive messages and display
  20. // the contents to the hardware serial port.
  21.  
  22. // While data is waiting in the XBee serial port ...
  23. while( xbee.available() )
  24. {
  25. // ... read the data.
  26. xbee.read();
  27. // If a complete message is available, display the contents
  28. if( xbee.isComplete() ){
  29. Serial.print("nIncoming Message: ");
  30. printPacket( xbee.getIncomingPacketObject() );
  31.  
  32. }
  33. }
  34.  
  35.  
  36. delay(10); // Small delay for stability
  37. // That's it! The coordinator is ready to go.
  38. }
  39.  
  40.  
  41.  
  42. // Function for printing the complete contents of a packet //
  43.  
  44. void printPacket(SimpleZigBeePacket & p)
  45. {
  46. Serial.print( START, HEX );
  47. Serial.print(' ');
  48. Serial.print( p.getLengthMSB(), HEX );
  49. Serial.print(' ');
  50. Serial.print( p.getLengthLSB(), HEX );
  51. Serial.print(' ');
  52. // Frame Type and Frame ID are stored in Frame Data
  53. uint8_t checksum = 0;
  54. for( int i=0; i<p.getFrameLength(); i++){
  55. Serial.print( p.getFrameData(i), HEX );
  56. Serial.print(' ');
  57. checksum += p.getFrameData(i);
  58. }
  59. // Calculate checksum based on summation of frame bytes
  60. checksum = 0xff - checksum;
  61. Serial.print(checksum, HEX );
  62. Serial.println();
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement