SmartHome with sonoff, esp8266, mqtt and micropython

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
User avatar
kfricke
Posts: 310
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: SmartHome with sonoff, esp8266, mqtt and micropython

Postby kfricke » Thu Oct 13, 2016 10:15 pm

The local pusbutton of the iTead Sonoff switch is implemented now as well. Thank you Pythoncoder for that excellent micro-threading library!

The script does implement a MQTT subscriber as well as a MQTT publisher. The pushbutton is simply bound to a method that publishes the new state onto the MQTT broker. Switching the relay is still only triggered by the MQTT subscription.

(edit: and of course this is pushed to Github if anyone is interested!)

User avatar
pythoncoder
Posts: 1382
Joined: Fri Jul 18, 2014 8:01 am

Re: SmartHome with sonoff, esp8266, mqtt and micropython

Postby pythoncoder » Fri Oct 14, 2016 6:09 am

kfricke wrote:...Thank you Pythoncoder for that excellent micro-threading library!
I'm glad you're finding it useful :D

If you feel like experimenting with MQTT I've found it can get a bit flaky if WiFi connectivity isn't ideal. The implementation uses blocking sockets and these seem capable of blocking indefinitely. One test is to move the device out of range of the WiFi and then back in. Another test I do with wireless devices is to put one end of the link in the microwave and gradually close the door to slowly kill the signal (a metal tin would work just as well, but you can observe the unit in a microwave).

Perhaps MQTT is "good enough" for most purposes. A simple solution might be to use the watchdog timer, though I haven't actually tried this. In my application I apply a hardware reset to the ESP8266 to achieve the same end.

I'd be interested to hear if other people are experiencing the same issue.
Peter Hinch

User avatar
kfricke
Posts: 310
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: SmartHome with sonoff, esp8266, mqtt and micropython

Postby kfricke » Fri Oct 14, 2016 6:54 am

We should avoid to suggest anyone to put electronics into the microwave ;)

I must agree with you...
In my scenarios I have also encountered various blocking situations with the ESP and the MQTT library. It is flaky, leading to a WDT reset very often and dies with an exception. To avoid the productive devices running the REPL I tend to catch exceptions all over the place and perform a hard reset as suggested on the forum earlier.
Missing any cable and networke connection to the devices deployed here makes it hard to tackle.


Return to “Hardware Projects”

Who is online

Users browsing this forum: No registered users and 2 guests