integration of myclass
This commit is contained in:
parent
bdfc6ea7ad
commit
170f65cb1a
@ -3,11 +3,18 @@
|
|||||||
|
|
||||||
#include <SPI.h> // to communicate using spi (required for our shields)
|
#include <SPI.h> // to communicate using spi (required for our shields)
|
||||||
#include <LoRa.h> // to use the LoRa shield
|
#include <LoRa.h> // to use the LoRa shield
|
||||||
#include "Ethernet.h" // to use the ethernet shield
|
#include <Ethernet.h> // to use the ethernet shield
|
||||||
|
#include <SD.h> // to use a SD card
|
||||||
|
#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 LENMAX 80 // maximum size for the LoRa frame
|
||||||
#define Serial SerialUSB // serial out on the M0 use a different function
|
#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
|
||||||
|
|
||||||
// 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, 0xFE, 0xED}; // set the mac address
|
||||||
@ -16,18 +23,6 @@ byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // set the mac addre
|
|||||||
|
|
||||||
EthernetServer server(80); // initialize the EthernetServer library, using port 80 (default fot HTTP)
|
EthernetServer server(80); // initialize the EthernetServer library, using port 80 (default fot HTTP)
|
||||||
|
|
||||||
typedef struct { // frame structure
|
|
||||||
uint8_t ID = 0; // station's ID
|
|
||||||
uint8_t IDp = 0; // gateway's ID
|
|
||||||
uint16_t TS = 0; // TimeStamp
|
|
||||||
uint16_t DT = 0; // Data Type
|
|
||||||
uint16_t D1 = 0; // DATA 1
|
|
||||||
uint16_t D2 = 0; // DATA 2
|
|
||||||
uint16_t D3 = 0; // DATA 3
|
|
||||||
} trame; // frame name
|
|
||||||
|
|
||||||
trame message; // creation of the frame message
|
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
while (!Serial); // wait for serial to initialize
|
while (!Serial); // wait for serial to initialize
|
||||||
@ -59,28 +54,24 @@ void loop() {
|
|||||||
if (packetSize > 0)
|
if (packetSize > 0)
|
||||||
{
|
{
|
||||||
SerialUSB.println("Nouveau paquet");
|
SerialUSB.println("Nouveau paquet");
|
||||||
message.ID = LoRa.read();
|
|
||||||
message.IDp = LoRa.read();
|
thisLoRa.read(&protocol); // objet thislora qui appele classe Lora.h et rempli la stucture de l'objet protocol, ser a allèger -5lignes
|
||||||
message.IDp = 0x07;
|
|
||||||
message.TS = ((uint16_t)LoRa.read() | (LoRa.read() << 8));
|
SerialUSB.println(protocol.getStationId(),HEX);
|
||||||
message.DT = ((uint16_t)LoRa.read() | LoRa.read() << 8);
|
SerialUSB.println(protocol.getGatewayId(),HEX);
|
||||||
message.D1 = ((uint16_t)LoRa.read() | LoRa.read() << 8);
|
SerialUSB.println(protocol.getTimestampMessage(),HEX);
|
||||||
message.D2 = ((uint16_t)LoRa.read() | LoRa.read() << 8);
|
SerialUSB.println(protocol.getDataType(),HEX);
|
||||||
message.D3 = ((uint16_t)LoRa.read() | LoRa.read() << 8);
|
SerialUSB.println(protocol.getDataOne(),HEX);
|
||||||
SerialUSB.println(message.ID, HEX);
|
SerialUSB.println(protocol.getDataTwo(),HEX);
|
||||||
SerialUSB.println(message.IDp, HEX);
|
SerialUSB.println(protocol.getDataThree(),HEX);
|
||||||
SerialUSB.println(message.TS, HEX);
|
|
||||||
SerialUSB.println(message.DT, HEX);
|
|
||||||
SerialUSB.println(message.D1, HEX);
|
|
||||||
SerialUSB.println(message.D2, HEX);
|
|
||||||
SerialUSB.println(message.D3, HEX);
|
|
||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SerialPrintElapsedTime(); // diplay the time the frame arrived
|
// SerialPrintElapsedTime(); // diplay the time the frame arrived
|
||||||
|
|
||||||
// post to server
|
// post to server
|
||||||
String postdata="&ID="+message.ID+"&IDp="+message.IDp+"&TS="+message.TS+"&DT="+message.DT+"&D1="+message.D1+"&D2="+message.D2+"&D3="+message.D3;
|
EthernetClient client;
|
||||||
|
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 = client.connect(server, 80);
|
||||||
if (connected){
|
if (connected){
|
||||||
client.println("POST /formulaireCollecte.html HTTP/1.1");
|
client.println("POST /formulaireCollecte.html HTTP/1.1");
|
||||||
@ -93,42 +84,44 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WebServer
|
// WebServer
|
||||||
EthernetClient client = server.available(); // WebServer :listen for incoming clients
|
EthernetClient serverGateway = server.available(); // try to get client
|
||||||
if (client) {
|
|
||||||
Serial.println("new client");
|
if (serverGateway) { // got client?
|
||||||
boolean currentLineIsBlank = true; // an http request ends with a blank line
|
boolean currentLineIsBlank = true;
|
||||||
while (client.connected()) {
|
while (client.connected()) {
|
||||||
if (client.available()) {
|
if (client.available()) { // client data available to read
|
||||||
char c = client.read();
|
char c = client.read(); // read 1 byte (character) from client
|
||||||
Serial.write(c);
|
// last line of client request is blank and ends with \n
|
||||||
if (c == '\n' && currentLineIsBlank) { // send the beginning of a standard http response header
|
// respond to client only after last line received
|
||||||
client.println("HTTP/1.1 200 OK");
|
if (c == '\n' && currentLineIsBlank) {
|
||||||
client.println("Content-Type: text/html");
|
// send a standard http response header
|
||||||
client.println("Connection: close"); // the connection will be closed after completion of the response
|
client.println("HTTP/1.1 200 OK");
|
||||||
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
|
client.println("Content-Type: text/html");
|
||||||
client.println();
|
client.println("Connection: close");
|
||||||
client.println("<!DOCTYPE HTML>");
|
client.println();
|
||||||
client.println("<html>");
|
// send web page
|
||||||
// output the value of each analog input pin
|
webFile = SD.open("index.html"); // open web page file
|
||||||
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
|
if (webFile) { // if the webfile exist
|
||||||
int sensorReading = analogRead(analogChannel);
|
while(webFile.available()) { // the webfile is avaible
|
||||||
client.print("analog input ");
|
client.write(webFile.read()); // send webfile to client
|
||||||
client.print(analogChannel);
|
}
|
||||||
client.print(" is ");
|
webFile.close();
|
||||||
client.print(sensorReading);
|
}
|
||||||
client.println("<br />");
|
break;
|
||||||
}
|
}
|
||||||
client.println("</html>");
|
// every line of text received from the client ends with \r\n
|
||||||
break;
|
if (c == '\n') {
|
||||||
}
|
// last character on line of received text
|
||||||
if (c == '\n') { // send a new blank line to indicate the end of the connection
|
// starting new line with next character read
|
||||||
currentLineIsBlank = true;
|
currentLineIsBlank = true;
|
||||||
} else if (c != '\r') {
|
}
|
||||||
currentLineIsBlank = false;
|
else if (c != '\r') {
|
||||||
}
|
// a text character was received from client
|
||||||
}
|
currentLineIsBlank = false;
|
||||||
}
|
}
|
||||||
delay(1); // give the web browser time to receive the data
|
} // end if (client.available())
|
||||||
client.stop(); // close the connection of the webserver
|
} // end while (client.connected())
|
||||||
}
|
delay(1); // give the web browser time to receive the data
|
||||||
}
|
client.stop(); // close the connection
|
||||||
|
} // end if (serverGateway)
|
||||||
|
} //end void loop
|
||||||
|
Loading…
Reference in New Issue
Block a user