From 355bfe40d9d8b38e9596b92888a759b06769759c Mon Sep 17 00:00:00 2001 From: Flavien Haas Date: Fri, 8 Jun 2018 23:18:11 +0200 Subject: [PATCH] add treament program --- .DS_Store | Bin 0 -> 6148 bytes WebServer/WebServer/WebServer.ino | 5 + frameTreatment/frameTreatment.ino | 118 ++++++++++++++++++++++++ gateway/gateway.ino | 34 ++----- numero_passerelle/numero_passerelle.ino | 4 + postToServer/postToServer.ino | 5 + 6 files changed, 142 insertions(+), 24 deletions(-) create mode 100644 .DS_Store create mode 100644 frameTreatment/frameTreatment.ino diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..eb042b26e01d07eaf04035bd810b43f04b0cb94b GIT binary patch literal 6148 zcmeHK!A`_~bgX~tfv%Pe>f?^D#f0HGUy&5~ zccmzES*0gTF6nE$v)$oZsKkQN#$*?qz0hacapXDPICjoUic)NNrS%6mBO%kVX2hw| zbcQ;qk9#H-htl$-W~P8CU<&+o1?0m{>kR^0YYLbGra+~Dd>=erFo{?O)K3Q+JpvHB z46Cs(X9=nC5tE2zKxSwzloCU!i$@F>${F{OmqaWBhH|)g_;7J%7f&coXXp4{>2OIv zYfS-DpsBz~xE;#=e|z}+-z>5_Q@|AXR|>f9csd^OC&j(B_2Xo(_4Eh2nDEMgRS7$~ g6_YDl@fBT-aW5TW60r=(2+jTos0`Ma0!LNg3oB1gwg3PC literal 0 HcmV?d00001 diff --git a/WebServer/WebServer/WebServer.ino b/WebServer/WebServer/WebServer.ino index e994f1b..65fdbd0 100644 --- a/WebServer/WebServer/WebServer.ino +++ b/WebServer/WebServer/WebServer.ino @@ -1,3 +1,8 @@ +// Flavien HAAS, 2018 +// before transfert, check these things: +// have all the librairies needed installed on your machine +// changed the SS port for ethernet as indicated on the README or you will not be able to use the LoRa shield as the same time as the Ethernet shield + #include #include #include diff --git a/frameTreatment/frameTreatment.ino b/frameTreatment/frameTreatment.ino new file mode 100644 index 0000000..acfd1d2 --- /dev/null +++ b/frameTreatment/frameTreatment.ino @@ -0,0 +1,118 @@ +// Flavien HAAS, 2018 +// before transfert, check these things: +// have all the librairies needed installed on your machine + +#include // to communicate using spi (required for our shields) +#include // to use the LoRa shield +#include // to use personalised LoRa class +#include // to use our protocol + +CModemLoRa thisLoRa; // create object for personnalizeed LoRa class +CProtocol12Bytes goodOne; // create object to store data using our protocol + +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 id1=0; // for comparing later the LoRa frames using ID data +int id2=0; // for comparing later the LoRa frames using ID data + +bool readFrameAndCheckID(); // function that compares station's ID +bool readFrameAndCheckTS(); // function that compares frame's TimeStamp + +void setup(){ + Serial.begin(9600); + while (!Serial); // wait for serial to initialize + Serial.println("LoRa frame treatment"); // display on serial the name of the device + + thisLoRa.begin(); // initialise LoRa +} // end of setup + +void loop() { + // frame treatment + while(readFrameAndCheckID() == true){ + // post to server + EthernetClient postClient; + String postData = "ID="+String(goodOne.getStationId())+"&IDp="+String(goodOne.getGatewayId())+"&TS="+String(goodOne.getTimestampMessage())+"&DT="+String(goodOne.getDataType())+"&D1="+String(goodOne.getDataOne())+"&D2="+String(goodOne.getDataTwo())+"&D3="+String(goodOne.getDataThree()); + if (postClient.connect("btslimayrac.ovh", 80)){ + postClient.print("POST /weather/formulaire/formulaireCollecteLORA.php HTTP/1.1\n"); + postClient.print("Host: btslimayrac.ovh\n"); + postClient.print("Connection: close\n"); + postClient.print("Content-Type: application/x-www-form-urlencoded\n"); + postClient.print("Content-Length: "); + postClient.print(postData.length()); + postClient.print("\n\n"); + postClient.print(postData); + Serial.println("Post to server sent"); + } + else{ + Serial.println("Post failed"); + } + } + +}// end void loop + +bool readFrameAndCheckID(){ + int packetSize = thisLoRa.parsePacket(); + if (packetSize > 0) + { + thisLoRa.read(&checkID); // 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 = checkID.getStationId(); + packetSize = thisLoRa.parsePacket(); + if (packetSize > 0) + { + thisLoRa.read(&checkID); // 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 = checkID.getStationId(); + if(id1==id2){ + readFrameAndCheckID(); + } + else{ + readFrameAndCheckTS(); + return true; + } +} //end readframeandcheckid + +bool readFrameAndCheckTS(){ + 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); + } + ts1 = protocol.getTimestampMessage(); + 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); + } + ts2 = protocol.getTimestampMessage(); + if(ts1==ts2){ + return false; + } + else{ + SerialUSB.println("New Frame :"); + 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); + return true; + } +} //end readframeandcheckts + + diff --git a/gateway/gateway.ino b/gateway/gateway.ino index d4ffeb8..8bc9ade 100644 --- a/gateway/gateway.ino +++ b/gateway/gateway.ino @@ -18,13 +18,21 @@ CProtocol12Bytes protocol; // create object to File webFile; // variable for the file containing the webpage -// void setSPIFrequency(uint32_t frequency); // set the SPI at 8MHz to use logic analyser - byte mac[] = {0xFA, 0xE3, 0x40, 0xEF, 0xFF, 0xFD}; // set the mac address IPAddress ip(192, 1, 1, 150); // set the IP address for the ethernet shield, overwise the librairy use DHCP EthernetServer server(80); // initialize the EthernetServer library, using port 80 (default fot HTTP) +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 id1=0; // for comparing later the LoRa frames using ID data +int id2=0; // for comparing later the LoRa frames using ID data + +bool readFrameAndCheckID(); //function that compares station's ID +bool readFrameAndCheckTS(); //function that compares frame's TimeStamp + +// void setSPIFrequency(uint32_t frequency); // set the SPI at 8MHz to use logic analyser + void setup(){ Serial.begin(9600); while (!Serial); // wait for serial to initialize @@ -78,7 +86,6 @@ while(readFrameAndCheckID() == true){ // WebServer EthernetClient serverGateway = server.available(); // try to get client - if (serverGateway) { // got client? boolean currentLineIsBlank = true; while (serverGateway.connected()) { @@ -120,8 +127,6 @@ while(readFrameAndCheckID() == true){ } //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) { @@ -148,10 +153,7 @@ bool readFrameAndCheckID(){ } } //end readframeandcheckid - bool readFrameAndCheckTS(){ - 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 packetSize = thisLoRa.parsePacket(); if (packetSize > 0) { @@ -190,22 +192,6 @@ bool readFrameAndCheckTS(){ } } //end readframeandcheckts - - - - - - - - - - - - - - - - //void PrintElapsedTime( boolean espaceFinal=true ){ // to display the elapsed time // unsigned long h,m,s = millis()/1000; // m=s/60; diff --git a/numero_passerelle/numero_passerelle.ino b/numero_passerelle/numero_passerelle.ino index 1e29222..f212134 100644 --- a/numero_passerelle/numero_passerelle.ino +++ b/numero_passerelle/numero_passerelle.ino @@ -1,3 +1,7 @@ +// Flavien HAAS, 2018 +// before transfert, check these things: +// have all the librairies needed installed on your machine + void setup() { Serial.begin(9600); } diff --git a/postToServer/postToServer.ino b/postToServer/postToServer.ino index 40e0a44..5b0e866 100644 --- a/postToServer/postToServer.ino +++ b/postToServer/postToServer.ino @@ -1,3 +1,8 @@ +// Flavien HAAS, 2018 +// before transfert, check these things: +// have all the librairies needed installed on your machine +// changed the SS port for ethernet as indicated on the README or you will not be able to use the LoRa shield as the same time as the Ethernet shield + #include // to use SPI #include // to use ethernet #include // to use our frame protocol