Adapatation au test de connectivite
This commit is contained in:
parent
ae1f288d1c
commit
f5aaa47537
3 changed files with 25 additions and 30 deletions
|
@ -2,6 +2,7 @@
|
|||
#include "sim5215_umts_shield.h"
|
||||
#include <SPI.h>
|
||||
#include <LoRa.h>
|
||||
#include <stdio.h>
|
||||
|
||||
Shield shield(5,3,4);
|
||||
|
||||
|
@ -9,6 +10,8 @@ const int pinNSS = 10;
|
|||
const int pinRST = 9;
|
||||
const int pinDIO0 = 2;
|
||||
|
||||
char num[] = "0659377414";
|
||||
|
||||
struct message {
|
||||
int vers;
|
||||
int type;
|
||||
|
@ -36,7 +39,10 @@ void setup() {
|
|||
// Initialisation de shield
|
||||
Serial.println("Initialisation shield UMTS");
|
||||
shield.power_on();
|
||||
shield.init("0000", "mmsbouygtel.com", "", "");
|
||||
char pin[] = "0000";
|
||||
char fournisseur[] = "mmsbouygtel.com";
|
||||
char useless[] = "";
|
||||
shield.init(pin, fournisseur, useless, useless);
|
||||
|
||||
// Initialisation LoRa
|
||||
Serial.println("Initialisation LoRa transceiver");
|
||||
|
@ -46,6 +52,14 @@ void setup() {
|
|||
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");
|
||||
|
@ -62,9 +76,11 @@ void receiveLoRa() {
|
|||
while (LoRa.available()) {
|
||||
String stringData = LoRa.readString();
|
||||
const char* LoRaData = stringData.c_str();
|
||||
int partie_entiere;
|
||||
int partie_decimale;
|
||||
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("");
|
||||
|
@ -99,36 +115,16 @@ void processMessage() {
|
|||
int port = 80;
|
||||
//Event
|
||||
if (msg.type == 1) {
|
||||
char request[150];
|
||||
sprintf(request, "POST /api/cameras/%d/counter HTTP/1.1\r\nHost: rasp.pikouri.fr\r\n\r\n", msg.cameraId);
|
||||
Serial.println(request);
|
||||
turnOnLed(Red);
|
||||
shield.sendTextMessage("0672654516", "[Smart Camera 1] Funny bird detected!");
|
||||
if (shield.sendPOSTrequest(url, port, request, 20000) == 3) {
|
||||
shield.power_on();
|
||||
delay(1000);
|
||||
shield.power_on();
|
||||
shield.init("0000", "mmsbouygtel.com", "", "");
|
||||
} else {
|
||||
Serial.println("Request sent\n\n\n");
|
||||
}
|
||||
turnOffLed(Red);
|
||||
//Rien
|
||||
}
|
||||
//Temperature
|
||||
else if (msg.type == 2) {
|
||||
char request[200];
|
||||
char message[200];
|
||||
String tempData = String(msg.data);
|
||||
sprintf(request, "POST /api/cameras/%d/temperature HTTP/1.1\r\nHost: rasp.pikouri.fr\r\nContent-Type: application/json\r\nContent-Length: %d\r\n\r\n%s", msg.cameraId, tempData.length(),tempData.c_str());
|
||||
Serial.println(request);
|
||||
sprintf(message, "Temperature recue : %s", tempData.c_str());
|
||||
Serial.println(message);
|
||||
turnOnLed(Red);
|
||||
if (shield.sendPOSTrequest(url, port, request, 20000) == 3) {
|
||||
shield.power_on();
|
||||
delay(1000);
|
||||
shield.power_on();
|
||||
shield.init("0000", "mmsbouygtel.com", "", "");
|
||||
} else {
|
||||
Serial.println("Request sent\n\n\n");
|
||||
}
|
||||
shield.sendTextMessage(num, message);
|
||||
turnOffLed(Red);
|
||||
} else {
|
||||
Serial.print("Type not indentified: ");
|
||||
|
|
|
@ -24,7 +24,6 @@ int Shield::init(char pin_number[], char apn[], char user_name[], char password[
|
|||
|
||||
while( (sendATcommand("AT+CREG?", "+CREG: 0,1", 500) || sendATcommand("AT+CREG?", "+CREG: 0,5", 500)) == 0 );
|
||||
|
||||
Serial.print("Setting SMS mode...");
|
||||
sendATcommand("AT+CMGF=1", "OK", 1000); // sets the SMS mode to text
|
||||
|
||||
// sets APN, user name and password
|
||||
|
|
|
@ -15,7 +15,7 @@ const int pinRST = 9;
|
|||
const int pinDIO0 = 3;
|
||||
|
||||
volatile boolean movementState = false;
|
||||
volatile boolean mesurementState = false;
|
||||
volatile boolean mesurementState = true;
|
||||
|
||||
void setup() {
|
||||
// Initialisation du moniteur série
|
||||
|
|
Loading…
Reference in a new issue