Controlling Two LED's using Node-Red and ESp8266

Dependencies:   ESP8266 mbed

Fork of thingspeak_LEDCONTROL by Karkhana Makerspace

Files at this revision

API Documentation at this revision

Comitter:
animesh44
Date:
Fri Jun 01 07:32:09 2018 +0000
Parent:
3:1722a03793c6
Commit message:
Controlling Two LED's using Node-Red and ESP8266

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 1722a03793c6 -r a4fecf27c726 main.cpp
--- a/main.cpp	Tue May 22 05:02:54 2018 +0000
+++ b/main.cpp	Fri Jun 01 07:32:09 2018 +0000
@@ -3,6 +3,7 @@
  
 Serial pc(USBTX,USBRX);
 DigitalOut rled(LED1);
+DigitalOut gled(LED2);
 
 //wifi UART port and baud rate
 ESP8266 wifi(PTE0, PTE1, 115200);    // Class Variable Pin dexlaration for WIFI
@@ -15,17 +16,18 @@
 int timeout = 5000; //timeout for wifi commands
 
 //SSID and password for connection 
-#define SSID "Karkhana"     
-#define PASS "Karkhana2018"  
+#define SSID "Redmi Lucifer"     
+#define PASS "bhulgaya"  
 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.43.73"          // IP for thingspeak server. Remains same for al codes using thingspeak
 //#define IP "192.168.0.25"
 //waterlevelue global variable
 int ledstatus=0;
+int ledstatus1=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 = "QRCE7DOPVY3I49YN";                   // 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
@@ -82,7 +84,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);    
@@ -91,7 +93,7 @@
     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
+    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");
@@ -114,15 +116,21 @@
 {
     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]);
+    ledstatus=int(resp[length-26]);
+    ledstatus1=int(resp[length-13]);
+    pc.printf("%s",resp);
+    pc.printf("LED Status is %c\r\n",resp[length-26]);
+    pc.printf("LED2 Status is %c\r\n",resp[length-13]);
     pc.printf("LED status is %d\r\n",ledstatus);
-    if(resp[length-13]==49){
+    pc.printf("LED2 status is %d\r\n",ledstatus1);
+    if(resp[length-26]==116 && resp[length-13]==97){
         pc.printf("LED ON");
         rled=0;
+        gled=1;
         }
-    else{
+    else if(resp[length-26]==102 && resp[length-13]==116){
         pc.printf("LED OFF");
+        gled=0;
         rled=1;
         }
 }