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 "led.h"
|
||||||
#include "sim5215_umts_shield.h"
|
#include "sim5215_umts_shield.h"
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <LoRa.h>
|
||||||
|
|
||||||
Shield shield(5,3,4);
|
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() {
|
void setup() {
|
||||||
|
// Initialisation du moniteur série
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial);
|
||||||
|
|
||||||
|
// Initialisation des leds
|
||||||
|
Serial.println("Initialisation LEDs");
|
||||||
initLed(Green, 8);
|
initLed(Green, 8);
|
||||||
initLed(Blue, 7);
|
initLed(Blue, 7);
|
||||||
initLed(Red, 6);
|
initLed(Red, 6);
|
||||||
|
|
||||||
|
// Début de l'initialisation
|
||||||
|
Serial.println("Start initialisation");
|
||||||
blinkLed(Green);
|
blinkLed(Green);
|
||||||
|
|
||||||
|
// Initialisation de shield
|
||||||
|
Serial.println("Initialisation shield UMTS");
|
||||||
shield.power_on();
|
shield.power_on();
|
||||||
shield.init("0000", "", "", "");
|
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);
|
turnOnLed(Green);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void receiveLoRa(struct message * msg) {
|
||||||
turnOnLed(Red);
|
int packetSize = LoRa.parsePacket();
|
||||||
shield.sendTextMessage("0659377414", "Led RED ON");
|
if (packetSize) {
|
||||||
turnOffLed(Red);
|
turnOnLed(Blue);
|
||||||
delay(10000);
|
Serial.print("Received packet '");
|
||||||
|
|
||||||
turnOnLed(Blue);
|
while (LoRa.available()) {
|
||||||
shield.sendTextMessage("0659377414", "Led BLUE ON");
|
String stringData = LoRa.readString();
|
||||||
turnOffLed(Blue);
|
const char* LoRaData = stringData.c_str();
|
||||||
delay(10000);
|
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