From e619cc16a32c205a08a3c44ab21a748b2e35bf92 Mon Sep 17 00:00:00 2001 From: Flavien Haas Date: Fri, 22 Jun 2018 15:35:13 +0200 Subject: [PATCH] FINAL --- LoRaReceiver-struct/LoRaReceiver-struct.ino | 1 + fakeStation/fakeStation.ino | 2 +- gateway/gateway.ino | 60 +++++++++++++-------- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/LoRaReceiver-struct/LoRaReceiver-struct.ino b/LoRaReceiver-struct/LoRaReceiver-struct.ino index a490f1a..c86fb84 100644 --- a/LoRaReceiver-struct/LoRaReceiver-struct.ino +++ b/LoRaReceiver-struct/LoRaReceiver-struct.ino @@ -13,6 +13,7 @@ void setup() { } void loop() { + //SerialUSB.println("Frame received"); int packetSize = thisLoRa.parsePacket(); if (packetSize > 0) { diff --git a/fakeStation/fakeStation.ino b/fakeStation/fakeStation.ino index 59b5243..3db44c7 100644 --- a/fakeStation/fakeStation.ino +++ b/fakeStation/fakeStation.ino @@ -13,7 +13,7 @@ void setup() { SerialUSB.println("LoRa Sender"); thisLoRa.begin(); - protocol.codeFrame(0x0B,0x00,0x0000,0x00FF,0x5BA2,0x0D4C,0x9299); // Name : LORA-TEST1 or 0x929A for *2 + protocol.codeFrame(0x0A,0x00,0x0000,0x00FF,0x5BA2,0x0D4C,0x929A); // Name : LORA-TEST1 or 0x929A for *2 LoRa.beginPacket(); LoRa.write((uint8_t*)&protocol, 12); // Send name diff --git a/gateway/gateway.ino b/gateway/gateway.ino index a95e52b..2908a46 100644 --- a/gateway/gateway.ino +++ b/gateway/gateway.ino @@ -16,12 +16,7 @@ CProtocol12Bytes protocol; // create object to //File webFile; // variable for the file containing the webpage String postData; -String tsarray; -String oldpostData; - -//Pour comparer les timestamps -uint16_t tstamp_old; -uint16_t tstamp_now; +String row; 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 @@ -70,8 +65,8 @@ void loop() { if(protocol.getTimestampMessage() == saveIDandTS[numCase]) {} else{ - tstamp_now = protocol.getTimestampMessage(); saveIDandTS[numCase] = protocol.getTimestampMessage(); + row += "" + String(protocol.getStationId())+""+String(protocol.getGatewayId())+""+String(protocol.getTimestampMessage())+"" + String(protocol.getDataType())+"" + String(protocol.getDataOne())+"" + String(protocol.getDataTwo())+"" + String(protocol.getDataThree())+""; //post to server EthernetClient postClient; 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()); @@ -86,12 +81,28 @@ void loop() { postClient.print(postData); // to send the concatenated frame SerialUSB.println("Post to server sent"); // to display the sent frame SerialUSB.println(postData); - delay(4000); + delay(10); } else{ SerialUSB.println("Post failed"); + SerialUSB.println(" New attempt to POST"); + if (postClient.connect("btslimayrac.ovh", 80)){ + postClient.print("POST /weather/formulaire/formulaireCollecteLORA.php HTTP/1.1\n"); + postClient.print("Host: btslimayrac.ovh\n"); // specifies the Internet host and port number of the resource being requested + 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"); // values are encoded in key-value separated by '&', with a '=' between the key and the value + postClient.print("Content-Length: "); // indicates the size of the entity-body, in decimal number of bytes + postClient.print(postData.length()); // to retrieve the size and send it + postClient.print("\n\n"); + postClient.print(postData); // to send the concatenated frame + SerialUSB.println("Post to server sent"); // to display the sent frame + SerialUSB.println(postData); + delay(10); } - delay(100); + else{ + SerialUSB.println("Post miserably failed, can't connect to btslimayrac.ovh, check your network's settings"); + }//end of secnd else + }//end of first else SerialUSB.println("New frame recieved : "); SerialUSB.print("ID = "); SerialUSB.print(protocol.getStationId(),HEX); @@ -106,6 +117,8 @@ void loop() { SerialUSB.println(protocol.getDataTwo(),HEX); SerialUSB.print("D3 = "); SerialUSB.println(protocol.getDataThree(),HEX); + SerialUSB.print("You can see the web interface at :"); + SerialUSB.println(Ethernet.localIP()); } }//if (packetSize > 0) @@ -127,7 +140,7 @@ void loop() { serverGateway.println(""); serverGateway.println(""); serverGateway.print(""); - serverGateway.print(""); + serverGateway.print(""); serverGateway.print(""); serverGateway.print(""); serverGateway.print(""); @@ -135,10 +148,11 @@ void loop() { serverGateway.println("html{font-family:\"Trebuchet MS\";text-align:center;background-color:white;color:black}"); serverGateway.println("h1{text-align:center;color:red;font-size:72px}"); serverGateway.println("h2{text-align:center;color:red;font-size:36px}"); - serverGateway.println("p{text-align:center;font-size:36px}"); - serverGateway.println("table,th,td{border:2px outset black;font-size:56px}"); + serverGateway.println("p{text-align:center;font-size:25px}"); + serverGateway.println("table,th,td{border:2px outset black;font-size:25px}"); serverGateway.println(""); serverGateway.println("

IHM Web Passerelle

"); + serverGateway.println("

Dernière trame envoyée

"); serverGateway.println("

ID station : "); serverGateway.print(protocol.getStationId()); serverGateway.print("
"); @@ -160,19 +174,19 @@ void loop() { serverGateway.println("Données 3 :"); serverGateway.print(protocol.getDataThree()); serverGateway.print("

"); - serverGateway.print("



"); - serverGateway.print("

20 dernières trames reçues :

"); + serverGateway.print("

"); + serverGateway.print("

Historique des dernières trames envoyées :

"); serverGateway.print(""); serverGateway.print(""); - serverGateway.print(""); - serverGateway.print(""); - serverGateway.print(""); - serverGateway.print(""); - serverGateway.print(""); - serverGateway.print(""); - serverGateway.print(""); + serverGateway.print(""); + serverGateway.print(""); + serverGateway.print(""); + serverGateway.print(""); + serverGateway.print(""); + serverGateway.print(""); + serverGateway.print(""); serverGateway.print(""); - //serverGateway.print(tsarray); + serverGateway.print(row); serverGateway.print("
IDIDpTSDTD1D2D3Identifiant stationIdentifiant passerelleTimeStampType de donnéesDonnée 1Donnée 2Donnée 3
"); serverGateway.println(""); break; @@ -190,7 +204,7 @@ void loop() { } // end if (client.available()) } // end while (client.connected()) delay(1); // give the web browser time to receive the data - serverGateway.stop(); // close the connection + serverGateway.stop(); // close the connection break; }//end if (serverGateway) }//end void loop