diff --git a/fakeStation/fakeStation.ino b/fakeStation/fakeStation.ino index f527470..4dac6d5 100644 --- a/fakeStation/fakeStation.ino +++ b/fakeStation/fakeStation.ino @@ -12,7 +12,7 @@ void setup() { SerialUSB.begin(9600); SerialUSB.println("LoRa Sender"); thisLoRa.begin(); - protocol.codeFrame(0x0A,0x00,0x0000,0x0001,0x0000,0x0000,0x0000); + protocol.codeFrame(0x0B,0x00,0x0000,0x0001,0x0000,0x0000,0x0000); } void loop() diff --git a/gateway/gateway.ino b/gateway/gateway.ino index 65b87c0..a95e52b 100644 --- a/gateway/gateway.ino +++ b/gateway/gateway.ino @@ -6,18 +6,22 @@ #include // to communicate using spi (required for our shields) #include // to use the LoRa shield #include // to use the ethernet shield -#include // to use a SD card +//#include // to use a SD card #include // to use personalised LoRa class #include // to use our protocol CModemLoRa thisLoRa; // create object for personnalizeed LoRa class CProtocol12Bytes protocol; // create object to store data using our protocol -File webFile; // variable for the file containing the webpage +//File webFile; // variable for the file containing the webpage -//String postData; -//String tsarray; -//String oldpostData; +String postData; +String tsarray; +String oldpostData; + +//Pour comparer les timestamps +uint16_t tstamp_old; +uint16_t tstamp_now; 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 @@ -31,27 +35,26 @@ int numCase; // used to associat void setup(){ SerialUSB.begin(9600); + delay(500); SerialUSB.println("LoRa Gateway"); // display on serial the name of the device - + delay(100); thisLoRa.begin(); // initialise LoRa - + delay(500); //Ethernet.begin(mac, ip); // initialize Ethernet shield using the set mac adress and set IP and DHCP for the rest Ethernet.begin(mac); // initialize Ethernet shield uding the set mac and DHCP for the rest + delay(500); server.begin(); // initialize WebServer part of the librairy + delay(500); SerialUSB.print("server is at "); SerialUSB.println(Ethernet.localIP()); // display on serial the IP you can find the webpage - SerialUSB.println("Initializing SD card..."); // initialize SD card - if (!SD.begin(4)) { - SerialUSB.println("ERROR - SD card initialization failed!"); - return; // init failed - } - SerialUSB.println("SUCCESS - SD card initialized."); - if (!SD.exists("index.html")) { // check for index.html file - SerialUSB.println("ERROR - Can't find index.html file!"); - return; // can't find index file - } - SerialUSB.println("SUCCESS - Found index.html file."); + //SerialUSB.println("Initializing SD card..."); // initialize SD card + //SD.begin(4); + //delay(500); + //SerialUSB.println("SUCCESS - SD card initialized."); + //SD.exists("index.htm"); + //delay(500); + //SerialUSB.println("SUCCESS - Found index.htm file."); }// end of setup void loop() { @@ -67,10 +70,11 @@ void loop() { if(protocol.getTimestampMessage() == saveIDandTS[numCase]) {} else{ + tstamp_now = protocol.getTimestampMessage(); saveIDandTS[numCase] = protocol.getTimestampMessage(); //post to server 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()); + 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)){ 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 @@ -109,7 +113,7 @@ void loop() { EthernetClient serverGateway = server.available(); // try to get client while (serverGateway) { // got client? boolean currentLineIsBlank = true; - if (serverGateway.connected()) { + while (serverGateway.connected()) { if (serverGateway.available()) { // client data available to read char c = serverGateway.read(); // read 1 byte (character) from client // last line of client request is blank and ends with \n @@ -120,14 +124,57 @@ void loop() { serverGateway.println("Content-Type: text/html"); serverGateway.println("Connection: close"); serverGateway.println(); - // send web page - webFile = SD.open("index.html"); // open web page file - if (webFile) { // if the webfile exist - while(webFile.available()) { // the webfile is avaible - serverGateway.write(webFile.read()); // send webfile to client - } - webFile.close(); - } + serverGateway.println(""); + serverGateway.println(""); + serverGateway.print(""); + serverGateway.print(""); + serverGateway.print(""); + serverGateway.print(""); + serverGateway.print(""); + serverGateway.println(""); + serverGateway.println("

IHM Web Passerelle

"); + serverGateway.println("

ID station : "); + serverGateway.print(protocol.getStationId()); + serverGateway.print("
"); + serverGateway.println("ID passerelle : "); + serverGateway.print(protocol.getGatewayId()); + serverGateway.print("
"); + serverGateway.println("Timestamp : "); + serverGateway.print(protocol.getTimestampMessage()); + serverGateway.print("
"); + serverGateway.println("Types de données : "); + serverGateway.print(protocol.getDataType()); + serverGateway.print("
"); + serverGateway.println("Données 1 :"); + serverGateway.print(protocol.getDataOne()); + serverGateway.print("
"); + serverGateway.println("Données 2 :"); + serverGateway.print(protocol.getDataTwo()); + serverGateway.print("
"); + 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(""); + serverGateway.print(""); + serverGateway.print(""); + serverGateway.print(""); + serverGateway.print(""); + serverGateway.print(""); + serverGateway.print(""); + serverGateway.print(""); + serverGateway.print(""); + //serverGateway.print(tsarray); + serverGateway.print("
IDIDpTSDTD1D2D3
"); + serverGateway.println(""); break; } // every line of text received from the client ends with \r\n