{"action":"created","issue":{"url":"https://api.github.com/repos/morrissinger/ESP8266-Websocket/issues/14","repository_url":"https://api.github.com/repos/morrissinger/ESP8266-Websocket","labels_url":"https://api.github.com/repos/morrissinger/ESP8266-Websocket/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/morrissinger/ESP8266-Websocket/issues/14/comments","events_url":"https://api.github.com/repos/morrissinger/ESP8266-Websocket/issues/14/events","html_url":"https://github.com/morrissinger/ESP8266-Websocket/issues/14","id":152025609,"number":14,"title":"Socket Timeout after some time","user":{"login":"niklasdoerfler","id":173291,"avatar_url":"https://avatars.githubusercontent.com/u/173291?v=3","gravatar_id":"","url":"https://api.github.com/users/niklasdoerfler","html_url":"https://github.com/niklasdoerfler","followers_url":"https://api.github.com/users/niklasdoerfler/followers","following_url":"https://api.github.com/users/niklasdoerfler/following{/other_user}","gists_url":"https://api.github.com/users/niklasdoerfler/gists{/gist_id}","starred_url":"https://api.github.com/users/niklasdoerfler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niklasdoerfler/subscriptions","organizations_url":"https://api.github.com/users/niklasdoerfler/orgs","repos_url":"https://api.github.com/users/niklasdoerfler/repos","events_url":"https://api.github.com/users/niklasdoerfler/events{/privacy}","received_events_url":"https://api.github.com/users/niklasdoerfler/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-04-30T11:24:27Z","updated_at":"2016-04-30T22:19:40Z","closed_at":null,"body":"Hey,\r\n\r\nI'm using this library to listen to a websocket in client mode. I'm trying to control a led stip with the esp8266 module. Everything works fine, but after some time the socket doesn't get the data from the server. Is there a way to reset the controller if socket connection is lost?\r\n\r\nThanks in advance :)\r\n\r\n\r\nMy code:\r\n```\r\n#include <ESP8266WiFi.h>\r\n#include <WebSocketClient.h>\r\n#include <DNSServer.h>            //Local DNS Server used for redirecting all requests to the configuration portal\r\n#include <ESP8266WebServer.h>     //Local WebServer used to serve the configuration portal\r\n#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager WiFi Configuration Magic\r\n\r\nchar path[] = \"/\";\r\nchar host[] = \"foo.bar\";\r\nint port = 9000;\r\n  \r\nWebSocketClient webSocketClient;\r\nWiFiClient client;\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  WiFiManager wifiManager;\r\n  //wifiManager.resetSettings();\r\n  \r\n  \r\n  //Initial LED settings\r\n  delay(10);\r\n  pinMode(12, OUTPUT); \r\n  pinMode(13, OUTPUT); \r\n  digitalWrite(12,HIGH);\r\n  digitalWrite(13,LOW);\r\n  delay(400);\r\n  digitalWrite(12,LOW);\r\n\r\n  //try to connect to Wifi Access Point or create a hotspot if no suitable network found\r\n  //first parameter is name of access point, second is the password\r\n  wifiManager.autoConnect(\"MyWiFi\", \"myPassphrase\");\r\n  \r\n  delay(1000);\r\n  \r\n\r\n  // Connect to the websocket server\r\n  if (client.connect(host, port)) {\r\n    Serial.println(\"Connected\");\r\n  } else {\r\n    Serial.println(\"Connection failed.\");\r\n    while(1) {\r\n      // Hang on failure\r\n    }\r\n  }\r\n\r\n  // Handshake with the server\r\n  webSocketClient.path = path;\r\n  webSocketClient.host = host;\r\n  if (webSocketClient.handshake(client)) {\r\n    Serial.println(\"Handshake successful\");\r\n    digitalWrite(12,HIGH);\r\n  } else {\r\n    Serial.println(\"Handshake failed.\");\r\n    while(1) {\r\n      // Hang on failure\r\n    }  \r\n  }\r\n}\r\n\r\n\r\nvoid loop() {\r\n  String data;\r\n\r\n  if (client.connected() && webSocketClient.handshake(client)) {\r\n    Serial.println(\"Try to get data...\");\r\n    webSocketClient.getData(data);\r\n    if (data.length() > 0) {\r\n      Serial.print(\"Received data: \");\r\n      Serial.println(data);\r\n\r\n      if(data==\"open\") //keyword to switch on the LED strip\r\n        digitalWrite(13,HIGH);\r\n      else //keyword to switch off the LED strip\r\n        digitalWrite(13,LOW);\r\n    }\r\n    \r\n  } else {\r\n    Serial.println(\"Client disconnected.\");\r\n    while (1) {\r\n      // Hang on disconnect.\r\n    }\r\n  }\r\n  \r\n  // wait to fully let the client disconnect\r\n  delay(2000);\r\n  \r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/morrissinger/ESP8266-Websocket/issues/comments/215999461","html_url":"https://github.com/morrissinger/ESP8266-Websocket/issues/14#issuecomment-215999461","issue_url":"https://api.github.com/repos/morrissinger/ESP8266-Websocket/issues/14","id":215999461,"user":{"login":"niklasdoerfler","id":173291,"avatar_url":"https://avatars.githubusercontent.com/u/173291?v=3","gravatar_id":"","url":"https://api.github.com/users/niklasdoerfler","html_url":"https://github.com/niklasdoerfler","followers_url":"https://api.github.com/users/niklasdoerfler/followers","following_url":"https://api.github.com/users/niklasdoerfler/following{/other_user}","gists_url":"https://api.github.com/users/niklasdoerfler/gists{/gist_id}","starred_url":"https://api.github.com/users/niklasdoerfler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niklasdoerfler/subscriptions","organizations_url":"https://api.github.com/users/niklasdoerfler/orgs","repos_url":"https://api.github.com/users/niklasdoerfler/repos","events_url":"https://api.github.com/users/niklasdoerfler/events{/privacy}","received_events_url":"https://api.github.com/users/niklasdoerfler/received_events","type":"User","site_admin":false},"created_at":"2016-04-30T22:19:40Z","updated_at":"2016-04-30T22:19:40Z","body":"Thank you for your answer!\r\nI replaced the last while loop with your code, but it doesn't really help me with my actual problem, not knowing when the Websockets disconnects. It only resets the ESP when the WiFi connection gets lost.\r\n\r\nDoes anybody know how to notice if the websocket connection is lost?\r\n\r\nThanks in advance!"}}