wasghujkl

Dependencies:   ESP8266 mbed

Fork of thingspeak_LEDCONTROL by Karkhana Makerspace

Revision:
4:00c227a97ba9
Parent:
3:1722a03793c6
--- a/main.cpp	Tue May 22 05:02:54 2018 +0000
+++ b/main.cpp	Wed May 30 07:19:36 2018 +0000
@@ -3,7 +3,10 @@
  
 Serial pc(USBTX,USBRX);
 DigitalOut rled(LED1);
+DigitalOut bled(LED2);
+DigitalOut gled(LED3);
 
+        
 //wifi UART port and baud rate
 ESP8266 wifi(PTE0, PTE1, 115200);    // Class Variable Pin dexlaration for WIFI
 
@@ -25,12 +28,16 @@
 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;
+        gled=1;
+    
     pc.printf("******** Resetting wifi module ********\r\n");
     wifi.Reset();
     
@@ -90,8 +97,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,"/channels/500979/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
     pc.printf(http_cmd);
     
     pc.printf("******** Sending URL to wifi ********\r\n");
@@ -109,24 +116,47 @@
     //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]);
     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;
+        gled=1;
+        }
+    else if(resp[length-13]==50)
+
+ {       pc.printf("GREEN LED ON");
+        rled=1;
+        bled=0;
+        gled=1;
+
         }
-    else{
-        pc.printf("LED OFF");
+   else if(resp[length-13]==51)
+   
+   {
+        pc.printf("BLUE LED ON");
         rled=1;
-        }
+        bled=1;
+        gled=0;
+
+        }  
+     else {
+        pc.printf("waiting");
+        rled=1;
+        bled=1;
+        gled=1;
+    }
 }
-        
+   
 
 int main () {