its now like a real station
parent
d319ffedbf
commit
88e6581927
@ -1,47 +1,45 @@
|
|||||||
#include <SPI.h>
|
#include <SPI.h> // to use SPI
|
||||||
#include <Ethernet.h>
|
#include <Ethernet.h> // to use ethernet
|
||||||
#include <CProtocol12Bytes.h> // to use our protocol
|
#include <CProtocol12Bytes.h> // to use our frame protocol
|
||||||
|
|
||||||
byte mac[] = {0xFA, 0xE3, 0x40, 0xEF, 0xFF, 0xFD}; // set the mac address
|
byte mac[] = {0xFA, 0xE3, 0x40, 0xEF, 0xFF, 0xFD}; // set the mac address
|
||||||
|
|
||||||
CProtocol12Bytes trameToSend;
|
CProtocol12Bytes trameToSend; // make an object with our protocol
|
||||||
|
|
||||||
uint16_t incrTS=0x0000;
|
uint16_t incrTS=0x0000;
|
||||||
|
|
||||||
void setup(){
|
void setup() {
|
||||||
SerialUSB.begin(9600);
|
SerialUSB.begin(9600); // initialise serial
|
||||||
Ethernet.begin(mac);
|
SerialUSB.println("POST"); // print on the screen the name of the program
|
||||||
|
Ethernet.begin(mac); // initialise ethernet
|
||||||
delay(1000);
|
delay(1000);
|
||||||
Serial.println("connecting...");
|
trameToSend.codeFrame(0x05,0x07,0x0000,0x0001,0x0300,0x0005,0x0000);
|
||||||
|
|
||||||
trameToSend.setStationId(0x05);
|
|
||||||
trameToSend.setGatewayId(0x07);
|
|
||||||
trameToSend.setTimestampMessage(0x0000);
|
|
||||||
trameToSend.setDataType(0x0001);
|
|
||||||
trameToSend.setDataOne(0x0293);
|
|
||||||
trameToSend.setDataTwo(0x0005);
|
|
||||||
trameToSend.setDataThree(0x0000);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop()
|
||||||
|
{
|
||||||
|
trameToSend.setDataOne((uint16_t)(random(500, 750)));
|
||||||
|
trameToSend.setDataTwo((uint16_t)(random(40, 60)));
|
||||||
|
trameToSend.setDataThree((uint16_t)(random(0, 1)));
|
||||||
|
|
||||||
EthernetClient postClient;
|
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());
|
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());
|
||||||
if (postClient.connect("btslimayrac.ovh", 80)){
|
if (postClient.connect("btslimayrac.ovh", 80)){
|
||||||
postClient.print("POST /weather/formulaire/formulaireCollecteLORA.php HTTP/1.1\n");
|
postClient.print("POST /weather/formulaire/formulaireCollecteLORA.php HTTP/1.1\n");
|
||||||
postClient.print("Host: btslimayrac.ovh\n");
|
postClient.print("Host: btslimayrac.ovh\n");
|
||||||
postClient.print("Connection: close\n");
|
postClient.print("Connection: close\n");
|
||||||
postClient.print("Content-Type: application/x-www-form-urlencoded\n");
|
postClient.print("Content-Type: application/x-www-form-urlencoded\n");
|
||||||
postClient.print("Content-Length: ");
|
postClient.print("Content-Length: ");
|
||||||
postClient.print(postData.length());
|
postClient.print(postData.length());
|
||||||
postClient.print("\n\n");
|
postClient.print("\n\n");
|
||||||
postClient.print(postData);
|
postClient.print(postData);
|
||||||
Serial.println("Post to server sent");
|
SerialUSB.println("Post to server sent, frame :");
|
||||||
incrTS = trameToSend.getTimestampMessage()+1,
|
SerialUSB.println(postData);
|
||||||
trameToSend.setTimestampMessage(incrTS);
|
incrTS = trameToSend.getTimestampMessage()+1,
|
||||||
}
|
trameToSend.setTimestampMessage(incrTS);
|
||||||
else{
|
delay(4000);
|
||||||
Serial.println("Post failed");
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
SerialUSB.println("Post failed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue