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.


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.


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.


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.


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.