LoRaGateway_BTS2A/fakeStation/fakeStation.ino

84 lines
1.7 KiB
Arduino
Raw Normal View History

2018-05-14 11:59:13 +02:00
#include <SPI.h>
2018-05-03 11:03:18 +02:00
#include <LoRa.h>
2018-05-02 10:41:24 +02:00
2018-05-23 08:55:25 +02:00
typedef struct
{
uint8_t ids = 0x45;
uint8_t idp = 0x00;
uint16_t ts = 0x0000;
uint16_t dt = 0x0001;
uint16_t d1 = 0x0000;
uint16_t d2 = 0x0000;
uint16_t d3 = 0x0000;
}message;
2018-05-02 10:41:24 +02:00
2018-05-23 08:55:25 +02:00
message msg;
2018-04-25 11:28:25 +02:00
2018-05-14 11:59:13 +02:00
void setup() {
2018-05-23 08:55:25 +02:00
SerialUSB.begin(9600);
2018-05-14 11:59:13 +02:00
while (!Serial);
2018-05-23 08:55:25 +02:00
SerialUSB.println("LoRa Sender");
2018-05-03 17:13:20 +02:00
2018-05-23 08:55:25 +02:00
if (!LoRa.begin(868E6))
{
SerialUSB.println("Starting LoRa failed!");
while(1);
2018-04-25 11:28:25 +02:00
}
2018-05-03 17:13:20 +02:00
}
2018-04-23 21:24:05 +02:00
2018-05-23 08:55:25 +02:00
void loop()
{
msg.ts = msg.ts + 1;
msg.d1 = random(20, 40);
msg.d2 = random(40, 60);
msg.d3 = random(0, 100);
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);
2018-05-03 17:13:20 +02:00
2018-05-23 08:55:25 +02:00
SerialUSB.print("Donnee 3 : ");
SerialUSB.print(msg.d3, DEC);
SerialUSB.print(", ");
SerialUSB.println(msg.d3, HEX);
SerialUSB.println(" ");
2018-05-26 20:00:37 +02:00
for(int i=0; i<3; i++){
SerialUSB.println("Sending packet !");
LoRa.beginPacket();
LoRa.write((uint8_t*)&msg, 12);
LoRa.endPacket();
SerialUSB.println("-----------------------------");
delay(4000);
}
delay(10000);
2018-05-03 17:13:20 +02:00
}