User Tools

Site Tools


projets:fuz:presence_button

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
projets:fuz:presence_button [2019/12/11 22:06]
lomanic [Current status] multiroom status
projets:fuz:presence_button [2020/05/11 00:02] (current)
lomanic [Current status] update current status on @mentions
Line 18: Line 18:
 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. 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 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**.+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**.
  
 {{:​projets:​fuz:​presence_button:​sonoff_s20_ftdi_pinout.jpg?​200|}} {{:​projets:​fuz:​presence_button:​sonoff_s20_ftdi_pinout.jpg?​200|}}
Line 26: Line 26:
 See [[https://​github.com/​Lomanic/​presence-button|Lomanic/​presence-button]] on Github. See [[https://​github.com/​Lomanic/​presence-button|Lomanic/​presence-button]] on Github.
  
-See [[https://​glitch.com/​edit/#​!/​presence-button|presence-button project]] on glitch.com for the remote server part.+See [[https://​glitch.com/​edit/#​!/​presence-button|presence-button project]] on glitch.com for the remote server part ([[https://​git.interhacker.space/​Lomanic/​presence-button-web|sourcecode mirror]]).
 ===== Roadmap ===== ===== Roadmap =====
   - make the LED blink (GPIO 13 is the green LED, **not 12** as it's the relay and blue LED)   - make the LED blink (GPIO 13 is the green LED, **not 12** as it's the relay and blue LED)
Line 40: Line 40:
   - properly notify when the Fuz is closed   - properly notify when the Fuz is closed
   - notify if the Fuz is open or closed on https://​fuz.re   - notify if the Fuz is open or closed on https://​fuz.re
 +  - investigate random crashes after some time, integrate the awesome [[https://​github.com/​krzychb/​EspSaveCrash|EspSaveCrash]] library, maybe do as this dude [[https://​www.esp8266.com/​viewtopic.php?​f=6&​t=18716&​start=4#​p79055|here]],​ but sending crash to HTTP server. See also https://​arduino-esp8266.readthedocs.io/​en/​latest/​faq/​a02-my-esp-crashes.html
   - ??   - ??
   - profit!   - profit!
Line 49: Line 50:
   - **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 rotating 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 rotating light when the button is pressed   - **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 rotating 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 rotating light when the button is pressed
   - **DONE** <​del>​[[https://​gist.github.com/​Lomanic/​b0b5e3eba81ecdc4f3065b5b3561bc92|sonoff_s20_wifimanager_with_custom_settings_and_led_status_and_reset_button_and_aruinoota_and_matrix_message.ino]],​ in case of ''​Authenticating...FAIL 18:43:52 [ERROR]: ERR: ERROR[4]: Not Enough Space''​ :-( => https://​www.esp8266.com/​viewtopic.php?​f=32&​t=19064#​p80107 (see also step 6)</​del>​ Sonoff S20 is not compatible with its only 1M flash   - **DONE** <​del>​[[https://​gist.github.com/​Lomanic/​b0b5e3eba81ecdc4f3065b5b3561bc92|sonoff_s20_wifimanager_with_custom_settings_and_led_status_and_reset_button_and_aruinoota_and_matrix_message.ino]],​ in case of ''​Authenticating...FAIL 18:43:52 [ERROR]: ERR: ERROR[4]: Not Enough Space''​ :-( => https://​www.esp8266.com/​viewtopic.php?​f=32&​t=19064#​p80107 (see also step 6)</​del>​ Sonoff S20 is not compatible with its only 1M flash
-  - **DONE** Unsurprisingly,​ it works, see this sketch I slightly adapted [[https://​gist.github.com/​Lomanic/​798936d9564fb5d42ee3806e15e82c2f|sonoff_s20_wifimanager_with_button_reset.ino]],​ next step is try to add custom options (Matrix login and room to post to), maybe adapt <​del>​https://​github.com/​tzapu/​WiFiManager/​blob/​368ea928f014be9c1616b1a94caf81a8971142ee/​examples/​OnDemandConfigPortal/​OnDemandConfigPortal.ino</​del>​ check out [[https://​gist.github.com/​Lomanic/​e8f4938202864c7b8e6da00211c07943|sonoff_s20_wifimanager_with_custom_settings_and_led_status_and_reset_button.ino]]+  - **DONE** Unsurprisingly,​ it works, see this sketch I slightly adapted [[https://​gist.github.com/​Lomanic/​798936d9564fb5d42ee3806e15e82c2f|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 <​del>​https://​github.com/​tzapu/​WiFiManager/​blob/​368ea928f014be9c1616b1a94caf81a8971142ee/​examples/​OnDemandConfigPortal/​OnDemandConfigPortal.ino</​del>​ check out [[https://​gist.github.com/​Lomanic/​e8f4938202864c7b8e6da00211c07943|sonoff_s20_wifimanager_with_custom_settings_and_led_status_and_reset_button.ino]]
   - <​del>​**DOING**,​ currently struggling with HTTPS, try using [[https://​github.com/​esp8266/​Arduino/​blob/​308e131dee0271f60459933b1315ec88fc2004a5/​libraries/​ESP8266httpUpdate/​examples/​httpUpdateSecure/​httpUpdateSecure.ino|httpUpdateSecure.ino]] (includes some NTP!!, see also [[https://​github.com/​esp8266/​Arduino/​issues/​4749|esp8266/​Arduino#​4749]] as it's not instant) or [[https://​github.com/​esp8266/​Arduino/​blob/​308e131dee0271f60459933b1315ec88fc2004a5/​libraries/​ESP8266WiFi/​examples/​BearSSL_CertStore/​BearSSL_CertStore.ino|BearSSL_CertStore.ino]]</​del>​ **DONE** (HTTP only through proxy though)! See [[https://​gist.github.com/​Lomanic/​fe318c9de4061493160cfb0c5349dfcd|sonoff_s20_wifimanager_with_custom_settings_and_led_status_and_reset_button_and_matrix_message.ino]]   - <​del>​**DOING**,​ currently struggling with HTTPS, try using [[https://​github.com/​esp8266/​Arduino/​blob/​308e131dee0271f60459933b1315ec88fc2004a5/​libraries/​ESP8266httpUpdate/​examples/​httpUpdateSecure/​httpUpdateSecure.ino|httpUpdateSecure.ino]] (includes some NTP!!, see also [[https://​github.com/​esp8266/​Arduino/​issues/​4749|esp8266/​Arduino#​4749]] as it's not instant) or [[https://​github.com/​esp8266/​Arduino/​blob/​308e131dee0271f60459933b1315ec88fc2004a5/​libraries/​ESP8266WiFi/​examples/​BearSSL_CertStore/​BearSSL_CertStore.ino|BearSSL_CertStore.ino]]</​del>​ **DONE** (HTTP only through proxy though)! See [[https://​gist.github.com/​Lomanic/​fe318c9de4061493160cfb0c5349dfcd|sonoff_s20_wifimanager_with_custom_settings_and_led_status_and_reset_button_and_matrix_message.ino]]
   - **DONE** Yup [[https://​gist.github.com/​Lomanic/​e8f4938202864c7b8e6da00211c07943|sonoff_s20_wifimanager_with_custom_settings_and_led_status_and_reset_button.ino]],​ but you have to properly set up your Arduino IDE [[https://​github.com/​esp8266/​Arduino/​issues/​5699#​issuecomment-459619483|like this]]   - **DONE** Yup [[https://​gist.github.com/​Lomanic/​e8f4938202864c7b8e6da00211c07943|sonoff_s20_wifimanager_with_custom_settings_and_led_status_and_reset_button.ino]],​ but you have to properly set up your Arduino IDE [[https://​github.com/​esp8266/​Arduino/​issues/​5699#​issuecomment-459619483|like this]]
-  - **DONE** following [[https://​github.com/​matt-williams/​matrix-esp8266/​blob/​master/​matrix-esp8266.ino#​L70-L109|matrix-esp8266.ino#​L70-L109]] [[https://​gist.github.com/​Lomanic/​06c1a2d873dfbd9be93db7c965117f91|sonoff_s20_multiwifi_matrix_events.ino]] (also implemented [[https://​matrix.org/​docs/​spec/​client_server/​latest#​post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid|read receipts]] in [[https://​gist.github.com/​Lomanic/​dba3cd9f93161cc1acc32c83197298eb/​e8fb3810c208f21e2d62c4d173d6801aec0b3a80|sonoff_s20_wifimanager_longpress_matrix_events.ino]] so even if nobody mentions the Matrix account, we see it running)+  - <del>**DONE** following [[https://​github.com/​matt-williams/​matrix-esp8266/​blob/​master/​matrix-esp8266.ino#​L70-L109|matrix-esp8266.ino#​L70-L109]] [[https://​gist.github.com/​Lomanic/​06c1a2d873dfbd9be93db7c965117f91|sonoff_s20_multiwifi_matrix_events.ino]] (also implemented [[https://​matrix.org/​docs/​spec/​client_server/​latest#​post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid|read receipts]] in [[https://​gist.github.com/​Lomanic/​dba3cd9f93161cc1acc32c83197298eb/​e8fb3810c208f21e2d62c4d173d6801aec0b3a80|sonoff_s20_wifimanager_longpress_matrix_events.ino]] so even if nobody mentions the Matrix account, we see it running)</​del>​ **REMOVED** in [[https://​git.interhacker.space/​Lomanic/​presence-button/​commit/​4c74d44d02f179aed81a439ef1abf0fd14eb860c|4c74d44d02f1]],​ to limit runtime crashes, useless feature
   - **DONE** (only useful when using WifiManager) [[https://​gist.github.com/​Lomanic/​dba3cd9f93161cc1acc32c83197298eb|sonoff_s20_wifimanager_longpress_matrix_events.ino]]   - **DONE** (only useful when using WifiManager) [[https://​gist.github.com/​Lomanic/​dba3cd9f93161cc1acc32c83197298eb|sonoff_s20_wifimanager_longpress_matrix_events.ino]]
-  - **TO BE TESTED** see [[https://​github.com/​Lomanic/​presence-button/​tree/​multiroom|multiroom branch]] +  - **WON'T DO** implemented in [[https://​github.com/​Lomanic/​presence-button/​tree/​multiroom|multiroom branch]], but of little use 
-  - **TODO** 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+  - **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. [[https://​git.interhacker.space/​Lomanic/​presence-button/​commit/​a0d852c1ed49de9c049d2704f0af9fc154c130fd|We //​insecurely//​ ping https://​presence-button.glitch.me]] 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 <​del>​MQTT ([[https://​github.com/​knolleary/​pubsubclient|PubSubClient library]])</​del>​ HTTP polling. <​del>​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 [[https://​gist.github.com/​Lomanic/​3ac81aa6bb5ce4cdb88da3a76fe4aa1c|sonoff_s20_wifimanager_longpress_matrix_events_webserver_admin.ino]] (with an admin interface as a bonus)</​del>,​ S20 part done in [[https://​github.com/​Lomanic/​presence-button/​commit/​450fdfcddf5a187fb261470427bf255231f175d5|450fdfcddf5a187fb261470427bf255231f175d5]],​ server side on the Glitch platform also done (via a JSON log file as container gets killed after a while and to be able to recover after being killed)   - **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 <​del>​MQTT ([[https://​github.com/​knolleary/​pubsubclient|PubSubClient library]])</​del>​ HTTP polling. <​del>​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 [[https://​gist.github.com/​Lomanic/​3ac81aa6bb5ce4cdb88da3a76fe4aa1c|sonoff_s20_wifimanager_longpress_matrix_events_webserver_admin.ino]] (with an admin interface as a bonus)</​del>,​ S20 part done in [[https://​github.com/​Lomanic/​presence-button/​commit/​450fdfcddf5a187fb261470427bf255231f175d5|450fdfcddf5a187fb261470427bf255231f175d5]],​ server side on the Glitch platform also done (via a JSON log file as container gets killed after a while and to be able to recover after being killed)
   - **ALMOST DONE** check out [[https://​github.com/​Lomanic/​presence-button/​commit/​450fdfcddf5a187fb261470427bf255231f175d5|450fdfcddf5a187fb261470427bf255231f175d5]] and https://​glitch.com/​edit/#​!/​presence-button [[https://​presence-button.glitch.me/​|presence-button]],​ to be integrated on fuz.re   - **ALMOST DONE** check out [[https://​github.com/​Lomanic/​presence-button/​commit/​450fdfcddf5a187fb261470427bf255231f175d5|450fdfcddf5a187fb261470427bf255231f175d5]] and https://​glitch.com/​edit/#​!/​presence-button [[https://​presence-button.glitch.me/​|presence-button]],​ to be integrated on fuz.re
 +  - **"​DONE"​** Unfortunately,​ [[https://​github.com/​krzychb/​EspSaveCrash|EspSaveCrash]] is not able to save crash information on flash and [[https://​git.interhacker.space/​Lomanic/​presence-button/​commit/​404c440ed4128d0a19e97092025c69cfb92c612e|was removed]]. Maybe a completely rework is needed as we may use too much RAM or something, where the ESP would only be pinging a remote server about its state and all the logic would be on this server (it would be the server that tells the ESP to turn on or off the rotating light). Maybe also remove @mentions handling as it's not used before a complete rework ([[https://​git.interhacker.space/​Lomanic/​presence-button/​commit/​4c74d44d02f179aed81a439ef1abf0fd14eb860c|removed]].
   - ??   - ??
-  - **TODO**+  - **DOING**, when people push the button and the button doesn'​t crash after some time
  
-Today the button can notify on Matrix when it's pressed after initialization or after being notified on Matrix, and a server registers pings from the button to notify on Matrix that the Fuz is closed.+Today the button can notify on Matrix when it's pressed after initialization or after being notified on Matrix, and a server registers pings from the button to notify on Matrix that the Fuz is closed ​when it's not pinged anymore.
  
 Next steps: Next steps:
  
-  - investigate random crashes after some time, integrate ​the awesome ​[[https://​github.com/​krzychb/EspSaveCrash|EspSaveCrash]] librarymaybe do as this dude [[https://www.esp8266.com/viewtopic.php?​f=6&​t=18716&​start=4#​79055|here]],​ but sending crash to HTTP server. See also https://arduino-esp8266.readthedocs.io/en/latest/​faq/​a02-my-esp-crashes.html +  - huge refactoring of the code is needed, it's a huge pile of hacks, hard to work on, follow how it's done in [[https://​github.com/​biohazardxxx/ESP_WiFiSwitch|this similar project]] (separate files?)also fix button reset [[https://github.com/biohazardxxx/ESP_WiFiSwitch/blob/1c642fe2b00fbf83324e2228826ad341f687ce45/ESP_WiFiSwitch.ino#L136-L172|with a ticker like in this project]]
-  ​handle multiple matrix channels configured (to listen to and to reply to)+
   - resolve HTTPS locally instead of relying on an HTTP/HTTPS proxy   - resolve HTTPS locally instead of relying on an HTTP/HTTPS proxy
- 
-===== Arduino sketch revisions ===== 
- 
-In chronological order for a better comprehension compared to the note-taking style above 
- 
-  * [[https://​gist.github.com/​Lomanic/​1fc51b4ae0df0d69c9e994ee8d6a9cbe|sonoff_s20_blinky_led.ino]] 
-  * [[https://​gist.github.com/​Lomanic/​798936d9564fb5d42ee3806e15e82c2f|sonoff_s20_wifimanager_with_button_reset.ino]] 
-  * [[https://​gist.github.com/​Lomanic/​e8f4938202864c7b8e6da00211c07943|sonoff_s20_wifimanager_with_custom_settings_and_led_status_and_reset_button.ino]] 
-  * [[https://​gist.github.com/​Lomanic/​fe318c9de4061493160cfb0c5349dfcd|sonoff_s20_wifimanager_with_custom_settings_and_led_status_and_reset_button_and_matrix_message.ino]] 
-  * [[https://​gist.github.com/​Lomanic/​06c1a2d873dfbd9be93db7c965117f91|sonoff_s20_multiwifi_matrix_events.ino]] 
-  * [[https://​gist.github.com/​Lomanic/​dba3cd9f93161cc1acc32c83197298eb|sonoff_s20_wifimanager_longpress_matrix_events.ino]] 
-  * [[https://​gist.github.com/​Lomanic/​3ac81aa6bb5ce4cdb88da3a76fe4aa1c|sonoff_s20_wifimanager_longpress_matrix_events_webserver_admin.ino]] 
- 
-Subsequent versions on [[https://​github.com/​Lomanic/​presence-button|Github Lomanic/​presence-button]]. 
  
 ===== Resources ===== ===== Resources =====
projets/fuz/presence_button.1576098365.txt.gz · Last modified: 2019/12/11 22:06 by lomanic