fixed issues with classe

jd-update
Flavien Haas 6 years ago
parent 170f65cb1a
commit a8f8fb0c55

@ -50,7 +50,7 @@ void loop()
client.println("Connection: close"); client.println("Connection: close");
client.println(); client.println();
// send web page // send web page
webFile = SD.open("index.htm"); // open web page file webFile = SD.open("index.html"); // open web page file
if (webFile) { if (webFile) {
while(webFile.available()) { while(webFile.available()) {
client.write(webFile.read()); // send web page to client client.write(webFile.read()); // send web page to client

@ -15,9 +15,11 @@
CModemLoRa thisLoRa; // create object for personnalizeed LoRa class CModemLoRa thisLoRa; // create object for personnalizeed LoRa class
CProtocol12Bytes protocol; // create object to store data using our protocol CProtocol12Bytes protocol; // create object to store data using our protocol
File webFile; // variable for the file containing the webpage
// void setSPIFrequency(uint32_t frequency); // set the SPI at 8MHz to use logic analyser // void setSPIFrequency(uint32_t frequency); // set the SPI at 8MHz to use logic analyser
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // set the mac address byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xED}; // set the mac address
//IPAddress ip(10, 0, 0, 49); // set the IP address for the ethernet shield, overwise the librairy use DHCP //IPAddress ip(10, 0, 0, 49); // set the IP address for the ethernet shield, overwise the librairy use DHCP
@ -28,9 +30,7 @@ void setup(){
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.print("Passerelle LoRa\n"); // display on serial the name of the device
if( !LoRa.begin(868E6) ){ // initialise LoRa and display a message if an error occur thisLoRa.begin(); // initialise LoRa
Serial.print("Echec de l'initialisation LoRa !\n");
while(true);}
//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
@ -50,7 +50,7 @@ void setup(){
void loop() { void loop() {
// LoRa receiver // LoRa receiver
int packetSize = LoRa.parsePacket(); int packetSize = thisLoRa.parsePacket();
if (packetSize > 0) if (packetSize > 0)
{ {
SerialUSB.println("Nouveau paquet"); SerialUSB.println("Nouveau paquet");
@ -70,17 +70,17 @@ void loop() {
// SerialPrintElapsedTime(); // diplay the time the frame arrived // SerialPrintElapsedTime(); // diplay the time the frame arrived
// post to server // post to server
EthernetClient client; 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 = client.connect(server, 80); bool connected = postClient.connect("weather.limayrac.ovh", 80);
if (connected){ if (connected){
client.println("POST /formulaireCollecte.html HTTP/1.1"); postClient.println("POST /formulaireCollecte.html HTTP/1.1");
client.println("Host: btslimayrac.ovh"); postClient.println("Host: btslimayrac.ovh");
client.println("Cache-Control: no-cache"); postClient.println("Cache-Control: no-cache");
client.println("Content-Type: application/x-www-form-urlencoded"); postClient.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: "); postClient.print("Content-Length: ");
client.println(postData.length()); //postClient.println(postData.length());
client.println(postData); //postClient.println(postData);
} }
// WebServer // WebServer
@ -88,22 +88,22 @@ void loop() {
if (serverGateway) { // got client? if (serverGateway) { // got client?
boolean currentLineIsBlank = true; boolean currentLineIsBlank = true;
while (client.connected()) { while (serverGateway.connected()) {
if (client.available()) { // client data available to read if (serverGateway.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client char c = serverGateway.read(); // read 1 byte (character) from client
// last line of client request is blank and ends with \n // last line of client request is blank and ends with \n
// respond to client only after last line received // respond to client only after last line received
if (c == '\n' && currentLineIsBlank) { if (c == '\n' && currentLineIsBlank) {
// send a standard http response header // send a standard http response header
client.println("HTTP/1.1 200 OK"); serverGateway.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html"); serverGateway.println("Content-Type: text/html");
client.println("Connection: close"); serverGateway.println("Connection: close");
client.println(); serverGateway.println();
// send web page // send web page
webFile = SD.open("index.html"); // open web page file webFile = SD.open("index.html"); // 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
client.write(webFile.read()); // send webfile to client serverGateway.write(webFile.read()); // send webfile to client
} }
webFile.close(); webFile.close();
} }
@ -122,6 +122,6 @@ void loop() {
} // end if (client.available()) } // end if (client.available())
} // end while (client.connected()) } // end while (client.connected())
delay(1); // give the web browser time to receive the data delay(1); // give the web browser time to receive the data
client.stop(); // close the connection serverGateway.stop(); // close the connection
} // end if (serverGateway) } // end if (serverGateway)
} //end void loop } //end void loop

Loading…
Cancel
Save