LoRaGateway_BTS2A/postToServer/postToServer.ino

51 lines
2.9 KiB
Arduino
Raw Normal View History

2018-06-08 23:18:11 +02:00
// 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
2018-05-31 19:09:14 +02:00
#include <SPI.h> // to use SPI
#include <Ethernet.h> // to use ethernet
#include <CProtocol12Bytes.h> // to use our frame protocol
2018-05-30 14:52:00 +02:00
byte mac[] = {0xFA, 0xE3, 0x40, 0xEF, 0xFF, 0xFD}; // set the mac address
2018-05-31 19:09:14 +02:00
CProtocol12Bytes trameToSend; // make an object with our protocol
2018-05-30 14:52:00 +02:00
uint16_t incrTS=0x0000;
2018-05-31 19:09:14 +02:00
void setup() {
SerialUSB.begin(9600); // initialise serial
SerialUSB.println("POST"); // print on the screen the name of the program
Ethernet.begin(mac); // initialise ethernet
2018-05-30 14:52:00 +02:00
delay(1000);
2018-05-31 19:09:14 +02:00
trameToSend.codeFrame(0x05,0x07,0x0000,0x0001,0x0300,0x0005,0x0000);
}
2018-05-30 14:52:00 +02:00
2018-05-31 19:09:14 +02:00
void loop()
{
trameToSend.setDataOne((uint16_t)(random(500, 750)));
trameToSend.setDataTwo((uint16_t)(random(40, 60)));
trameToSend.setDataThree((uint16_t)(random(0, 1)));
2018-05-30 14:52:00 +02:00
EthernetClient postClient;
String postData = "ID="+String(trameToSend.getStationId())+"&IDp="+String(trameToSend.getGatewayId())+"&TS="+String(trameToSend.getTimestampMessage())+"&DT="+String(trameToSend.getDataType())+"&D1="+String(trameToSend.getDataOne())+"&D2="+String(trameToSend.getDataTwo())+"&D3="+String(trameToSend.getDataThree());
2018-05-31 19:09:14 +02:00
if (postClient.connect("btslimayrac.ovh", 80)){
postClient.print("POST /weather/formulaire/formulaireCollecteLORA.php HTTP/1.1\n");
2018-06-01 04:02:50 +02:00
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
2018-05-31 19:09:14 +02:00
postClient.print("\n\n");
2018-06-01 04:02:50 +02:00
postClient.print(postData); // to send the concatenated frame
SerialUSB.println("Post to server sent, frame :"); // to display the sent frame
2018-05-31 19:09:14 +02:00
SerialUSB.println(postData);
2018-06-01 04:02:50 +02:00
incrTS = trameToSend.getTimestampMessage()+1; // to increment TS part of the frame
2018-05-31 19:09:14 +02:00
trameToSend.setTimestampMessage(incrTS);
delay(4000);
2018-05-30 14:52:00 +02:00
}
2018-05-31 19:09:14 +02:00
else{
SerialUSB.println("Post failed");
}
2018-06-12 13:13:30 +02:00
}//end of loop