mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	Fix nginx closing WebSocket connection after 60 seconds (#370)
* Test
* Add keepalive
* Revert "Add keepalive"
This reverts commit 8b92198122.
* Update dashboard.py
* Revert
* Lint
			
			
This commit is contained in:
		| @@ -429,6 +429,8 @@ def run_logs(config, address): | |||||||
|     stopping = False |     stopping = False | ||||||
|     retry_timer = [] |     retry_timer = [] | ||||||
|  |  | ||||||
|  |     has_connects = [] | ||||||
|  |  | ||||||
|     def try_connect(tries=0, is_disconnect=True): |     def try_connect(tries=0, is_disconnect=True): | ||||||
|         if stopping: |         if stopping: | ||||||
|             return |             return | ||||||
| @@ -451,8 +453,13 @@ def run_logs(config, address): | |||||||
|             return |             return | ||||||
|  |  | ||||||
|         wait_time = min(2**tries, 300) |         wait_time = min(2**tries, 300) | ||||||
|         _LOGGER.warning(u"Couldn't connect to API (%s). Trying to reconnect in %s seconds", |         if not has_connects: | ||||||
|                         error, wait_time) |             _LOGGER.warning(u"Initial connection failed. The ESP might not be connected" | ||||||
|  |                             u"to WiFi yet (%s). Re-Trying in %s seconds", | ||||||
|  |                             error, wait_time) | ||||||
|  |         else: | ||||||
|  |             _LOGGER.warning(u"Couldn't connect to API (%s). Trying to reconnect in %s seconds", | ||||||
|  |                             error, wait_time) | ||||||
|         timer = threading.Timer(wait_time, functools.partial(try_connect, tries + 1, is_disconnect)) |         timer = threading.Timer(wait_time, functools.partial(try_connect, tries + 1, is_disconnect)) | ||||||
|         timer.start() |         timer.start() | ||||||
|         retry_timer.append(timer) |         retry_timer.append(timer) | ||||||
| @@ -465,8 +472,6 @@ def run_logs(config, address): | |||||||
|                                   'TCP buffer - This is only cosmetic)') |                                   'TCP buffer - This is only cosmetic)') | ||||||
|         safe_print(time_ + text) |         safe_print(time_ + text) | ||||||
|  |  | ||||||
|     has_connects = [] |  | ||||||
|  |  | ||||||
|     def on_login(): |     def on_login(): | ||||||
|         try: |         try: | ||||||
|             cli.subscribe_logs(on_log, dump_config=not has_connects) |             cli.subscribe_logs(on_log, dump_config=not has_connects) | ||||||
|   | |||||||
| @@ -511,6 +511,12 @@ def make_app(debug=False): | |||||||
|                 self.set_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0') |                 self.set_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0') | ||||||
|  |  | ||||||
|     static_path = os.path.join(os.path.dirname(__file__), 'static') |     static_path = os.path.join(os.path.dirname(__file__), 'static') | ||||||
|  |     settings = { | ||||||
|  |         'debug': debug, | ||||||
|  |         'cookie_secret': COOKIE_SECRET, | ||||||
|  |         'log_function': log_function, | ||||||
|  |         'websocket_ping_interval': 30.0, | ||||||
|  |     } | ||||||
|     app = tornado.web.Application([ |     app = tornado.web.Application([ | ||||||
|         (r"/", MainRequestHandler), |         (r"/", MainRequestHandler), | ||||||
|         (r"/login", LoginHandler), |         (r"/login", LoginHandler), | ||||||
| @@ -527,7 +533,7 @@ def make_app(debug=False): | |||||||
|         (r"/ping", PingRequestHandler), |         (r"/ping", PingRequestHandler), | ||||||
|         (r"/wizard.html", WizardRequestHandler), |         (r"/wizard.html", WizardRequestHandler), | ||||||
|         (r'/static/(.*)', StaticFileHandler, {'path': static_path}), |         (r'/static/(.*)', StaticFileHandler, {'path': static_path}), | ||||||
|     ], debug=debug, cookie_secret=COOKIE_SECRET, log_function=log_function) |     ], **settings) | ||||||
|  |  | ||||||
|     if debug: |     if debug: | ||||||
|         _STATIC_FILE_HASHES.clear() |         _STATIC_FILE_HASHES.clear() | ||||||
|   | |||||||
| @@ -409,7 +409,7 @@ | |||||||
|     </div> |     </div> | ||||||
|   </div> |   </div> | ||||||
|   <div class="modal-footer"> |   <div class="modal-footer"> | ||||||
|     <a class="modal-close waves-effect waves-green btn-flat stop-logs">Stop</a> |     <a class="modal-close waves-effect waves-green btn-flat stop-logs">Close</a> | ||||||
|   </div> |   </div> | ||||||
| </div> | </div> | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user