This is a free implementation of firmware for Wi-Fi remote switches Itead Sonoff Basic and Dual written for Micropython
The device uses proprietary firmware, an Android app and a cloud for interconnection. Such an approach does not meet neither author's needs nor his philosophy. Any kind of home automation needlessly bound to internet connection and cloud services is a bad practice. Though electrical part of these devices looks pretty good and ready for daily usage. That's why the project was written.
- Uses your own MQTT server.
- Can be controlled just by writing a single bit to a proper MQ topic. You can use whatever you want: android apps, scripts etc
- Survives Wi-Fi and MQTT outages
- Handles hardware buttons to control the load.
- Sends health reports to the queue.
-
First of all you need to reflash your device with Micropython. Both Single and Dual models are based on ESP8266. There are plenty of detailed articles on the net so please use google. Here is an Example. In short, you need to solder a few pins and use RS-232 to TTL(3v) converter.
-
Find out MAC address of the device. Connect to REPL via serial port and get mac address of the device:
import network,ubinascii; ubinascii.hexlify(network.WLAN(network.STA_IF).config('mac'),':').decode()
- Make changes to a config.py:
- SSID
- PSK
- MQTT broker IP
- WEBREPL_PASSWORD (WebREPL)
- Write MAC address of your device to the 'SETTINGS' and set a name for it. See config.py.example
-
Copy project files to the root of the device flash.
-
(Optional) Connect pins to push-buttons. Your can find one in a local electrical equipment store. I just use a common garage door switch.
-
Install and configure IoTManager android app.
-
Write a persistent MQTT entry to configure your android app. Here's an exmaple(using mosquitto)
mosquitto_pub -h <mqtt_host> -r -t "/IoTmanager/<device_name>/config" -m "{\"id\":\"1\",\"page\":\"room1\",\"descr\":\"Top lights\",\"widget\":\"toggle\",\"topic\":\"/IoTmanager/<device_name>/relay_1\",\"color\":\"blue\"}"
The relay statuses will be published to the following topics:
/IoTmanager/<device_name>/relay_<0|1>/status
The simplest way to control a device:
Turn on relay 1:
mosquitto_pub -h <mqtt_host> -t /IoTmanager/<device_name>/relay_0/control -m 1
Turn off relay 2
mosquitto_pub -h <mqtt_host> -t /IoTmanager/<device_name>/relay_1/control -m 0
- Micropython >= 1.9.3
- MQTT server (Mosquitto 1.4.11 is the only tested one, should work with any other though)
Apache 2.0