Pratit Nayak
/
node_red_DL
wsedfyuji
Fork of thingspeak_LEDCONTROL by
Revision 4:a8e100b532ee, committed 2018-05-30
- Comitter:
- pratit911
- Date:
- Wed May 30 07:18:44 2018 +0000
- Parent:
- 3:1722a03793c6
- Commit message:
- qwerghj
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue May 22 05:02:54 2018 +0000 +++ b/main.cpp Wed May 30 07:18:44 2018 +0000 @@ -3,10 +3,10 @@ Serial pc(USBTX,USBRX); DigitalOut rled(LED1); - +DigitalOut bled(LED2); //wifi UART port and baud rate ESP8266 wifi(PTE0, PTE1, 115200); // Class Variable Pin dexlaration for WIFI - + //buffers for wifi library char snd[255],resp[9000]; char http_cmd[300], comm[300]; @@ -19,18 +19,21 @@ #define PASS "Karkhana2018" void control_led(void); //Remote IP -#define IP "184.106.153.149" // IP for thingspeak server. Remains same for al codes using thingspeak +#define IP "192.168.88.76" // IP for thingspeak server. Remains same for al codes using thingspeak //#define IP "192.168.0.25" //waterlevelue global variable int ledstatus=0; //Public and private keys for phant -char* Update_Key = "QRCE7DOPVY3I49YN"; // Copy the read key for your channel and paste it here. +char* Update_Key = "OPETON9L7UP3FCOP"; // Copy the read key for your channel and paste it here. //char* Private_Key = "GPoWnRM60yidrB0e1pXD"; //Wifi init function. Sets the module to connect to wifi accesspoint with ssid and password mentioned above void wifi_initialize(void){ + rled=1; + bled=1; + pc.printf("******** Resetting wifi module ********\r\n"); wifi.Reset(); @@ -82,7 +85,7 @@ void wifi_send(void){ pc.printf("******** Starting TCP connection on IP and port ********\r\n"); - wifi.startTCPConn(IP,80); //cipstart + wifi.startTCPConn(IP,1880); //cipstart wifi.RcvReply(resp, timeout); if (wifi.RcvReply(resp, timeout)) pc.printf("%s",resp); @@ -90,8 +93,8 @@ pc.printf("No response while starting TCP connection \r\n"); wait(1); - //create link - sprintf(http_cmd,"/channels/501352/fields/1.json?api_key=%s&results=2",Update_Key); // Forms the url for transmitting to thingspeak server. the format can be seen on thingspeak site as well + //create link + sprintf(http_cmd,"/status?"); // Forms the url for transmitting to thingspeak server. the format can be seen on thingspeak site as well pc.printf(http_cmd); pc.printf("******** Sending URL to wifi ********\r\n"); @@ -109,24 +112,72 @@ //wifi.RcvReply(resp, timeout); //pc.printf("%s", resp); } + void control_led(void) -{ - int length=strlen(resp); - pc.printf("Length of response: %d\r\n",strlen(resp)); - ledstatus=int(resp[length-13]); - pc.printf("LED Status is %c\r\n",resp[length-13]); +{ +int length=strlen(resp); +pc.printf("%s",resp); +pc.printf("Length of response: %d\r\n",strlen(resp)); + + +/*if(resp[8]=='t') + { + rled=0; + pc.printf("LED1 is ON"); + wait(1); + if(resp[20]=='t') + {bled=0; + pc.printf("LED2 is ON"); + wait(1); + } + else + bled=1; + pc.printf("LED2 is FALSE"); + wait(1); + + } + else if(resp[8]=='f') + { + + rled=1; + pc.printf("LED1 is OFF"); + wait(1); + if(resp[21]=='t') + {bled=0; + pc.printf("LED2 is ON"); + wait(1); + } + else + bled=1; + pc.printf("LED2 is OFF"); + wait(1); + */ + + /* ledstatus=int(resp[length-13]); + pc.printf("LED Status is %c\r\n",resp[length-13]); pc.printf("LED status is %d\r\n",ledstatus); if(resp[length-13]==49){ - pc.printf("LED ON"); + pc.printf("RED LED ON"); rled=0; + bled=1; + } - else{ - pc.printf("LED OFF"); + else if(resp[length-13]==50) + + { pc.printf("GREEN LED ON"); rled=1; - } -} - + bled=0; + + } + else { + pc.printf("waiting"); + rled=1; + bled=1; + gled=1; + }*/ + +} int main () {