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
Diff: main.cpp
- Revision:
- 6:66b21f6166bd
- Parent:
- 5:280650ceb796
- Child:
- 7:bdf957914029
--- a/main.cpp Thu Mar 17 21:37:39 2016 +0000 +++ b/main.cpp Tue Apr 19 17:16:41 2016 +0000 @@ -5,7 +5,7 @@ //#include "DS18B20.h" Serial pc(USBTX, USBRX); -Serial esp(p28, p27); // tx, rx +Serial esp(p13, p14); // tx, rx //DS18B20 thermom(A0, DS18B20::RES_12_BIT); @@ -16,19 +16,19 @@ DigitalOut led4(LED4); // Digital Out and In pins, can be configured to any suitable pin depending on Platform -DigitalOut Outlet1(p25); -DigitalOut Outlet2(p24); -DigitalOut Outlet3(p23); -DigitalOut Outlet4(p22); -DigitalOut reset(p26); +DigitalOut Outlet1(p18); +DigitalOut Outlet2(p17); +DigitalOut Outlet3(p20); +DigitalOut Outlet4(p19); +DigitalOut reset(p29); int setOut2=0; // if 0, turn off when temp > // if 1, turn on when temp > -DHT tsensor(p21, DHT11); +DHT tsensor(p22, DHT11); -AnalogIn I1(p20); -AnalogIn Ain1(p19); +AnalogIn I1(p15); +AnalogIn Ain1(p16); //PwmOut speaker(p21); //AnalogIn Ain1(p18); @@ -100,7 +100,7 @@ wait(0.5); reset=1; Outlet1=1, Outlet2=1, Outlet3=1, Outlet4=1; - led1=0,led2=0,led3=1; + //led1=0,led2=0,led3=1; timeout=6000; getcount=500; getreply(); @@ -200,15 +200,15 @@ strcat(webbuff,setTmpOn); strcat(webbuff,"\"> </sup>"); } - strcat(webbuff, "<p><input type=\"radio\" name=\"outlet3\" value=\"1\" checked> Outlet 3 On"); - /*if(Outlet3==0) { + //strcat(webbuff, "<p><input type=\"radio\" name=\"outlet3\" value=\"1\" checked> Outlet 3 On"); + if(Outlet3==1) { strcat(webbuff, "<p><input type=\"radio\" name=\"Outlet 3\" value=\"0\" checked> Outlet 3 off"); strcat(webbuff, "<br><input type=\"radio\" name=\"Outlet 3\" value=\"1\" > Outlet 3 on"); } else { strcat(webbuff, "<p><input type=\"radio\" name=\"Outlet 3\" value=\"0\" > Outlet 3 off"); strcat(webbuff, "<br><input type=\"radio\" name=\"Outlet 3\" value=\"1\" checked> Outlet 3 on"); - }*/ - if(Outlet4==0) { + } + if(Outlet4==1) { 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"); } else {