Added Arduino codes for 4-node chain
This commit is contained in:
parent
a12d8472f5
commit
9e5655b028
4 changed files with 235 additions and 0 deletions
52
examples/Node0/Node0.ino
Normal file
52
examples/Node0/Node0.ino
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "KiteLib.h"
|
||||
|
||||
HC05 bluetooth = Kite.ModuleA;
|
||||
SX1278 lora = Kite.ModuleB;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
bluetooth.begin(9600);
|
||||
Serial.println("[HC05] Port open!");
|
||||
|
||||
Serial.print("[SX1278] Initializing ... ");
|
||||
byte state = lora.begin();
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println("success!");
|
||||
} else {
|
||||
Serial.print("failed, code 0x");
|
||||
Serial.println(state, HEX);
|
||||
while(true);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
bool receivedFlag = false;
|
||||
String receivedString;
|
||||
|
||||
Serial.println("[HC05] Waiting for incoming data ...");
|
||||
while(bluetooth.available() > 0) {
|
||||
char receivedCharacter = bluetooth.read();
|
||||
receivedString += receivedCharacter;
|
||||
if(receivedCharacter == '\n') {
|
||||
Serial.print("[HC05] Received string: ");
|
||||
Serial.println(receivedString);
|
||||
receivedFlag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(receivedFlag) {
|
||||
receivedFlag = false;
|
||||
Packet pack("01:23:45:67:89:AB:CD:EF", receivedString.c_str());
|
||||
Serial.print("[SX1278] Transmitting packet ... ");
|
||||
byte state = lora.transmit(pack);
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println("success!");
|
||||
} else {
|
||||
Serial.print("failed, code 0x");
|
||||
Serial.println(state, HEX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
70
examples/Node1/Node1.ino
Normal file
70
examples/Node1/Node1.ino
Normal file
|
@ -0,0 +1,70 @@
|
|||
#include "KiteLib.h"
|
||||
|
||||
SX1278 lora = Kite.ModuleA;
|
||||
XBee bee = Kite.ModuleB;
|
||||
|
||||
Packet pack;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
Serial.print("[SX1278] Initializing ... ");
|
||||
byte state = lora.begin();
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println("success!");
|
||||
} else {
|
||||
Serial.print("failed, code 0x");
|
||||
Serial.println(state, HEX);
|
||||
while(true);
|
||||
}
|
||||
|
||||
bee.begin(9600);
|
||||
Serial.println("[XBee] Port open!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.print("[SX1278] Waiting for incoming transmission ... ");
|
||||
byte state = lora.receive(pack);
|
||||
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println("success!");
|
||||
|
||||
char str[24];
|
||||
|
||||
pack.getSourceStr(str);
|
||||
Serial.print("[SX1278] Source:\t\t");
|
||||
Serial.println(str);
|
||||
|
||||
pack.getDestinationStr(str);
|
||||
Serial.print("[SX1278] Destination:\t");
|
||||
Serial.println(str);
|
||||
|
||||
Serial.print("[SX1278] Length:\t\t");
|
||||
Serial.println(pack.length);
|
||||
|
||||
Serial.print("[SX1278] Data:\t\t");
|
||||
Serial.println(pack.data);
|
||||
|
||||
Serial.print("[SX1278] Datarate:\t");
|
||||
Serial.print(lora.dataRate);
|
||||
Serial.println(" bps");
|
||||
|
||||
Serial.print("[SX1278] RSSI:\t\t");
|
||||
Serial.print(lora.lastPacketRSSI);
|
||||
Serial.println(" dBm");
|
||||
|
||||
Serial.print("[XBee] Sending packet ...");
|
||||
state = bee.send(0x0013A200, 0x40A58A62, pack.data);
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println("success!");
|
||||
}
|
||||
|
||||
} else if(state == ERR_RX_TIMEOUT) {
|
||||
Serial.println("timeout!");
|
||||
|
||||
} else if(state == ERR_CRC_MISMATCH) {
|
||||
Serial.println("CRC error!");
|
||||
|
||||
}
|
||||
}
|
||||
|
28
examples/Node2/Node2.ino
Normal file
28
examples/Node2/Node2.ino
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include "KiteLib.h"
|
||||
|
||||
XBee bee = Kite.ModuleA;
|
||||
RF69 rf = Kite.ModuleB;
|
||||
|
||||
Packet pack;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
bee.begin(9600);
|
||||
Serial.println("[XBee] Port open!");
|
||||
|
||||
Serial.print("[RF69] Initializing ... ");
|
||||
byte state = rf.begin();
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println("success!");
|
||||
} else {
|
||||
Serial.print("failed, code 0x");
|
||||
Serial.println(state, HEX);
|
||||
while(true);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
85
examples/Node3/Node3.ino
Normal file
85
examples/Node3/Node3.ino
Normal file
|
@ -0,0 +1,85 @@
|
|||
#include "KiteLib.h"
|
||||
|
||||
RF69 rf = Kite.ModuleA;
|
||||
ESP8266 wifi = Kite.ModuleB;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
Serial.print("[RF69] Initializing ... ");
|
||||
byte state = rf.begin();
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println("success!");
|
||||
} else {
|
||||
Serial.print("failed, code 0x");
|
||||
Serial.println(state, HEX);
|
||||
while(true);
|
||||
}
|
||||
|
||||
Serial.print("[ESP8266] Connecting ... ");
|
||||
byte state = wifi.begin(9600);
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println("success!");
|
||||
} else {
|
||||
Serial.print("failed, code 0x");
|
||||
Serial.println(state, HEX);
|
||||
while(true);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.print("[RF69] Waiting for incoming transmission ... ");
|
||||
byte state = rf.receive(pack);
|
||||
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println("success!");
|
||||
|
||||
char str[24];
|
||||
|
||||
pack.getSourceStr(str);
|
||||
Serial.print("[RF69] Source:\t\t");
|
||||
Serial.println(str);
|
||||
|
||||
pack.getDestinationStr(str);
|
||||
Serial.print("[RF69] Destination:\t");
|
||||
Serial.println(str);
|
||||
|
||||
Serial.print("[RF69] Length:\t\t");
|
||||
Serial.println(pack.length);
|
||||
|
||||
Serial.print("[RF69] Data:\t\t");
|
||||
Serial.println(pack.data);
|
||||
|
||||
Serial.print("[RF69] Datarate:\t");
|
||||
Serial.print(lora.dataRate);
|
||||
Serial.println(" bps");
|
||||
|
||||
Serial.print("[RF69] RSSI:\t\t");
|
||||
Serial.print(lora.lastPacketRSSI);
|
||||
Serial.println(" dBm");
|
||||
|
||||
Serial.print("[ESP266] Sending HTTP POST ...");
|
||||
String response;
|
||||
int http_code = wifi.HttpPost("http://www.httpbin.org/ip", response);
|
||||
if(http_code == 200) {
|
||||
Serial.println("success!");
|
||||
Serial.println("[ESP8266] Response:\n");
|
||||
Serial.println(response);
|
||||
} else {
|
||||
Serial.print("failed, code 0x");
|
||||
Serial.println(http_code, HEX);
|
||||
}
|
||||
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println("success!");
|
||||
}
|
||||
|
||||
} else if(state == ERR_RX_TIMEOUT) {
|
||||
Serial.println("timeout!");
|
||||
|
||||
} else if(state == ERR_CRC_MISMATCH) {
|
||||
Serial.println("CRC error!");
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Reference in a new issue