Test
Dependencies: mbed as3935 ESP8266NodeMCUInterface
Diff: main.cpp
- Revision:
- 3:c69be808548f
- Parent:
- 1:5508e5a66441
--- a/main.cpp Mon Nov 09 02:35:49 2020 +0000 +++ b/main.cpp Mon Nov 09 21:38:12 2020 +0000 @@ -28,6 +28,13 @@ char distanceKM; unsigned long time; }; + +union rawReceivedData +{ + struct DATA struc; + char dataString[sizeof(DATA)]; +}; + //using namespace std::chrono //DECLARATIONS: GLOBAL VARIABLES DigitalOut led1(LED1); //DEBUGGING: On-board LED used for debugging purposes @@ -42,12 +49,14 @@ DigitalOut wifiRST(p26); //Reset signal to the ESP8266 Device char ssid[32] = "GTother"; //enter WiFi router ssid inside the quotes char pwd [32] = "GeorgeP@1927"; //enter WiFi router password inside the quotes -char serverIP [32] = "143.215.104.115"; //The server IP to connect to (the main mBed) +char serverIP [32] = "143.215.99.29"; //The server IP to connect to (the main mBed) +//char serverIP [32] = "143.215.104.115"; //The server IP to connect to (the main mBed) Timer timeoutTimer; //A timer in case of ESP8266 timeouts unsigned int timeout; //A maximum time (in seconds) before timeout int county; //A counter for timeouts in the ESP8266 bool ended; //A boolean letting us know when the ESP8266's role is terminated -DATA dataToSend; //A struct to send over TCP to the server +union rawReceivedData dataToSend; //A struct to send over TCP to the server + //DECLARATIONS: FUNCTION PROTOTYPES void LightningDetected(); //Interrupt routine to handle the event of lightning occurring @@ -72,10 +81,15 @@ SetupLightningDetector(); pc.printf("Ready!\r\n"); clocky.start(); + dataToSend.struc.distanceKM = 5; + dataToSend.struc.detectorID = 1; + dataToSend.struc.time = 0x0F; while(1) { //Blinky - wait(1); + pc.printf("Test packet send!"); + wifi.send((char *)dataToSend.dataString, sizeof(DATA)); //Send the data + wait(3); led1 = !led1; //sleep(1); } @@ -106,17 +120,17 @@ { // detection // pc.printf(" Lightning detection\r\n"); dataTEMP[0] = ld.lightningDistanceKm(); //Shove the distance into index 0 - dataToSend.distanceKM = dataTEMP[0]; //Shove the distance into the struct - pc.printf("Lightning detection, distance=%dm\r\n", dataTEMP); + dataToSend.struc.distanceKM = dataTEMP[0]; //Shove the distance into the struct + pc.printf("Lightning detection, distance=%dm\r\n", dataTEMP[0]); pc.printf("Energy %d\r\n", ld.getEnergy()); ld.clearStats(); //Clear the contents and get } dataTEMP[1] = (char)LIGHTNINGDETECTORID; //Shove the detector's ID into index 1 - dataToSend.detectorID = (char)LIGHTNINGDETECTORID; //Shove thed etector's dsitance into the struct - dataToSend.time = clocky.read(); //Shove the time in milliseconds into the struct + dataToSend.struc.detectorID = (char)LIGHTNINGDETECTORID; //Shove thed etector's dsitance into the struct + dataToSend.struc.time = clocky.read(); //Shove the time in milliseconds into the struct wait(0.5); - wifi.send(dataTEMP, 2); //Send the data - clocky.start(); //Start the clock again + //wifi.send((char *)dataToSend.dataString, sizeof(DATA)); //Send the data + clocky.start(); //Start the clock again //TODO: Send the struct