|All for less than a fiver!|
- Get the ESP8266 core for Arduino by following the instructions. I used the git version.
- Get the Arduino version of the Sonoff firmware and read the prerequisite section of its wiki.
- I also had to specify version 3.1 of MQTT in PubSubClient.h for correct interoperation with mosquitto on Raspian.
- Edit the sketch's user_config.h for your LAN.
- Under the IDE tools menu, set Flash size: "1M (64K SPIFFS)"
- Solder a pin header onto the board and connect an FTDI cable to the headers.
- Holding the Sonoff button down, plug the FTDI cable into the host and upload the firmware.
- The Arduino serial monitor comes in handy for troubleshooting, set the baud rate to 115200.
- The Arduino IDE allows specification of debug level, under the Tools menu, to get firmware debugging messages on the serial port. (Set this prior to upload, obviously.)
- I had to enable 802.11b networking on my router, before the Sonoff would connect.
- I installed mosquitto on a Raspberry Pi, and enabled rsyslog on it. I also installed mosquitto-clients on my laptop to keep an eye on the MQTT stream.
- On power-up the Sonoff creates a temporary access point, allowing direct configuration of networking parameters, if you've made a mistake, at IP address http://192.168.4.1. (This configuration page is also available during normal operation, at whatever address you've configured for it.)
- Once this firmware has been flashed, it can be upgraded OTA. (I installed nginx on my laptop and had it serve files from my ~/www directory to facilitate this.)