"
Introduction
When playing1 with Mongoose OS2 on the ESP82663, I came to the conclusion it was great for building simple things.
So, I built a simple thing with it: a switch for my IoT light4.
Schematic
The BOM has two items: a NodeMCU style ESP8266 board; and a switch. We can use the ESP8266’s pullups so don’t need any external resistors. We won’t need a sophisticated CAD program:
ESP8266 board
Using a NodeMCU style board makes construction easy: electrically everything we need is on the board; mechanically it comes with handy mounting holes.
You could make a much smaller switch by choosing a different board, but I'm not sure that would be an advantage.
The switch
Getting a rotary encoder to work reliably was hassle, so I used a two way Mom-Off-Mom rocker switch instead. Digikey had a nice one5 made by TE Connectivity (part number 6-1571986-46).
Annoyingly the switch cost more than the ESP8266 board!
The case
I made a case by stacking slices of 3mm plywood, laser-cut to shape. PDFs for the case are available in the GitHub repo7.
Firmware
The ESP8266 runs a lightly modified version of the Mongoose AWS sample app.
Assuming that you’ve set up the necessary certificates and configured the MQTT device, you need only replace init.js
.
Functionality
When the switch is clicked up (down), the ESP8266 sets the related Amazon Device Shadow to a higher (lower) value. If the switch is held down, it gets set to the maximum (minimum) value.
Implementation
Firstly, the quality isn’t great.
The only non-trivial code is a crude task manager: this should be refactored into a separate library.
If you still want the code with these cavets, visit the GitHub repo8.
References
- 1. ./mongoose.html
- 2. https://mongoose-os.com
- 3. http://espressif.com/en/products/hardware/esp8266ex/overview
- 4. ../05/yauiotl.html
- 5. https://www.digikey.co.uk/product-detail/en/te-connectivity-alcoswitch-switches/6-1571986-4/450-1529-ND/1021826
- 6. http://www.te.com/commerce/DocumentDelivery/DDEController?Action=srchrtrv&DocNm=1571986&DocType=Customer+Drawing&DocLang=English
- 7. https://github.com/mjoldfield/esp8266-aws-switch
- 8. https://github.com/mjoldfield/esp8266-aws-switch