added support for the multi received frame

jd-update
Flavien Haas 6 years ago
parent 0fc0588334
commit 03984040c0

@ -1,5 +1,7 @@
// Flavien HAAS, 2018
// before transfert, check that you have changed the SS port as indicated on the README or you will not be able to use the LoRa shield as the same time as the Ethernet shield
// 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
#include <SPI.h> // to communicate using spi (required for our shields)
#include <LoRa.h> // to use the LoRa shield
@ -19,7 +21,6 @@ File webFile; // variable for the
// void setSPIFrequency(uint32_t frequency); // set the SPI at 8MHz to use logic analyser
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFD}; // set the mac address
IPAddress ip(192, 1, 1, 150); // set the IP address for the ethernet shield, overwise the librairy use DHCP
EthernetServer server(80); // initialize the EthernetServer library, using port 80 (default fot HTTP)
@ -31,8 +32,8 @@ void setup(){
thisLoRa.begin(); // initialise LoRa
//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, 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
@ -50,36 +51,23 @@ void setup(){
Serial.println("SUCCESS - Found index.htm file.");
} // end of setup
//void SerialPrintElapsedTime( boolean espaceFinal=true ){ // to display the elapsed time
// unsigned long h,m,s = millis()/1000;
// m=s/60;
// h=m/60;
// s=s-(m*60);
// m=m-(h*60);
// Serial << ((h<10)?"0":"") << h << ":" << ((m<10)?"0":"") << m << ":" << ((s<10)?"0":"") << s << (espaceFinal?" ":"");
//}
void loop() {
// LoRa receiver
int packetSize = thisLoRa.parsePacket();
if (packetSize > 0)
{
SerialUSB.println("Nouvelle trame reçue");
// 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 recieved");
// delay(100);
// }
thisLoRa.read(&protocol); // objet thislora qui appele classe Lora.h et rempli la stucture de l'objet protocol, ser a allèger -5lignes
// SerialPrintElapsedTime(); // diplay the time the frame arrived
SerialUSB.println(protocol.getStationId(),HEX);
SerialUSB.println(protocol.getGatewayId(),HEX);
SerialUSB.println(protocol.getTimestampMessage(),HEX);
SerialUSB.println(protocol.getDataType(),HEX);
SerialUSB.println(protocol.getDataOne(),HEX);
SerialUSB.println(protocol.getDataTwo(),HEX);
SerialUSB.println(protocol.getDataThree(),HEX);
delay(100);
// frame treatment
while(readFrameAndCheckTS() == true){
Serial.println("trame envoyée");
}
// SerialPrintElapsedTime(); // diplay the time the frame arrived
// 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());
@ -137,3 +125,48 @@ void loop() {
serverGateway.stop(); // close the connection
} // end if (serverGateway)
} //end void loop
bool readFrameAndCheckTS(){
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 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 recieved");
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 recieved");
delay(100);
}
ts2 = protocol.getTimestampMessage();
if(ts1==ts2){
return false;
}
else{
SerialUSB.println("New Frame :");
SerialUSB.println(protocol.getStationId(),HEX);
SerialUSB.println(protocol.getGatewayId(),HEX);
SerialUSB.println(protocol.getTimestampMessage(),HEX);
SerialUSB.println(protocol.getDataType(),HEX);
SerialUSB.println(protocol.getDataOne(),HEX);
SerialUSB.println(protocol.getDataTwo(),HEX);
SerialUSB.println(protocol.getDataThree(),HEX);
return true;
}
}
//void PrintElapsedTime( boolean espaceFinal=true ){ // to display the elapsed time
// unsigned long h,m,s = millis()/1000;
// m=s/60;
// h=m/60;
// s=s-(m*60);
// m=m-(h*60);
// Serial << ((h<10)?"0":"") << h << ":" << ((m<10)?"0":"") << m << ":" << ((s<10)?"0":"") << s << (espaceFinal?" ":"");
//}

Loading…
Cancel
Save