Table of Contents
- some glorious esp8266 in a Sonoff S20 power plug (NodeMCU v0.9 for development)
- something to turn on/off that may get attendants attention, that they would want to turn off. We chose a revolving light that we already had, an off-the-shelf lamp (like this one) which plugs to main via the Sonoff
To flash a Sonoff S20, solder the pins on the left of the push button, connect your USB-to-Serial convertor (RobotDyn CH340G in this case) to the headers like in the image below (from top to bottom, GND, TX, RX, 3.3v VCC), push Sonoff button while plugging in your USB-to-Serial convertor in your PC and then release the push button after a few seconds (check out this link and that one). Don't forget about the SPIFFS setting in Arduino IDE as we are using it to store custom settings via WifiManager (see step 6 below).
Unplug the 3V3 VCC cable to be able to watch the serial monitor when the Sonoff is powered on through main else you will fry the esp. You can also flash Sonoff's esp like this (be careful to not touch main current through the Sonoff when manipulating it).
It also looks like when the program is of a given size, the USB/serial adapter (CH340G at least) is not able to give enough current for the esp to run properly (crashes in loop with stacktraces). An FTDI adapter looks more reliable.
You can also use
screen /dev/ttyUSB0 115200 to watch the serial monitor, but Arduino IDE serial monitor is more practical to use as it is relaunched each time it detects when the USB/serial adapter is plugged to a running chip.
Using a FTDI as below is more practical and safer as it's able to properly power the Sonoff S20. Don't forget to set the jumper to 3.3V or you will fry the ESP.
- make the LED blink (GPIO 13 is the green LED, not 12 as it's the relay and blue LED)
- define how to detect the Fuz is open
- check out ArduinoOTA or similar for easy iterations
- connect to Fuz WiFi, would be great to use https://github.com/tzapu/WiFiManager
- send (reply?) message on Matrix (work is already done)
- make things easily configurable via internal webserver (WiFi, Matrix login/channel/message). I think tzapu/WiFiManager is able to do that, check out examples
- react to @mentions on Matrix
- handle long press for reset
- handle multiple Matrix rooms
- resolve HTTPS on the esp8266 directly
- properly notify when the Fuz is closed
- notify if the Fuz is open or closed on https://fuz.re
- investigate random crashes after some time, integrate the awesome EspSaveCrash library, maybe do as this dude here, but sending crash to HTTP server. See also https://arduino-esp8266.readthedocs.io/en/latest/faq/a02-my-esp-crashes.html
- DONE the Fuz is open when there is electricity in the basement and someone pushes the button. Someone wants to push the button because the revolving light is lightened up by the Sonoff S20 when it is powered up
and also each time someone mentions the Matrix account on Matrix; the S20 disables the revolving light when the button is pressed
sonoff_s20_wifimanager_with_custom_settings_and_led_status_and_reset_button_and_aruinoota_and_matrix_message.ino, in case ofSonoff S20 is not compatible with its only 1M flash. We should solder a bigger memory.
Authenticating…FAIL 18:43:52 [ERROR]: ERR: ERROR: Not Enough Space⇒ https://www.esp8266.com/viewtopic.php?f=32&t=19064#p80107 (see also step 6)
- DONE Unsurprisingly, it works, see this sketch I slightly adapted sonoff_s20_wifimanager_with_button_reset.ino, next step is to try to add custom options (Matrix login and room to post to), maybe adapt
https://github.com/tzapu/WiFiManager/blob/368ea928f014be9c1616b1a94caf81a8971142ee/examples/OnDemandConfigPortal/OnDemandConfigPortal.inocheck out sonoff_s20_wifimanager_with_custom_settings_and_led_status_and_reset_button.ino DOING, currently struggling with HTTPS, try using httpUpdateSecure.ino (includes some NTP!!, see also esp8266/Arduino#4749 as it's not instant) or BearSSL_CertStore.inoDONE (HTTP only through proxy though)! See sonoff_s20_wifimanager_with_custom_settings_and_led_status_and_reset_button_and_matrix_message.ino
- DONE Yup sonoff_s20_wifimanager_with_custom_settings_and_led_status_and_reset_button.ino, but you have to properly set up your Arduino IDE like this
DONE following matrix-esp8266.ino#L70-L109 sonoff_s20_multiwifi_matrix_events.ino (also implemented read receipts in sonoff_s20_wifimanager_longpress_matrix_events.ino so even if nobody mentions the Matrix account, we see it running)REMOVED in 4c74d44d02f1, to limit runtime crashes, useless feature
- DONE (only useful when using WifiManager) sonoff_s20_wifimanager_longpress_matrix_events.ino
- WON'T DO implemented in multiroom branch, but of little use
- INSECURELY/PARTIALLY DONE For reference: https://github.com/esp8266/Arduino/issues/4826#issuecomment-491813938 (insecure) https://github.com/esp8266/Arduino/pull/3271/files (more secure). https://github.com/SensorsIot/HTTPS-for-Makers https://github.com/knolleary/pubsubclient/issues/462#issuecomment-542911896 very promising example, finally. Also for POST-ing/PUT-ing https://github.com/esp8266/Arduino/issues/5975#issuecomment-483995654, https://www.esp8266.com/viewtopic.php?f=29&t=14054. We //insecurely// ping https://presence.fuz.re as doing the same on https://matrix.fuz.re was making the ESP systematically crash.
- DONE making the S20 regularly ping a remote server. This remote server would then send a message on Matrix saying Fuz is closed if it's not ping-ed after some delay. Implementing the latter using
MQTT (PubSubClient library)HTTP polling. simpler, have an HTTP server on the S20 indicating if the button has been pushed once, and have an always-on esp8266 poll this webserver and notify the Matrix channel and a remote server when it's gone after a few minutes. S20 webserver done in sonoff_s20_wifimanager_longpress_matrix_events_webserver_admin.ino (with an admin interface as a bonus), S20 part done in 450fdfcddf5a187fb261470427bf255231f175d5, server side on the Glitch platform also done (via a JSON database file as container gets killed after a while and to be able to recover after being killed)
- DONE Unfortunately, EspSaveCrash is not able to save crash information on flash and was removed. We did a complete rework/simplification, where the ESP is only pinging a remote server about its state and all the logic is on this server (in the future it could even be the server that tells the ESP to turn on or off the revolving light according to what the remote server replies to the HTTP ping). @mentions handling was also removed as it's not used in 4c74d44d02f179aed81a439ef1abf0fd14eb860c.
- DOING, when people push the button!
Today the button regularly pings a server (HTTPS requests) every ten seconds, this server registers pings from the button to notify on Matrix that the Fuz opens (on first
fuzisopen=1 call) or is closed when it's not pinged anymore after 5 minutes.
- http://blinkingled.cc/update-firmware-of-smart-switch-sonoff-s20/ Putting S20 in flash mode
- https://www.itead.cc/wiki/S20_Smart_Socket S20 specifications
- https://notenoughtech.com/category/home-automation/esp/ really great website about esp-based smart shits
- http://www.martyncurrey.com/category/esp8266/ nice little series of tutorials, may be obsolete
- https://diyprojects.io/hack-connected-sonoff-s20-plug-esp-easy-rules/ interesting part here is the hardware mod with a 3.5 mm jack used to connect the pins without opening the Sonoff case
- https://www.letscontrolit.com/forum/viewtopic.php?t=3263#p17124 GPIO15 physical location on Sonoff S20 PCB
- http://blog.zener.free.fr/index.php?post/2018/10/07/ESPEasy-et-le-Sonoff-S26 (French) how to flash Sonoff S26
- https://wiki.das-labor.org/w/Status-Bot this German hackerpace has its own presence button, really similar design
- https://www.iot-experiments.com/esp32-warning-light/ An old school warning light connected to an MQTT server thanks to an ESP32. Uses veroboard, a 12v warning light, an ESP32 (or an ESP8266), a IRF3205 MOSFET and 2N2222 NPN to drive the light+motor. Pretty cool build.
- Project created on Thu 19-09-19 by lomanic