Regenerating PPM signal based on distances from ultrasonic sensors, ESP8266 for connectin via wifi. Autonomous quadcopter behaviour, autonomou height holding. Flying direction based on front and back ultrasonic sensors.
Dependencies: ConfigFile HCSR04 PID PPM2 mbed-rtos mbed
Diff: ESP8266/Server.h
- Revision:
- 9:86a5af9935b1
- Parent:
- 2:d172c9963f87
- Child:
- 10:bb9c778f8e3e
--- a/ESP8266/Server.h Thu Oct 26 17:36:52 2017 +0000 +++ b/ESP8266/Server.h Fri Oct 27 09:09:24 2017 +0000 @@ -1,5 +1,6 @@ #include "mbed.h" #include "rtos.h" +#include "hardware.h" RawSerial esp(p9, p10); // tx, rx @@ -39,9 +40,7 @@ int port =80; // set server port int SERVtimeout =5; // set server timeout in seconds in case link breaks. -char P[6] = "7.2"; -char I[6] = "6.3"; -char D[6] = "1.8"; + //serverThread.start(serverRun); @@ -71,6 +70,7 @@ getreply(); esp.baud(115200); // ESP8266 baudrate. Maximum on KLxx' is 115200, 230400 works on K20 and K22F startserver(); + loadConfigFile(); while(1){ if(DataRX==1) { ReadWebData(); @@ -107,13 +107,16 @@ strcat(webbuff, "<br><input type=\"radio\" name=\"led1\" value=\"1\" checked> LED 1 on<br>"); } strcat(webbuff, "P: <input type=\"text\" name=\"proportional\" size=6 value=\""); - strcat(webbuff, P); + ConvertToCharArray(_P); + strcat(webbuff, _str); strcat(webbuff, "\"><br>"); strcat(webbuff, "I: <input type=\"text\" name=\"integral\" size=6 value=\""); - strcat(webbuff, I); + ConvertToCharArray(_I); + strcat(webbuff, _str); strcat(webbuff, "\"><br>"); strcat(webbuff, "D: <input type=\"text\" name=\"derivative\" size=6 value=\""); - strcat(webbuff, D); + ConvertToCharArray(_D); + strcat(webbuff, _str); strcat(webbuff, "\"><br>"); strcat(webbuff, "<p><input type=\"radio\" name=\"nothing\" value=\"1\" checked>"); strcat(webbuff, "<p><input type=\"submit\" value=\"send-refresh\" style=\"background: #3498db;"); @@ -213,13 +216,14 @@ int i = 0; while(*p_webdata != '&'){ pc.printf("%c", *p_webdata); - P[i] = *p_webdata; + _str[i] = *p_webdata; p_webdata += 1; i++; } pc.printf("\n\r"); - P[i] = '\0'; - pc.printf("proportional: %s", P); + _str[i] = '\0'; + pc.printf("proportional: %s", _str); + _P = atof(_str); pc.printf("\n\r end of looking for data \n\r"); } if (strstr(webdata, "integral") != NULL){ @@ -229,13 +233,14 @@ int i = 0; while(*p_webdata != '&'){ pc.printf("%c", *p_webdata); - I[i] = *p_webdata; + _str[i] = *p_webdata; p_webdata += 1; i++; } pc.printf("\n\r"); - I[i] = '\0'; - pc.printf("integral: %s", I); + _str[i] = '\0'; + pc.printf("integral: %s", _str); + _I = atof(_str); pc.printf("\n\r end of looking for data \n\r"); } @@ -246,13 +251,14 @@ int i = 0; while(*p_webdata != '&'){ pc.printf("%c", *p_webdata); - D[i] = *p_webdata; + _str[i] = *p_webdata; p_webdata += 1; i++; } pc.printf("\n\r"); - D[i] = '\0'; - pc.printf("derivative: %s", D); + _str[i] = '\0'; + pc.printf("derivative: %s", _str); + _D = atof(_str); pc.printf("\n\r end of looking for data \n\r"); } sprintf(channel, "%d",linkID); @@ -264,6 +270,7 @@ } webcounter++; sprintf(webcount, "%d",webcounter); + // Save data to configFile }else{ memset(webbuff, '\0', sizeof(webbuff)); esp.attach(&callback);