update softs + algo on main
This commit is contained in:
parent
88e6581927
commit
e9dbd16495
@ -1,51 +1,38 @@
|
|||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <LoRa.h>
|
#include <LoRa.h>
|
||||||
|
#include <CModemLoRa.h>
|
||||||
|
#include <CProtocol12Bytes.h>
|
||||||
|
|
||||||
typedef struct{ // frame structure
|
CModemLoRa thisLoRa;
|
||||||
uint8_t IDs = 0; // station's ID
|
CProtocol12Bytes protocol;
|
||||||
uint8_t IDp = 0; // gateway's ID
|
|
||||||
uint16_t TS = 0; // TimeStamp
|
|
||||||
uint16_t DT = 0; // Data Type
|
|
||||||
uint16_t D1 = 0; // DATA 1
|
|
||||||
uint16_t D2 = 0; // DATA 2
|
|
||||||
uint16_t D3 = 0; // DATA 3
|
|
||||||
} trame;
|
|
||||||
|
|
||||||
trame message;
|
|
||||||
|
|
||||||
uint16_t ID;
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
SerialUSB.begin(9600);
|
SerialUSB.begin(9600);
|
||||||
while (!SerialUSB){};
|
while (!SerialUSB){};
|
||||||
SerialUSB.println("LoRa Receiver");
|
SerialUSB.println("LoRa Receiver");
|
||||||
|
thisLoRa.begin();
|
||||||
if (!LoRa.begin(868E6)) {
|
|
||||||
Serial.println("Starting LoRa failed!");
|
|
||||||
while (1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
int packetSize = LoRa.parsePacket();
|
int packetSize = thisLoRa.parsePacket();
|
||||||
if (packetSize > 0)
|
if (packetSize > 0)
|
||||||
{
|
{
|
||||||
SerialUSB.println("Nouveau paquet");
|
thisLoRa.read(&protocol); // objet thislora qui appele classe Lora.h et rempli la stucture de l'objet protocol, ser a allèger -5lignes
|
||||||
message.IDs = LoRa.read();
|
SerialUSB.println("Frame received");
|
||||||
message.IDp = LoRa.read();
|
|
||||||
message.IDp = 0x07;
|
|
||||||
message.TS = ((uint16_t)LoRa.read() | (LoRa.read() << 8));
|
|
||||||
message.DT = ((uint16_t)LoRa.read() | LoRa.read() << 8);
|
|
||||||
message.D1 = ((uint16_t)LoRa.read() | LoRa.read() << 8);
|
|
||||||
message.D2 = ((uint16_t)LoRa.read() | LoRa.read() << 8);
|
|
||||||
message.D3 = ((uint16_t)LoRa.read() | LoRa.read() << 8);
|
|
||||||
ID = (uint16_t)(message.IDs | message.IDp), HEX;
|
|
||||||
SerialUSB.println(ID, HEX);
|
|
||||||
SerialUSB.println(message.TS, HEX);
|
|
||||||
SerialUSB.println(message.DT, HEX);
|
|
||||||
SerialUSB.println(message.D1, HEX);
|
|
||||||
SerialUSB.println(message.D2, HEX);
|
|
||||||
SerialUSB.println(message.D3, HEX);
|
|
||||||
delay(100);
|
delay(100);
|
||||||
|
SerialUSB.print("ID = ");
|
||||||
|
SerialUSB.print(protocol.getStationId(),HEX);
|
||||||
|
SerialUSB.println(protocol.getGatewayId(),HEX);
|
||||||
|
SerialUSB.print("TS = ");
|
||||||
|
SerialUSB.println(protocol.getTimestampMessage(),HEX);
|
||||||
|
SerialUSB.print("DT = ");
|
||||||
|
SerialUSB.println(protocol.getDataType(),HEX);
|
||||||
|
SerialUSB.print("D1 = ");
|
||||||
|
SerialUSB.println(protocol.getDataOne(),HEX);
|
||||||
|
SerialUSB.print("D2 = ");
|
||||||
|
SerialUSB.println(protocol.getDataTwo(),HEX);
|
||||||
|
SerialUSB.print("D3 = ");
|
||||||
|
SerialUSB.println(protocol.getDataThree(),HEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,79 +1,46 @@
|
|||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <LoRa.h>
|
#include <LoRa.h>
|
||||||
|
#include <CModemLoRa.h>
|
||||||
|
#include <CProtocol12Bytes.h>
|
||||||
|
|
||||||
typedef struct
|
CProtocol12Bytes protocol;
|
||||||
{
|
CModemLoRa thisLoRa;
|
||||||
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;
|
|
||||||
|
|
||||||
message msg;
|
uint16_t incrTS=0x0000;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
SerialUSB.begin(9600);
|
SerialUSB.begin(9600);
|
||||||
while (!Serial);
|
|
||||||
|
|
||||||
SerialUSB.println("LoRa Sender");
|
SerialUSB.println("LoRa Sender");
|
||||||
|
thisLoRa.begin();
|
||||||
if (!LoRa.begin(868E6))
|
protocol.codeFrame(0x05,0x07,0x0000,0x0001,0x0300,0x0005,0x0000);
|
||||||
{
|
|
||||||
SerialUSB.println("Starting LoRa failed!");
|
|
||||||
while(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
msg.ts = msg.ts + 1;
|
protocol.setDataOne((uint16_t)(random(500, 750)));
|
||||||
msg.d1 = random(20, 40);
|
protocol.setDataTwo((uint16_t)(random(40, 60)));
|
||||||
msg.d2 = random(40, 60);
|
protocol.setDataThree((uint16_t)(random(0, 1)));
|
||||||
msg.d3 = random(0, 100);
|
incrTS = protocol.getTimestampMessage()+1;
|
||||||
|
protocol.setTimestampMessage(incrTS);
|
||||||
|
|
||||||
SerialUSB.print("ID station : ");
|
SerialUSB.print("ID = ");
|
||||||
SerialUSB.print(msg.ids, DEC);
|
SerialUSB.print(protocol.getStationId(),HEX);
|
||||||
SerialUSB.print(", ");
|
SerialUSB.println(protocol.getGatewayId(),HEX);
|
||||||
SerialUSB.println(msg.ids, HEX);
|
SerialUSB.print("TS = ");
|
||||||
|
SerialUSB.println(protocol.getTimestampMessage(),HEX);
|
||||||
|
SerialUSB.print("DT = ");
|
||||||
|
SerialUSB.println(protocol.getDataType(),HEX);
|
||||||
|
SerialUSB.print("D1 = ");
|
||||||
|
SerialUSB.println(protocol.getDataOne(),HEX);
|
||||||
|
SerialUSB.print("D2 = ");
|
||||||
|
SerialUSB.println(protocol.getDataTwo(),HEX);
|
||||||
|
SerialUSB.print("D3 = ");
|
||||||
|
SerialUSB.println(protocol.getDataThree(),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);
|
|
||||||
|
|
||||||
SerialUSB.print("Donnee 3 : ");
|
|
||||||
SerialUSB.print(msg.d3, DEC);
|
|
||||||
SerialUSB.print(", ");
|
|
||||||
SerialUSB.println(msg.d3, HEX);
|
|
||||||
SerialUSB.println(" ");
|
|
||||||
|
|
||||||
for(int i=0; i<3; i++){
|
for(int i=0; i<3; i++){
|
||||||
SerialUSB.println("Sending packet !");
|
SerialUSB.println("Frame sent !");
|
||||||
LoRa.beginPacket();
|
LoRa.beginPacket();
|
||||||
LoRa.write((uint8_t*)&msg, 12);
|
LoRa.write((uint8_t*)&protocol, 12);
|
||||||
LoRa.endPacket();
|
LoRa.endPacket();
|
||||||
|
|
||||||
SerialUSB.println("-----------------------------");
|
SerialUSB.println("-----------------------------");
|
||||||
|
|||||||
@ -56,13 +56,13 @@ void loop() {
|
|||||||
// SerialPrintElapsedTime(); // diplay the time the frame arrived
|
// SerialPrintElapsedTime(); // diplay the time the frame arrived
|
||||||
|
|
||||||
// frame treatment
|
// frame treatment
|
||||||
while(readFrameAndCheckTS() == true){
|
while(readFrameAndCheckID() == true){
|
||||||
// post to server
|
// post to server
|
||||||
EthernetClient postClient;
|
EthernetClient postClient;
|
||||||
String postData = "ID="+String(protocol.getStationId())+"&IDp="+String(protocol.getGatewayId())+"&TS="+String(protocol.getTimestampMessage())+"&DT="+String(protocol.getDataType())+"&D1="+String(protocol.getDataOne())+"&D2="+String(protocol.getDataTwo())+"&D3="+String(protocol.getDataThree());
|
String postData = "ID="+String(protocol.getStationId())+"&IDp="+String(protocol.getGatewayId())+"&TS="+String(protocol.getTimestampMessage())+"&DT="+String(protocol.getDataType())+"&D1="+String(protocol.getDataOne())+"&D2="+String(protocol.getDataTwo())+"&D3="+String(protocol.getDataThree());
|
||||||
if (postClient.connect("btslimayrac.ovh", 80)){
|
if (postClient.connect("btslimayrac.ovh", 80)){
|
||||||
postClient.print("POST /weather/formulaire/formulaireCollecteLORA.php HTTP/1.1\n");
|
postClient.print("POST /weather/formulaire/formulaireCollecteLORA.php HTTP/1.1\n");
|
||||||
postClient.print("Host: weather.btslimayrac.ovh\n");
|
postClient.print("Host: btslimayrac.ovh\n");
|
||||||
postClient.print("Connection: close\n");
|
postClient.print("Connection: close\n");
|
||||||
postClient.print("Content-Type: application/x-www-form-urlencoded\n");
|
postClient.print("Content-Type: application/x-www-form-urlencoded\n");
|
||||||
postClient.print("Content-Length: ");
|
postClient.print("Content-Length: ");
|
||||||
@ -119,6 +119,36 @@ while(readFrameAndCheckTS() == true){
|
|||||||
} // end if (serverGateway)
|
} // end if (serverGateway)
|
||||||
} //end void loop
|
} //end void loop
|
||||||
|
|
||||||
|
bool readFrameAndCheckID(){
|
||||||
|
int id1=0; // for comparing later the LoRa frames using ID data
|
||||||
|
int id2=0; // for comparing later the LoRa frames using ID data
|
||||||
|
int packetSize = thisLoRa.parsePacket();
|
||||||
|
if (packetSize > 0)
|
||||||
|
{
|
||||||
|
thisLoRa.read(&protocol); // objet thislora qui appele classe Lora.h et rempli la stucture de l'objet protocol, ser a allèger -5lignes
|
||||||
|
SerialUSB.println("Frame received");
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
id1 = protocol.getStationId();
|
||||||
|
// big delay
|
||||||
|
packetSize = thisLoRa.parsePacket();
|
||||||
|
if (packetSize > 0)
|
||||||
|
{
|
||||||
|
thisLoRa.read(&protocol); // objet thislora qui appele classe Lora.h et rempli la stucture de l'objet protocol, ser a allèger -5lignes
|
||||||
|
SerialUSB.println("Frame received");
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
id2 = protocol.getStationId();
|
||||||
|
if(id1==id2){
|
||||||
|
readFrameAndCheckID();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
readFrameAndCheckTS();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} //end readframeandcheckid
|
||||||
|
|
||||||
|
|
||||||
bool readFrameAndCheckTS(){
|
bool readFrameAndCheckTS(){
|
||||||
int ts1=0; // for comparing later the LoRa frames using timestamp data
|
int ts1=0; // for comparing later the LoRa frames using timestamp data
|
||||||
int ts2=0; // for comparing later the LoRa frames using timestamp data
|
int ts2=0; // for comparing later the LoRa frames using timestamp data
|
||||||
@ -157,8 +187,24 @@ bool readFrameAndCheckTS(){
|
|||||||
SerialUSB.print("D3 = ");
|
SerialUSB.print("D3 = ");
|
||||||
SerialUSB.println(protocol.getDataThree(),HEX);
|
SerialUSB.println(protocol.getDataThree(),HEX);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
} //end readframeandcheckts
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//void PrintElapsedTime( boolean espaceFinal=true ){ // to display the elapsed time
|
//void PrintElapsedTime( boolean espaceFinal=true ){ // to display the elapsed time
|
||||||
// unsigned long h,m,s = millis()/1000;
|
// unsigned long h,m,s = millis()/1000;
|
||||||
|
|||||||
@ -26,16 +26,16 @@ void loop()
|
|||||||
String postData = "ID="+String(trameToSend.getStationId())+"&IDp="+String(trameToSend.getGatewayId())+"&TS="+String(trameToSend.getTimestampMessage())+"&DT="+String(trameToSend.getDataType())+"&D1="+String(trameToSend.getDataOne())+"&D2="+String(trameToSend.getDataTwo())+"&D3="+String(trameToSend.getDataThree());
|
String postData = "ID="+String(trameToSend.getStationId())+"&IDp="+String(trameToSend.getGatewayId())+"&TS="+String(trameToSend.getTimestampMessage())+"&DT="+String(trameToSend.getDataType())+"&D1="+String(trameToSend.getDataOne())+"&D2="+String(trameToSend.getDataTwo())+"&D3="+String(trameToSend.getDataThree());
|
||||||
if (postClient.connect("btslimayrac.ovh", 80)){
|
if (postClient.connect("btslimayrac.ovh", 80)){
|
||||||
postClient.print("POST /weather/formulaire/formulaireCollecteLORA.php HTTP/1.1\n");
|
postClient.print("POST /weather/formulaire/formulaireCollecteLORA.php HTTP/1.1\n");
|
||||||
postClient.print("Host: btslimayrac.ovh\n");
|
postClient.print("Host: btslimayrac.ovh\n"); // specifies the Internet host and port number of the resource being requested
|
||||||
postClient.print("Connection: close\n");
|
postClient.print("Connection: close\n"); // header option to signal that the connection will be closed after completion of the response
|
||||||
postClient.print("Content-Type: application/x-www-form-urlencoded\n");
|
postClient.print("Content-Type: application/x-www-form-urlencoded\n"); // values are encoded in key-value separated by '&', with a '=' between the key and the value
|
||||||
postClient.print("Content-Length: ");
|
postClient.print("Content-Length: "); // indicates the size of the entity-body, in decimal number of bytes
|
||||||
postClient.print(postData.length());
|
postClient.print(postData.length()); // to retrieve the size and send it
|
||||||
postClient.print("\n\n");
|
postClient.print("\n\n");
|
||||||
postClient.print(postData);
|
postClient.print(postData); // to send the concatenated frame
|
||||||
SerialUSB.println("Post to server sent, frame :");
|
SerialUSB.println("Post to server sent, frame :"); // to display the sent frame
|
||||||
SerialUSB.println(postData);
|
SerialUSB.println(postData);
|
||||||
incrTS = trameToSend.getTimestampMessage()+1,
|
incrTS = trameToSend.getTimestampMessage()+1; // to increment TS part of the frame
|
||||||
trameToSend.setTimestampMessage(incrTS);
|
trameToSend.setTimestampMessage(incrTS);
|
||||||
delay(4000);
|
delay(4000);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user