An offline-first IoT project on-air light for video meetings, using ESP32 & JavaScript with Moddable XS.
While the materials demonstrate using an ESP32 development board, it is possible using an ESP8266 with the same code (updated pins probably required) since Moddable runs on both platforms.
- ESP32
- Breadboard
- 2 tri-color LEDs
- male/male jumper wires
- slim USB battery pack
- Box (I used an Adabox container)
The dev environment was bootstrapped and managed using xs-dev
; however, that is not required if you want to go through the Moddable set up instructions manually or has been done previously.
After cloning this project repo, the ssid
and password
config fields in the manifest.json
to match your WiFi details. The project does not require any Internet access (i.e. "offline-first"), just a shared network for local Web UI and HTTP API control.
After wiring the hardware materials together to match the documented diagram, the code can be uploaded to the board.
Using xs-dev
:
xs-dev run --device esp32
Using mcconfig
:
mcconfig -d -m -p esp32
Once the LEDs are green for 3 seconds, the web UI should be available at http://on-air.local/
.
There are some HTTP API endpoints for checking and controlling the light outside of the web UI:
GET /api/state
: returns the current color if the light is on, otherwise returns[1023, 1023, 1023]
as "off"POST /api/toggle
: toggles the state of the light, using the last used color if the light is offPOST /api/color
: expects acolor
field in the body to set the color of the light, returns 204 status code if successful
Run using pm2
to control long running process:
pm2 start daemon/index.mjs --name on-air
The script (daemon/index.mjs
) watches the standard output stream from log stream
on MacOS for Camera events that include "turn off" and "turn off" messages. When it sees one of those messages, it will make a POST request to the /api/toggle
endpoint at the http://on-air.local
host. If it cannot reach on-air.local
, it will log the error and continue watching the log output.