XBee - updated example

This commit is contained in:
Jan Gromeš 2018-07-24 09:47:05 +02:00
parent 0a32e985bf
commit 305ee6e6ed

View file

@ -1,12 +1,12 @@
/* /*
* KiteLib XBee API Transmit Example KiteLib XBee API Transmit Example
*
* This example transmits packets using XBee API mode. This example transmits packets using XBee API mode.
* In API mode, many XBee modules can form a mesh network. In API mode, many XBee modules can form a mesh network.
*
* IMPORTANT: Before uploading this example, make sure that the XBee module IMPORTANT: Before uploading this example, make sure that the XBee module
* is running API COORDINATOR firmware! is running API COORDINATOR firmware!
*/ */
// include the library // include the library
#include <KiteLib.h> #include <KiteLib.h>
@ -20,12 +20,12 @@ void setup() {
// initialize XBee module with baudrate 9600 // initialize XBee module with baudrate 9600
Serial.print(F("[XBee] Initializing ... ")); Serial.print(F("[XBee] Initializing ... "));
int state = bee.begin(9600); int state = bee.begin(9600);
if(state == ERR_NONE) { if (state == ERR_NONE) {
Serial.println(F("success!")); Serial.println(F("success!"));
} else { } else {
Serial.print(F("failed, code ")); Serial.print(F("failed, code "));
Serial.println(state); Serial.println(state);
while(true); while (true);
} }
// set PAN ID to 0x0123456789ABCDEF // set PAN ID to 0x0123456789ABCDEF
@ -33,12 +33,12 @@ void setup() {
uint8_t panId[] = {0x01, 0x23, 0x45, 0x67, uint8_t panId[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF}; 0x89, 0xAB, 0xCD, 0xEF};
state = bee.setPanId(panId); state = bee.setPanId(panId);
if(state == ERR_NONE) { if (state == ERR_NONE) {
Serial.println(F("success!")); Serial.println(F("success!"));
} else { } else {
Serial.print(F("failed, code ")); Serial.print(F("failed, code "));
Serial.println(state); Serial.println(state);
while(true); while (true);
} }
} }
@ -48,10 +48,12 @@ void loop() {
0x40, 0xA5, 0x8A, 0x6B}; 0x40, 0xA5, 0x8A, 0x6B};
Serial.print(F("[XBee] Transmitting message ... ")); Serial.print(F("[XBee] Transmitting message ... "));
int state = bee.transmit(dest, "Hello World!"); int state = bee.transmit(dest, "Hello World!");
if(state == ERR_NONE) { if (state == ERR_NONE) {
Serial.println(F("success!")); Serial.println(F("success!"));
} else { } else {
Serial.print(F("failed, code ")); Serial.print(F("failed, code "));
Serial.println(state); Serial.println(state);
} }
delay(1000);
} }