This is a code repository for my lamp switch project. Aim of this project is to provide a simple self contained IOT light solution. No central server or cloud is required for operation of my module. My module is also fails safe. Failure of the module results in the relay staying in closed position allowing for light operation by turing on/off module power supply.
- ESP12-F board (ESP8266)
- 3V relay
- 3.3V power supply
- AC power detector
- Wall switch with 2 controlable outputs
Total price: ~7USD (excluding wall switch)
To build and install this project:
- Install Arduino IDE
- Add
http://arduino.esp8266.com/stable/package_esp8266com_index.json
in Arduino preferences->Extra URLs for Board Manager - Install ESP8266 in Board Manager
- Open the project
- Copy
config.h.example
toconfig.h
- Fill configuration parameters in
config.h
file. - Build&upload the code to ESP8266.
- Install
https://github.com/esp8266/arduino-esp8266fs-plugin
- Build the SPIFFS image.
To update the running module online see UI->HTTP update. You can aquire SPIFFS file by using "upload spiffs" function of the spiffs plugin. It will fail due to missing connection to ESP8266, but in logs you will find the path of build spiffs image.
Main UI with buttons for controlling the light and status info. No authorizations is provided / authorization has to be handled on network level.
This is a Web Progressive App and works nicely when added to Home Screen on Android.
Allows for updating app image and SPIFFS image after authorization. See config
parameters: none
returns: JSON with current state
example:
{
"lamp": "ON",
"switch": "OFF",
"switchLastChange": 124220188,
"systemTime": 167513477
}
parameters:
- (required) lampState - value has to be one off:
ON
,OFF
,TOGGLE
returns: JSON with current state (result of getState)
example:
$ http "lamp.local/setLamp?lampState=ON"
HTTP/1.1 200 OK
Connection: close
Content-Length: 87
Content-Type: application/json
{
"lamp": "ON",
"switch": "OFF",
"switchLastChange": 124220188,
"systemTime": 167647811
}