|
|
@ -27,16 +27,28 @@ EthernetServer server(80); // initialize the Et
|
|
|
|
void setup(){
|
|
|
|
void setup(){
|
|
|
|
Serial.begin(9600);
|
|
|
|
Serial.begin(9600);
|
|
|
|
while (!Serial); // wait for serial to initialize
|
|
|
|
while (!Serial); // wait for serial to initialize
|
|
|
|
Serial.print("Passerelle LoRa\n"); // display on serial the name of the device
|
|
|
|
Serial.println("LoRa Gateway"); // display on serial the name of the device
|
|
|
|
|
|
|
|
|
|
|
|
thisLoRa.begin(); // initialise LoRa
|
|
|
|
thisLoRa.begin(); // initialise LoRa
|
|
|
|
|
|
|
|
|
|
|
|
//Ethernet.begin(mac, ip); // initialize Ethernet shield using the set mac adress and set IP
|
|
|
|
//Ethernet.begin(mac, ip); // initialize Ethernet shield using the set mac adress and set IP
|
|
|
|
Ethernet.begin(mac); // initialize Ethernet shield uding the set mac and DHCP for the IP
|
|
|
|
Ethernet.begin(mac); // initialize Ethernet shield uding the set mac and DHCP for the IP
|
|
|
|
server.begin(); // initialize WebServer part of the librairy
|
|
|
|
server.begin(); // initialize WebServer part of the librairy
|
|
|
|
Serial.print("server is at "); // display on serial the IP you can find the webpage
|
|
|
|
Serial.print("server is at ");
|
|
|
|
Serial.println(Ethernet.localIP());
|
|
|
|
Serial.println(Ethernet.localIP()); // display on serial the IP you can find the webpage
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println("Initializing SD card..."); // initialize SD card
|
|
|
|
|
|
|
|
if (!SD.begin(4)) {
|
|
|
|
|
|
|
|
Serial.println("ERROR - SD card initialization failed!");
|
|
|
|
|
|
|
|
return; // init failed
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Serial.println("SUCCESS - SD card initialized.");
|
|
|
|
|
|
|
|
if (!SD.exists("index.htm")) { // check for index.htm file
|
|
|
|
|
|
|
|
Serial.println("ERROR - Can't find index.htm file!");
|
|
|
|
|
|
|
|
return; // can't find index file
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Serial.println("SUCCESS - Found index.htm file.");
|
|
|
|
|
|
|
|
} // end of setup
|
|
|
|
|
|
|
|
|
|
|
|
//void SerialPrintElapsedTime( boolean espaceFinal=true ){ // to display the elapsed time
|
|
|
|
//void SerialPrintElapsedTime( boolean espaceFinal=true ){ // to display the elapsed time
|
|
|
|
// unsigned long h,m,s = millis()/1000;
|
|
|
|
// unsigned long h,m,s = millis()/1000;
|
|
|
@ -69,19 +81,19 @@ void loop() {
|
|
|
|
// SerialPrintElapsedTime(); // diplay the time the frame arrived
|
|
|
|
// SerialPrintElapsedTime(); // diplay the time the frame arrived
|
|
|
|
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
bool connected = postClient.connect("weather.limayrac.ovh", 80);
|
|
|
|
// bool connected = postClient.connect("weather.limayrac.ovh", 80);
|
|
|
|
if (connected){
|
|
|
|
// if (connected){
|
|
|
|
postClient.println("POST /formulaireCollecte.html HTTP/1.1");
|
|
|
|
// postClient.println("POST /formulaireCollecte.html HTTP/1.1");
|
|
|
|
postClient.println("Host: btslimayrac.ovh");
|
|
|
|
// postClient.println("Host: btslimayrac.ovh");
|
|
|
|
postClient.println("Cache-Control: no-cache");
|
|
|
|
// postClient.println("Cache-Control: no-cache");
|
|
|
|
postClient.println("Content-Type: application/x-www-form-urlencoded");
|
|
|
|
// postClient.println("Content-Type: application/x-www-form-urlencoded");
|
|
|
|
postClient.print("Content-Length: ");
|
|
|
|
// postClient.print("Content-Length: ");
|
|
|
|
//postClient.println(postData.length());
|
|
|
|
// //postClient.println(postData.length());
|
|
|
|
//postClient.println(postData);
|
|
|
|
// //postClient.println(postData);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
Serial.println("post envoye vers le serveur");
|
|
|
|
// Serial.println("post envoye vers le serveur");
|
|
|
|
|
|
|
|
|
|
|
|
// WebServer
|
|
|
|
// WebServer
|
|
|
|
EthernetClient serverGateway = server.available(); // try to get client
|
|
|
|
EthernetClient serverGateway = server.available(); // try to get client
|
|
|
@ -100,7 +112,7 @@ void loop() {
|
|
|
|
serverGateway.println("Connection: close");
|
|
|
|
serverGateway.println("Connection: close");
|
|
|
|
serverGateway.println();
|
|
|
|
serverGateway.println();
|
|
|
|
// send web page
|
|
|
|
// send web page
|
|
|
|
webFile = SD.open("index.html"); // open web page file
|
|
|
|
webFile = SD.open("index.htm"); // open web page file
|
|
|
|
if (webFile) { // if the webfile exist
|
|
|
|
if (webFile) { // if the webfile exist
|
|
|
|
while(webFile.available()) { // the webfile is avaible
|
|
|
|
while(webFile.available()) { // the webfile is avaible
|
|
|
|
serverGateway.write(webFile.read()); // send webfile to client
|
|
|
|
serverGateway.write(webFile.read()); // send webfile to client
|
|
|
|