Pot and LDR value Wifi logging TO Node-red and from there to local phant
Fork of ESP8266_LocalPhant_KL25Z by
Revision 3:5ba1cb5e6613, committed 2017-03-30
- Comitter:
- rushabkarani
- Date:
- Thu Mar 30 12:31:19 2017 +0000
- Parent:
- 2:817794b2f733
- Commit message:
- Esp8266 With NODE-RED
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 817794b2f733 -r 5ba1cb5e6613 main.cpp --- a/main.cpp Sun Jun 26 10:19:24 2016 +0000 +++ b/main.cpp Thu Mar 30 12:31:19 2017 +0000 @@ -5,6 +5,7 @@ //POT sensor AnalogIn pot(PTB0); +AnalogIn ldr(PTB1); //wifi UART port and baud rate ESP8266 wifi(PTE0, PTE1, 115200); @@ -13,21 +14,22 @@ char snd[255],resp[1000]; char http_cmd[300], comm[300]; -int timeout = 3000; //timeout for wifi commands +int timeout = 5000; //timeout for wifi commands //SSID and password for connection -#define SSID "Eduvance_WiFi" -#define PASS "eduvance" +#define SSID "eduvanceAP" +#define PASS "winteriscoming" //Remote IP -#define IP "192.168.0.2" +#define IP "192.168.0.22" //ldrvalue global variable -float ldrval = 0; +float ldrval = 0; +float potval = 0; //Public and private keys for phant -char* Public_Key = "eaWkxgdlQZszLEDKpy6OFeDeO8x"; -char* Private_Key = "25xqpAeBmzSml4Yjpr05Hj3jOBq"; +//char* Public_Key = "eaWkxgdlQZszLEDKpy6OFeDeO8x"; +//char* Private_Key = "25xqpAeBmzSml4Yjpr05Hj3jOBq"; //Wifi init function void wifi_initialize(void){ @@ -36,7 +38,7 @@ wifi.Reset(); //wait for 5 seconds for response, else display no response receiveed - if (wifi.RcvReply(resp, 5000)) + if (wifi.RcvReply(resp, 8000)) pc.printf("%s",resp); else pc.printf("No response"); @@ -83,7 +85,7 @@ void wifi_send(void){ pc.printf("******** Starting TCP connection on IP and port ********\r\n"); - wifi.startTCPConn(IP, 8080); //cipstart + wifi.startTCPConn(IP, 1880); //cipstart wifi.RcvReply(resp, timeout); if (wifi.RcvReply(resp, timeout)) pc.printf("%s",resp); @@ -92,7 +94,7 @@ wait(1); //create link - sprintf(http_cmd,"/input/%s?private_key=%s&val=%0.2f",Public_Key,Private_Key,ldrval); + sprintf(http_cmd,"/log?pot=%0.2f&ldr=%0.2f",potval,ldrval); pc.printf(http_cmd); pc.printf("******** Sending URL to wifi ********\r\n"); @@ -113,8 +115,9 @@ wifi_initialize(); while (1) { - ldrval = pot.read(); - pc.printf("Potentiometer ldrvalue=%.3f \r\n", ldrval); + potval = pot.read(); + ldrval = ldr.read(); + pc.printf("Potentiometer potvalue=%.3f & ldrvalue=%.3f\r\n",potval,ldrval); wifi_send(); wait(3);