139 lines
3.2 KiB
C++
139 lines
3.2 KiB
C++
#include "led.h"
|
|
#include "sim5215_umts_shield.h"
|
|
#include <SPI.h>
|
|
#include <LoRa.h>
|
|
#include <stdio.h>
|
|
|
|
Shield shield(5,3,4);
|
|
|
|
const int pinNSS = 10;
|
|
const int pinRST = 9;
|
|
const int pinDIO0 = 2;
|
|
|
|
char num[] = "0659377414";
|
|
|
|
struct message {
|
|
int vers;
|
|
int type;
|
|
int cameraId;
|
|
float data;
|
|
};
|
|
|
|
struct message msg = {-1, -1, -1, 0.0};
|
|
|
|
void setup() {
|
|
// Initialisation du moniteur série
|
|
Serial.begin(115200);
|
|
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();
|
|
char pin[] = "0000";
|
|
char fournisseur[] = "mmsbouygtel.com";
|
|
char useless[] = "";
|
|
shield.init(pin, fournisseur, useless, useless);
|
|
|
|
// Initialisation LoRa
|
|
Serial.println("Initialisation LoRa transceiver");
|
|
LoRa.setPins(pinNSS, pinRST, pinDIO0);
|
|
while (!LoRa.begin(868E6)) {
|
|
Serial.print(".");
|
|
delay(500);
|
|
}
|
|
LoRa.setSyncWord(0x12);
|
|
|
|
// Notification de fin d'initialisation
|
|
Serial.println("Notification de l'utilisateur");
|
|
turnOnLed(Red);
|
|
char message[] = "Gateway initialised";
|
|
shield.sendTextMessage(num, message);
|
|
turnOffLed(Red);
|
|
|
|
|
|
// Fin de l'initialisation
|
|
Serial.println("Initialisation completed");
|
|
turnOnLed(Green);
|
|
}
|
|
|
|
void receiveLoRa() {
|
|
msg.vers = -1;
|
|
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();
|
|
int partie_entiere = 0;
|
|
int partie_decimale = 0;
|
|
sscanf(LoRaData, "%d-%d-%d-%d.%d", &(msg.vers), &(msg.type), &(msg.cameraId), &partie_entiere, &partie_decimale);
|
|
msg.vers = 1;
|
|
msg.type = 2;
|
|
msg.data = float(partie_entiere) + (float(partie_decimale))/100;
|
|
Serial.print(LoRaData);
|
|
Serial.print("");
|
|
}
|
|
|
|
// print RSSI of packet
|
|
Serial.print("' with RSSI ");
|
|
Serial.println(LoRa.packetRssi());
|
|
turnOffLed(Blue);
|
|
}
|
|
}
|
|
|
|
void printMessage() {
|
|
if (msg.vers > 0) {
|
|
Serial.println("Message : ");
|
|
Serial.print("\tVersion : ");
|
|
Serial.println(msg.vers);
|
|
Serial.print("\tType : ");
|
|
Serial.println(msg.type);
|
|
Serial.print("\tCamera ID : ");
|
|
Serial.println(msg.cameraId);
|
|
Serial.print("\tData : ");
|
|
Serial.println(msg.data);
|
|
Serial.println("");
|
|
}
|
|
}
|
|
|
|
void processMessage() {
|
|
if (msg.vers > 0) {
|
|
delay(50);
|
|
const char url[] = "rasp.pikouri.fr";
|
|
int port = 80;
|
|
//Event
|
|
if (msg.type == 1) {
|
|
//Rien
|
|
}
|
|
//Temperature
|
|
else if (msg.type == 2) {
|
|
char message[200];
|
|
String tempData = String(msg.data);
|
|
sprintf(message, "Temperature recue : %s", tempData.c_str());
|
|
Serial.println(message);
|
|
turnOnLed(Red);
|
|
shield.sendTextMessage(num, message);
|
|
turnOffLed(Red);
|
|
} else {
|
|
Serial.print("Type not indentified: ");
|
|
Serial.println(msg.type);
|
|
}
|
|
}
|
|
}
|
|
|
|
void loop() {
|
|
receiveLoRa();
|
|
processMessage();
|
|
}
|