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: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: SmartHome with sonoff, esp8266, mqtt and micropython

Post by 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: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: SmartHome with sonoff, esp8266, mqtt and micropython

Post by 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
Index to my micropython libraries.

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

Re: SmartHome with sonoff, esp8266, mqtt and micropython

Post by 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.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: SmartHome with sonoff, esp8266, mqtt and micropython

Post by pythoncoder » Mon Sep 04, 2017 8:51 am

To revive an old thread I've started experimenting with these Sonoff units and am encountering problems - I simply cannot get them working reliably when working autonomously running from mains power with no computer connection. Code which runs until interrupted (12 hours+) on other ESP8266 platforms crashes after 12 minutes on the Sonoff. I am using the same firmware build, the same application code, the same flashing procedure (including an initial erase) and locating the units in the same place (close to the WiFi AP) yet getting completely different results.

Has anyone else encountered this?

I also have problems actually getting a REPL. I can erase flash, install a build, get a successful verify message and yet get no REPL. Repeating the exact same steps sometimes works. Sometimes the serial port produces nothing, other times an endless stream of fatal exceptions from the vendor code. After spending a lot of time looking for causes in my flashing method and firmware image I started looking at the electronics.

There are aspects its design which I'm uncomfortable with. The mains PSU produces an isolated 3.3V supply. I can find no fault with this, it has excellent voltage accuracy, low noise and I can find no evidence of dropout issues when flashing or running code. However the ESP8266 circuitry is isolated from mains earth except when linked to an earthed PC. This strikes me as unwise with mains-bearing PCB tracks nearby. I also wondered about the lack of a groundplane on the PCB. Adding an earth and a groundplane immediately beneath the plastic baseplate definitely improves reliability.

With the mains earth lead connected to the electronics ground and the unit mounted on an earthed groundplane I can reliably flash firmware to old design Sonoff units. However I still can't run applications for more than a few minutes before a crash or (on one occasion) a spontaneous hard reset, whereupon the code ran for another few minutes before crashing.

I have so far completely failed to get a REPL on a new design Sonoff despite the above electrical measures.

Has anyone else encountered these issues? Any other comments/ideas/observations before the things go into my shelved projects box?
Peter Hinch
Index to my micropython libraries.

Post Reply