Gateway receiver
This commit is contained in:
parent
ee37c413c0
commit
6c5f6045b1
1 changed files with 74 additions and 10 deletions
|
@ -1,27 +1,91 @@
|
|||
#include "led.h"
|
||||
#include "sim5215_umts_shield.h"
|
||||
#include <SPI.h>
|
||||
#include <LoRa.h>
|
||||
|
||||
Shield shield(5,3,4);
|
||||
|
||||
const int pinNSS = 10;
|
||||
const int pinRST = 9;
|
||||
const int pinDIO0 = 2;
|
||||
|
||||
struct message {
|
||||
int vers;
|
||||
int type;
|
||||
int cameraId;
|
||||
float data;
|
||||
};
|
||||
|
||||
void setup() {
|
||||
// Initialisation du moniteur série
|
||||
Serial.begin(9600);
|
||||
while (!Serial);
|
||||
|
||||
// Initialisation des leds
|
||||
Serial.println("Initialisation LEDs");
|
||||
initLed(Green, 8);
|
||||
initLed(Blue, 7);
|
||||
initLed(Red, 6);
|
||||
|
||||
// Début de l'initialisation
|
||||
Serial.println("Start initialisation");
|
||||
blinkLed(Green);
|
||||
|
||||
// Initialisation de shield
|
||||
Serial.println("Initialisation shield UMTS");
|
||||
shield.power_on();
|
||||
shield.init("0000", "", "", "");
|
||||
|
||||
// Initialisation LoRa
|
||||
Serial.println("Initialisation LoRa transceiver");
|
||||
LoRa.setPins(pinNSS, pinRST, pinDIO0);
|
||||
while (!LoRa.begin(868E6)) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
LoRa.setSyncWord(0x12);
|
||||
|
||||
// Fin de l'initialisation
|
||||
Serial.println("Initialisation completed");
|
||||
turnOnLed(Green);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
turnOnLed(Red);
|
||||
shield.sendTextMessage("0659377414", "Led RED ON");
|
||||
turnOffLed(Red);
|
||||
delay(10000);
|
||||
|
||||
turnOnLed(Blue);
|
||||
shield.sendTextMessage("0659377414", "Led BLUE ON");
|
||||
turnOffLed(Blue);
|
||||
delay(10000);
|
||||
void receiveLoRa(struct message * msg) {
|
||||
int packetSize = LoRa.parsePacket();
|
||||
if (packetSize) {
|
||||
turnOnLed(Blue);
|
||||
Serial.print("Received packet '");
|
||||
|
||||
while (LoRa.available()) {
|
||||
String stringData = LoRa.readString();
|
||||
const char* LoRaData = stringData.c_str();
|
||||
sscanf(LoRaData, "%d-%d-%d-%f", &(msg->vers), &(msg->type), &(msg->cameraId), &(msg->data));
|
||||
Serial.print(LoRaData);
|
||||
Serial.print("");
|
||||
}
|
||||
|
||||
// print RSSI of packet
|
||||
Serial.print("' with RSSI ");
|
||||
Serial.println(LoRa.packetRssi());
|
||||
turnOffLed(Blue);
|
||||
}
|
||||
}
|
||||
|
||||
void printMessage(struct message msg) {
|
||||
Serial.println("Message : ");
|
||||
Serial.print("\tVersion : ");
|
||||
Serial.print(msg.vers);
|
||||
Serial.print("\tType : ");
|
||||
Serial.print(msg.type);
|
||||
Serial.print("\tCamera ID : ");
|
||||
Serial.print(msg.cameraId);
|
||||
Serial.print("\tData : ");
|
||||
Serial.println(msg.data);
|
||||
Serial.println("");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
struct message msg;
|
||||
receiveLoRa(&msg);
|
||||
printMessage(msg);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue