From 19840f824941f67ec9e76fa65a3651abbbd68519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Grome=C5=A1?= Date: Thu, 19 Jul 2018 16:22:19 +0200 Subject: [PATCH] XBee - Added API transmit example --- examples/XBee_Transmit/XBee_Transmit.ino | 57 ++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 examples/XBee_Transmit/XBee_Transmit.ino diff --git a/examples/XBee_Transmit/XBee_Transmit.ino b/examples/XBee_Transmit/XBee_Transmit.ino new file mode 100644 index 00000000..078fc1c8 --- /dev/null +++ b/examples/XBee_Transmit/XBee_Transmit.ino @@ -0,0 +1,57 @@ +/* + * KiteLib XBee API Transmit Example + * + * This example transmits packets using XBee API mode. + * In API mode, many XBee modules can form a mesh network. + * + * IMPORTANT: Before uploading this example, make sure that the XBee module + * is running API COORDINATOR firmware! + */ + +// include the library +#include + +// XBee module is in slot A on the shield +XBee bee = Kite.ModuleA; + +void setup() { + Serial.begin(9600); + + // initialize XBee module with baudrate 9600 + Serial.print(F("[XBee] Initializing ... ")); + byte state = bee.begin(9600); + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code 0x")); + Serial.println(state, HEX); + while(true); + } + + // set PAN ID to 0x0123456789ABCDEF + Serial.print(F("[XBee] Setting PAN ID ... ")); + uint8_t panId[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; + state = bee.setPanId(panId); + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code 0x")); + Serial.println(state, HEX); + while(true); + } +} + +void loop() { + // transmit data to the destination module + uint8_t dest[] = {0x00, 0x13, 0xA2, 0x00, + 0x40, 0xA5, 0x8A, 0x6B}; + Serial.print(F("[XBee] Transmitting message ... ")); + byte state = bee.transmit(dest, "Hello World!"); + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code 0x")); + Serial.println(state, HEX); + } +}