{"action":"closed","issue":{"url":"https://api.github.com/repos/letscontrolit/ESPEasy/issues/1356","repository_url":"https://api.github.com/repos/letscontrolit/ESPEasy","labels_url":"https://api.github.com/repos/letscontrolit/ESPEasy/issues/1356/labels{/name}","comments_url":"https://api.github.com/repos/letscontrolit/ESPEasy/issues/1356/comments","events_url":"https://api.github.com/repos/letscontrolit/ESPEasy/issues/1356/events","html_url":"https://github.com/letscontrolit/ESPEasy/issues/1356","id":319688706,"number":1356,"title":"esp8266 slows significantly when MQTT server unavailable/disconnected","user":{"login":"ZericE","id":38921404,"avatar_url":"https://avatars0.githubusercontent.com/u/38921404?v=4","gravatar_id":"","url":"https://api.github.com/users/ZericE","html_url":"https://github.com/ZericE","followers_url":"https://api.github.com/users/ZericE/followers","following_url":"https://api.github.com/users/ZericE/following{/other_user}","gists_url":"https://api.github.com/users/ZericE/gists{/gist_id}","starred_url":"https://api.github.com/users/ZericE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZericE/subscriptions","organizations_url":"https://api.github.com/users/ZericE/orgs","repos_url":"https://api.github.com/users/ZericE/repos","events_url":"https://api.github.com/users/ZericE/events{/privacy}","received_events_url":"https://api.github.com/users/ZericE/received_events","type":"User","site_admin":false},"labels":[{"id":587074027,"url":"https://api.github.com/repos/letscontrolit/ESPEasy/labels/Category:%20Controller","name":"Category: Controller","color":"5319e7","default":false},{"id":850761330,"url":"https://api.github.com/repos/letscontrolit/ESPEasy/labels/Status:%20Fixed","name":"Status: Fixed","color":"0e8a16","default":false},{"id":257820025,"url":"https://api.github.com/repos/letscontrolit/ESPEasy/labels/Type:%20Enhancement","name":"Type: Enhancement","color":"84b6eb","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2018-05-02T19:50:11Z","updated_at":"2018-05-07T02:29:28Z","closed_at":"2018-05-07T02:29:28Z","author_association":"CONTRIBUTOR","body":"### Summarize of the problem/feature request\r\nWhen a working connection to an MQTT broker becomes unavailable OR a connection to a non-existent broker is attempted, the esp8266 slows down significantly from that point forward. If the MQTT server becomes available, the esp8266 goes back to normal. See below for more on the source of the problem and a possible code change.\r\n\r\n### Expected behavior\r\nThe sudden unavailability of a connection to MQTT broker should not significantly disrupt all other operations of the esp device for an ongoing basis.\r\n\r\n### Actual behavior\r\nGetting a response from the web interface or through local gpio inputs becomes slow and unreliable when an unavailable MQTT broker is defined. After a few minutes, the \"Load\" spikes to 100% and stays there.\r\n\r\n### Steps to reproduce\r\nCreate a MQTT controller in espeasy (I selected OpenHab controller),  point it to a non existing MQTT broker, enable it, and reboot. Usually it's possible to get the web interface to respond enough to disable the controller, although it may take more than one try.\r\n\r\n### System configuration\r\nHardware: sonoff (basic and TH1x models). This isn't a hardware dependant issue.\r\n\r\nESP Easy version:  V2.0 Mar 22 2018 build and Mega May 02 2018 build. This has been an issue for quite some time. \r\n\r\nESP Easy settings/screenshots: \r\n![2018-05-02_110042](https://user-images.githubusercontent.com/38921404/39540809-a57a17f2-4df8-11e8-9191-0b329f6dea41.jpg)\r\n![2018-05-02_122121](https://user-images.githubusercontent.com/38921404/39544737-dbf0e954-4e03-11e8-9496-d6a52b17fcfe.jpg)\r\n![2018-05-02_122431](https://user-images.githubusercontent.com/38921404/39544742-e0183276-4e03-11e8-83af-b23ce7571984.jpg)\r\n\r\n### Rules or log data\r\n![2018-05-02_110132](https://user-images.githubusercontent.com/38921404/39540793-987809c4-4df8-11e8-8328-3fa9bf6c0cc3.jpg)\r\n\r\n### Source of the problem\r\nWhen pubsubclient attempts to connect to an unavailable MQTT broker via MQTTclient.connect(...) in Controller.ino, it blocks other esp operations for >6 seconds in V2.0 and >5s for Mega. Additionally, when a controller is unavailable, espeasy aggressively tries to (re)connect.\r\n\r\nIn ESPEasy.ino, the delay between MQTT connection attempts is set by timermqtt_interval and maxes at 2000 milliseconds delay (2s). This means that most of the CPU time (>70%) is spend trying to (re)connect to the broker, leaving little time for other activities. This long delay when an MQTT broker connect attempt fails is a known issue and occurs below the pubsubclient library from my understanding after reading the issue list for pubsubclient.\r\n\r\nESP Easy can however, resort to a far less aggressive (re)connect policy, leaving more time for other activities. There is little reason I can think of to attempt a reconnect more than a 1-3 times per minute after a couple of quicker tries. I have recompiled V2.0 changing the max timermqtt_interval from 2000ms to 30000ms and the backoff increment interval (currently: timermqtt_interval += 250) to a higher value of 5000 (5s), and that helps improve the situation significantly.  I no longer see the Load maxed out when it's trying to reconnect to an unavailable MQTT broker and in general the device is more responsive.\r\n\r\n```\r\n\r\n```\r\n"}}
{"actor":{"display_login":"ZericE"}}