Demo code for a Wi-Fi controlled wall outlet that monitors light intensity, temperature, and motion and can control which plugs are supplied with power based off of user preference.

Dependencies:   BH1750 DHT11_Lib mbed

Fork of ECE4180_Lab4_ESP8266_IoT_Outlets by Deron Mai

Revision:
11:74be5786e4b0
Parent:
9:69283f36da94
Child:
12:9de0e402ff17
--- a/main.cpp	Sat Apr 23 20:14:53 2016 +0000
+++ b/main.cpp	Sat Apr 23 22:22:59 2016 +0000
@@ -107,8 +107,8 @@
     pc.printf("\f\n\r------------ ESP8266 Hardware Reset --------------\n\r");
     wait(0.5);
     reset=1;
-    Outlet1=1, Outlet2=1, Outlet3=0, Outlet4=1;
-    //led1=0,led2=0,led3=1;
+    Outlet1=1, Outlet2=1, Outlet3=1, Outlet4=1;
+    led1=0,led2=0,led3=1,led4=1;
     timeout=6000;
     getcount=500;
     getreply();
@@ -142,11 +142,11 @@
         }
         if (setOut3 == 0) { //turn on when light <
             if (lightSensor.readIntesity() < lighton) {
-                Outlet3 = 0;
+                Outlet3 = 1;
                 led3 = 1;
             }
             else {
-                Outlet3 = 1;
+                Outlet3 = 0;
                 led3 = 0;
             }
         }        
@@ -252,7 +252,7 @@
         strcat(webbuff, "<br><input type=\"radio\" name=\"outlet3\" value=\"1\" checked>  Outlet 3 is always OFF");
         strcat(webbuff,"\ </sup>");
     }
-    if(Outlet4==1) {
+    if(Outlet4==0) {
         strcat(webbuff, "<p><input type=\"radio\" name=\"outlet4\" value=\"0\" checked>  Outlet 4 off");
         strcat(webbuff, "<br><input type=\"radio\" name=\"outlet4\" value=\"1\" >  Outlet 4 on");
         pc.printf("outlet4 == 1\r\n");
@@ -404,13 +404,13 @@
         }
         if( strstr(webdata, "outlet4=1") != NULL ) {
             led4=1;
-            Outlet4=0;
+            Outlet4=1;
             pc.printf("outlet4 set ON\r\n");
         }
         //else pc.printf("outlet4 on not found\r\n");
         if( strstr(webdata, "outlet4=0") != NULL ) {
             led4=0;
-            Outlet4=1;
+            Outlet4=0;
             pc.printf("outlet4 set OFF\r\n");
         }
         //else pc.printf("outlet4 off not found\r\n");