jd-update
Flavien Haas 7 years ago
parent 16cf1d7c4c
commit 96a56c19ac

@ -12,7 +12,7 @@ void setup() {
SerialUSB.begin(9600);
SerialUSB.println("LoRa Sender");
thisLoRa.begin();
protocol.codeFrame(0x02,0x00,0x0000,0x0001,0x0000,0x0000,0x0000);
protocol.codeFrame(0x0B,0x00,0x0000,0x0001,0x0000,0x0000,0x0000);
}
void loop()

@ -11,7 +11,7 @@ CModemLoRa thisLoRa; // create object fo
CProtocol12Bytes received; // create object that will be used to send data using our protocol
uint16_t saveIDandTS[255]; // used to send the correct frame
int numCase;
int numCase; // used to associates timestamp and id in the arraw
void setup(){
SerialUSB.begin(9600);

@ -10,9 +10,6 @@
#include <CModemLoRa.h> // to use personalised LoRa class
#include <CProtocol12Bytes.h> // to use our protocol
#define LENMAX 80 // maximum size for the LoRa frame
#define Serial SerialUSB // serial out on the M0 use a different function
CModemLoRa thisLoRa; // create object for personnalizeed LoRa class
CProtocol12Bytes protocol; // create object to store data using our protocol
@ -23,72 +20,93 @@ byte mac[] = {0xFA, 0xE3, 0x40, 0xEF, 0xFF, 0xFD}; // set the mac addr
EthernetServer server(80); // initialize the EthernetServer library, using port 80 (default fot HTTP)
int ts1=0; // for comparing later the LoRa frames using timestamp data
int ts2=0; // for comparing later the LoRa frames using timestamp data
int id1=0; // for comparing later the LoRa frames using ID data
int id2=0; // for comparing later the LoRa frames using ID data
bool readFrameAndCheckID(); //function that compares station's ID
bool readFrameAndCheckTS(); //function that compares frame's TimeStamp
uint16_t saveIDandTS[255]; // used to send the correct frame
int numCase; // used to associates timestamp and id in the arraw
// void setSPIFrequency(uint32_t frequency); // set the SPI at 8MHz to use logic analyser
void setup(){
Serial.begin(9600);
while (!Serial); // wait for serial to initialize
Serial.println("LoRa Gateway"); // display on serial the name of the device
SerialUSB.begin(9600);
while (!SerialUSB); // wait for serial to initialize
SerialUSB.println("LoRa Gateway"); // display on serial the name of the device
thisLoRa.begin(); // initialise LoRa
//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
server.begin(); // initialize WebServer part of the librairy
Serial.print("server is at ");
Serial.println(Ethernet.localIP()); // display on serial the IP you can find the webpage
SerialUSB.print("server is at ");
SerialUSB.println(Ethernet.localIP()); // display on serial the IP you can find the webpage
Serial.println("Initializing SD card..."); // initialize SD card
SerialUSB.println("Initializing SD card..."); // initialize SD card
if (!SD.begin(4)) {
Serial.println("ERROR - SD card initialization failed!");
SerialUSB.println("ERROR - SD card initialization failed!");
return; // init failed
}
Serial.println("SUCCESS - SD card initialized.");
SerialUSB.println("SUCCESS - SD card initialized.");
if (!SD.exists("index.htm")) { // check for index.htm file
Serial.println("ERROR - Can't find index.htm file!");
SerialUSB.println("ERROR - Can't find index.htm file!");
return; // can't find index file
}
Serial.println("SUCCESS - Found index.htm file.");
} // end of setup
SerialUSB.println("SUCCESS - Found index.htm file.");
}// end of setup
void loop() {
// SerialPrintElapsedTime(); // diplay the time the frame arrived
//SerialPrintElapsedTime(); // diplay the time the frame arrived
// frame treatment
while(readFrameAndCheckID() == true){
// post to server
int packetSize = thisLoRa.parsePacket();
if (packetSize > 0)
{
thisLoRa.read(&protocol);
numCase = protocol.getStationId();
if(protocol.getTimestampMessage() == saveIDandTS[numCase])
{}
else{
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());
if (postClient.connect("btslimayrac.ovh", 80)){
postClient.print("POST /weather/formulaire/formulaireCollecteLORA.php HTTP/1.1\n");
postClient.print("Host: btslimayrac.ovh\n");
postClient.print("Connection: close\n");
postClient.print("Content-Type: application/x-www-form-urlencoded\n");
postClient.print("Content-Length: ");
postClient.print(postData.length());
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
postClient.print("\n\n");
postClient.print(postData);
Serial.println("Post to server sent");
postClient.print(postData); // to send the concatenated frame
SerialUSB.println("Post to server sent"); // to display the sent frame
SerialUSB.println(postData);
delay(4000);
}
else{
Serial.println("Post failed");
SerialUSB.println("Post failed");
}
delay(100);
SerialUSB.println("New frame recieved : ");
SerialUSB.print("ID = ");
SerialUSB.print(protocol.getStationId(),HEX);
SerialUSB.println(protocol.getGatewayId(),HEX);
SerialUSB.print("TS = ");
SerialUSB.println(protocol.getTimestampMessage(),HEX);
SerialUSB.print("DT = ");
SerialUSB.println(protocol.getDataType(),HEX);
SerialUSB.print("D1 = ");
SerialUSB.println(protocol.getDataOne(),HEX);
SerialUSB.print("D2 = ");
SerialUSB.println(protocol.getDataTwo(),HEX);
SerialUSB.print("D3 = ");
SerialUSB.println(protocol.getDataThree(),HEX);
}
}
}//if (packetSize > 0)
// WebServer
EthernetClient serverGateway = server.available(); // try to get client
if (serverGateway) { // got client?
boolean currentLineIsBlank = true;
while (serverGateway.connected()) {
if (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
@ -107,7 +125,7 @@ while(readFrameAndCheckID() == true){
}
webFile.close();
}
break;
//break;
}
// every line of text received from the client ends with \r\n
if (c == '\n') {
@ -123,74 +141,8 @@ while(readFrameAndCheckID() == true){
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
serverGateway.stop(); // close the connection
} // end if (serverGateway)
} //end void loop
bool readFrameAndCheckID(){
int packetSize = thisLoRa.parsePacket();
if (packetSize > 0)
{
thisLoRa.read(&protocol); // objet thislora qui appele classe Lora.h et rempli la stucture de l'objet protocol, ser a allèger -5lignes
SerialUSB.println("Frame received");
delay(100);
}
id1 = protocol.getStationId();
// big delay
packetSize = thisLoRa.parsePacket();
if (packetSize > 0)
{
thisLoRa.read(&protocol); // objet thislora qui appele classe Lora.h et rempli la stucture de l'objet protocol, ser a allèger -5lignes
SerialUSB.println("Frame received");
delay(100);
}
id2 = protocol.getStationId();
if(id1==id2){
readFrameAndCheckID();
}
else{
readFrameAndCheckTS();
return true;
}
} //end readframeandcheckid
bool readFrameAndCheckTS(){
int packetSize = thisLoRa.parsePacket();
if (packetSize > 0)
{
thisLoRa.read(&protocol); // objet thislora qui appele classe Lora.h et rempli la stucture de l'objet protocol, ser a allèger -5lignes
SerialUSB.println("Frame received");
delay(100);
}
ts1 = protocol.getTimestampMessage();
packetSize = thisLoRa.parsePacket();
if (packetSize > 0)
{
thisLoRa.read(&protocol); // objet thislora qui appele classe Lora.h et rempli la stucture de l'objet protocol, ser a allèger -5lignes
SerialUSB.println("Frame received");
delay(100);
}
ts2 = protocol.getTimestampMessage();
if(ts1==ts2){
return false;
}
else{
SerialUSB.println("New Frame :");
SerialUSB.print("ID = ");
SerialUSB.print(protocol.getStationId(),HEX);
SerialUSB.println(protocol.getGatewayId(),HEX);
SerialUSB.print("TS = ");
SerialUSB.println(protocol.getTimestampMessage(),HEX);
SerialUSB.print("DT = ");
SerialUSB.println(protocol.getDataType(),HEX);
SerialUSB.print("D1 = ");
SerialUSB.println(protocol.getDataOne(),HEX);
SerialUSB.print("D2 = ");
SerialUSB.println(protocol.getDataTwo(),HEX);
SerialUSB.print("D3 = ");
SerialUSB.println(protocol.getDataThree(),HEX);
return true;
}
} //end readframeandcheckts
}//end if (serverGateway)
}//end void loop
//void PrintElapsedTime( boolean espaceFinal=true ){ // to display the elapsed time
// unsigned long h,m,s = millis()/1000;

@ -47,4 +47,4 @@ void loop()
else{
SerialUSB.println("Post failed");
}
}
}//end of loop

Loading…
Cancel
Save