This commit is contained in:
Flavien Haas 2018-05-23 08:55:25 +02:00
parent c822463ef9
commit 1bc26701c1
4 changed files with 127 additions and 48 deletions

View File

@ -0,0 +1,51 @@
#include <SPI.h>
#include <LoRa.h>
typedef struct{ // frame structure
uint8_t IDs = 0; // station's ID
uint8_t IDp = 0; // gateway's ID
uint16_t TS = 0; // TimeStamp
uint16_t DT = 0; // Data Type
uint16_t D1 = 0; // DATA 1
uint16_t D2 = 0; // DATA 2
uint16_t D3 = 0; // DATA 3
} trame;
trame message;
uint16_t ID;
void setup() {
SerialUSB.begin(9600);
while (!SerialUSB){};
SerialUSB.println("LoRa Receiver");
if (!LoRa.begin(868E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop() {
int packetSize = LoRa.parsePacket();
if (packetSize > 0)
{
SerialUSB.println("Nouveau paquet");
message.IDs = LoRa.read();
message.IDp = LoRa.read();
message.IDp = 0x07;
message.TS = ((uint16_t)LoRa.read() | (LoRa.read() << 8));
message.DT = ((uint16_t)LoRa.read() | LoRa.read() << 8);
message.D1 = ((uint16_t)LoRa.read() | LoRa.read() << 8);
message.D2 = ((uint16_t)LoRa.read() | LoRa.read() << 8);
message.D3 = ((uint16_t)LoRa.read() | LoRa.read() << 8);
ID = (uint16_t)(message.IDs | message.IDp), HEX;
SerialUSB.println(ID, HEX);
SerialUSB.println(message.TS, HEX);
SerialUSB.println(message.DT, HEX);
SerialUSB.println(message.D1, HEX);
SerialUSB.println(message.D2, HEX);
SerialUSB.println(message.D3, HEX);
delay(100);
}
}

View File

@ -6,23 +6,23 @@ void setup() {
while (!SerialUSB){}; while (!SerialUSB){};
SerialUSB.println("LoRa Receiver"); SerialUSB.println("LoRa Receiver");
//if (!LoRa.begin(868E6)) { if (!LoRa.begin(868E6)) {
// Serial.println("Starting LoRa failed!"); Serial.println("Starting LoRa failed!");
// while (1); while (1);
//} }
} }
void loop() { void loop() {
int packetSize = LoRa.parsePacket(); int packetSize = LoRa.parsePacket();
if (packetSize > 0) { if (packetSize > 0) {
for (int i = 0; i < packetSize; i++) SerialUSB.println("Nouveau paquet");
for (int i = 0; i < packetSize; i++)
{ {
SerialUSB.println((char)LoRa.read()); SerialUSB.println(LoRa.read(),HEX);
} }
//Serial.print("with RSSi"); //Serial.print("with RSSi");
//Serial.println(LoRa.packetRssi()); //Serial.println(LoRa.packetRssi());
delay(100); delay(100);
} }
//SerialUSB.println("");
} }

View File

@ -1,54 +1,80 @@
#include <SPI.h> #include <SPI.h>
#include <LoRa.h> #include <LoRa.h>
typedef struct{ // frame structure typedef struct
uint16_t ID = 1025; // ID {
uint16_t TS = 0; // TimeStamp uint8_t ids = 0x45;
uint16_t DT = 0; // Data Type uint8_t idp = 0x00;
uint16_t D1 = 0; // DATA 1 uint16_t ts = 0x0000;
uint16_t D2 = 0; // DATA 2 uint16_t dt = 0x0001;
uint16_t D3 = 0; // DATA 3 uint16_t d1 = 0x0000;
}trame; uint16_t d2 = 0x0000;
uint16_t d3 = 0x0000;
}message;
trame message; message msg;
void setup() { void setup() {
Serial.begin(9600); SerialUSB.begin(9600);
while (!Serial); while (!Serial);
Serial.println("LoRa Sender"); SerialUSB.println("LoRa Sender");
message.ID = 0x0007; if (!LoRa.begin(868E6))
message.TS = 0x0001; {
message.DT = 0x0001; SerialUSB.println("Starting LoRa failed!");
message.D1 = 0x0026; while(1);
message.D2 = 0x0003;
message.D3 = 0x0004;
if (!LoRa.begin(868E6)) {
Serial.println("Starting LoRa failed!");
while (1);
} }
} }
void loop() { void loop()
Serial.print("Sending packet: "); {
msg.ts = msg.ts + 1;
msg.d1 = random(20, 40);
msg.d2 = random(40, 60);
msg.d3 = random(0, 100);
// send packet SerialUSB.print("ID station : ");
SerialUSB.print(msg.ids, DEC);
SerialUSB.print(", ");
SerialUSB.println(msg.ids, HEX);
SerialUSB.print("ID passerelle : ");
SerialUSB.print(msg.idp, DEC);
SerialUSB.print(", ");
SerialUSB.println(msg.idp, HEX);
SerialUSB.print("Numero de message : ");
SerialUSB.print(msg.ts, DEC);
SerialUSB.print(", ");
SerialUSB.println(msg.ts, HEX);
SerialUSB.print("Type de donne : ");
SerialUSB.print(msg.dt, DEC);
SerialUSB.print(", ");
SerialUSB.println(msg.dt, HEX);
SerialUSB.print("Donnee 1 : ");
SerialUSB.print(msg.d1, DEC);
SerialUSB.print(", ");
SerialUSB.println(msg.d1, HEX);
SerialUSB.print("Donnee 2 : ");
SerialUSB.print(msg.d2, DEC);
SerialUSB.print(", ");
SerialUSB.println(msg.d2, HEX);
SerialUSB.print("Donnee 3 : ");
SerialUSB.print(msg.d3, DEC);
SerialUSB.print(", ");
SerialUSB.println(msg.d3, HEX);
SerialUSB.println(" ");
SerialUSB.println("Sending packet !");
LoRa.beginPacket(); LoRa.beginPacket();
LoRa.write((uint8_t)(message.ID >> 8)); LoRa.write((uint8_t*)&msg, 12);
LoRa.write((uint8_t)message.ID);
LoRa.write((uint8_t)(message.TS >> 8));
LoRa.write((uint8_t)message.TS);
LoRa.write((uint8_t)(message.DT >> 8));
LoRa.write((uint8_t)message.DT);
LoRa.write((uint8_t)(message.D1 >> 8));
LoRa.write((uint8_t)message.D1);
LoRa.write((uint8_t)(message.D2 >> 8));
LoRa.write((uint8_t)message.D2);
LoRa.write((uint8_t)(message.D3 >> 8));
LoRa.write((uint8_t)message.D3);
LoRa.endPacket(); LoRa.endPacket();
delay(3000); SerialUSB.println("-----------------------------");
delay(4000);
} }

View File

@ -16,16 +16,18 @@ byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // set the mac addre
EthernetServer server(80); // initialize the EthernetServer library, using port 80 (default fot HTTP) EthernetServer server(80); // initialize the EthernetServer library, using port 80 (default fot HTTP)
typedef struct paquet_LoRa { // frame structure typedef struct { // frame structure
uint16_t ID = 1025; // ID uint16_t ID = 1025; // ID
uint16_t TS = 0; // TimeStamp uint16_t TS = 0; // TimeStamp
uint16_t DT = 0; // Data Type uint16_t DT = 0; // Data Type
uint16_t D1 = 0; // DATA 1 uint16_t D1 = 0; // DATA 1
uint16_t D2 = 0; // DATA 2 uint16_t D2 = 0; // DATA 2
uint16_t D3 = 0; // DATA 3 uint16_t D3 = 0; // DATA 3
} trame; } trame; // frame name
trame message; trame message; // creation of the frame message
uint16_t ID;
void setup(){ void setup(){
Serial.begin(9600); Serial.begin(9600);