Provide ESP8266 based itead Sonoff with MQTT and 'Over the Air' or OTA firmware.
Install the ESP8266 development environment from esp8266-dev.
Copy the sonoff code files as follows:
- Create directory
esp8266-dev/work
and copy directorysonoff
and fileespupload.php
into it - Replace file
Makefile.common
in directoryesp8266-dev
Install a local web server for OTA and copy directory api
in webroot.
Update sonoff/user/user_config.h
with your specific Wifi and MQTT parameters.
Compile source with make
and flash once to sonoff using cable connection as shown in Peter Scargill's blog with make flash
. Do not connect AC power during the flash cable connection.
Compile and upload OTA images to your web server with make clean; make IMAGE=1; make register; make clean; make IMAGE=2; make register
.
Note: this software is not compatible with Pete's implementation.
The button on sonoff provides the following features:
- a short press toggles the relay. This will blink the LED twice and sends a MQTT status message like
stat/sonoff/POWER on
- three short presses start Wifi smartconfig which allows for SSID and Password configuration using an Android mobile phone with the ESP8266 SmartConfig app. The green LED will blink during the smartconfig period for 100 seconds. The MQTT server still needs to be configured using the
user_config.h
file - four short presses start OTA download of firmware. The green LED is lit during the update
- pressing the button for over four seconds resets settings to defaults as defined in
user_config.h
and reboots sonoff
Sonoff responds to the following MQTT commands:
- the relay can be controlled by
cmnd/sonoff/power on
,cmns/sonoff/power off
orcmnd/sonoff/power toggle
. The LED will blink twice and sends a MQTT status message likestat/sonoff/POWER on
. The same function can be initiated withcmnd/sonoff/light on
- the MQTT topic can be changed with
cmnd/sonoff/topic sonoff1
which reboots sonoff and makes it available for MQTT commands likecmnd/sonoff1/power on
- the OTA firmware location can be made known to sonoff by
cmnd/sonoff/otaurl http://sidnas2:80/api/sonoff/user1.bin
where sidnas2 is your webserver hosting the firmware. Reset to default withcmnd/sonoff/otaurl 1
- upgrade OTA firmware by
cmnd/sonoff/upgrade 1
- show status information by
cmnd/sonoff/status 1
Most MQTT commands will result in a status feedback like stat/sonoff/POWER On
.
See the code for other features.
To aid in finding the IP address of sonoff the network name will be ESP-<MQTT topic>
. So the default name is ESP-sonoff
.