RadioLib/examples/Node1/Node1.ino

89 wiersze
1.9 KiB
Arduino
Czysty Zwykły widok Historia

2018-03-09 19:15:35 +00:00
#include "KiteLib.h"
2018-03-31 08:12:33 +00:00
XBee bee = Kite.ModuleA;
RF69 rf = Kite.ModuleB;
2018-03-09 19:15:35 +00:00
Packet pack;
void setup() {
Serial.begin(9600);
2018-03-31 08:12:33 +00:00
Serial.print("[XBee] Initializing ... ");
byte state = bee.begin(9600);
2018-03-09 19:15:35 +00:00
if(state == ERR_NONE) {
Serial.println("success!");
} else {
Serial.print("failed, code 0x");
Serial.println(state, HEX);
while(true);
}
2018-04-02 11:23:44 +00:00
Serial.print("[XBee] Setting PAN ID ... ");
state = bee.setPanId("0123456789ABCDEF");
if(state == ERR_NONE) {
Serial.println("success!");
} else {
Serial.print("failed, code 0x");
Serial.println(state, HEX);
while(true);
}
2018-03-31 08:12:33 +00:00
Serial.print("[XBee] Setting destination address ... ");
state = bee.setDestinationAddress("0013A200", "40A58A5D");
if(state == ERR_NONE) {
Serial.println("success!");
} else {
Serial.print("failed, code 0x");
Serial.println(state, HEX);
while(true);
}
Serial.print("[RF69] Initializing ... ");
state = rf.begin();
if(state == ERR_NONE) {
Serial.println("success!");
} else {
Serial.print("failed, code 0x");
Serial.println(state, HEX);
while(true);
}
2018-03-09 19:15:35 +00:00
}
void loop() {
2018-03-31 08:12:33 +00:00
Serial.print("[RF69] Waiting for incoming transmission ... ");
byte state = rf.receive(pack);
2018-04-02 11:23:44 +00:00
bee.println("Hello World!");
2018-03-09 19:15:35 +00:00
if(state == ERR_NONE) {
Serial.println("success!");
char str[24];
pack.getSourceStr(str);
2018-03-31 08:12:33 +00:00
Serial.print("[RF69] Source:\t\t");
2018-03-09 19:15:35 +00:00
Serial.println(str);
pack.getDestinationStr(str);
2018-03-31 08:12:33 +00:00
Serial.print("[RF69] Destination:\t");
2018-03-09 19:15:35 +00:00
Serial.println(str);
2018-03-31 08:12:33 +00:00
Serial.print("[RF69] Length:\t\t");
2018-03-09 19:15:35 +00:00
Serial.println(pack.length);
2018-03-31 08:12:33 +00:00
Serial.print("[RF69] Data:\t\t");
2018-03-09 19:15:35 +00:00
Serial.println(pack.data);
2018-03-31 08:12:33 +00:00
Serial.print("[XBee] Sending packet ... ");
bee.println(pack.data);
Serial.println("done!");
2018-03-09 19:15:35 +00:00
} else if(state == ERR_RX_TIMEOUT) {
Serial.println("timeout!");
} else if(state == ERR_CRC_MISMATCH) {
Serial.println("CRC error!");
}
}