{"action":"opened","issue":{"url":"https://api.github.com/repos/esp8266/Arduino/issues/1594","repository_url":"https://api.github.com/repos/esp8266/Arduino","labels_url":"https://api.github.com/repos/esp8266/Arduino/issues/1594/labels{/name}","comments_url":"https://api.github.com/repos/esp8266/Arduino/issues/1594/comments","events_url":"https://api.github.com/repos/esp8266/Arduino/issues/1594/events","html_url":"https://github.com/esp8266/Arduino/issues/1594","id":131893618,"number":1594,"title":"Random crash ESP286 WEMOS D1    DHT 22 server  ","user":{"login":"hymby","id":5839651,"avatar_url":"https://avatars.githubusercontent.com/u/5839651?v=3","gravatar_id":"","url":"https://api.github.com/users/hymby","html_url":"https://github.com/hymby","followers_url":"https://api.github.com/users/hymby/followers","following_url":"https://api.github.com/users/hymby/following{/other_user}","gists_url":"https://api.github.com/users/hymby/gists{/gist_id}","starred_url":"https://api.github.com/users/hymby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hymby/subscriptions","organizations_url":"https://api.github.com/users/hymby/orgs","repos_url":"https://api.github.com/users/hymby/repos","events_url":"https://api.github.com/users/hymby/events{/privacy}","received_events_url":"https://api.github.com/users/hymby/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-06T20:04:35Z","updated_at":"2016-02-06T20:04:35Z","closed_at":null,"body":"Random crash ESP286 WEMOS D1     \r\n\r\n\r\na couple of hours Tested result: crash Wemos D1\r\nwhat causes this?\r\n\r\n\r\n///////////////////////////////////////////////////////////////////////////\r\nArduino side\r\n\r\n#include <Ethernet.h>\r\n#include <SPI.h>\r\nbyte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xE1};///////////!!\r\nIPAddress ip(192, 168, 1, 175);\r\nIPAddress gateway(192, 168, 1, 254);\r\nIPAddress subnet(255, 255, 255, 0);\r\nEthernetClient client;\r\n\r\n\r\nIPAddress server(192, 168, 1, 11); ////////////////// WEMOS D1 Side\r\n\r\n\r\nlong mintavetelIdeje = 0;\r\nconst long mintavetelSzunet = 5000;\r\n\r\nvoid setup() {\r\n  Serial.begin(9600);\r\n  Serial.println(\"start\");\r\n  Ethernet.begin(mac, ip);\r\n  delay(1000);\r\n}\r\n\r\nString request(char what) {\r\n  String value = \"\";\r\n  if (client.connect(server, 85)) {\r\n    client.println(what);\r\n    delay(500);\r\n    while (client.available()) {\r\n      char c = client.read();\r\n      value.concat(c);\r\n    delay(200);\r\n  }\r\n    client.stop();\r\n  }\r\n  return value;\r\n}\r\n\r\nvoid loop() {\r\n  if (millis() - mintavetelIdeje > mintavetelSzunet) {\r\n    mintavetelIdeje = millis();\r\n    String temp = request('h');\r\n    String hum = request('l');\r\n    String pinState = request('p');\r\n    Serial.println(temp + \"\\n\" + hum + \"\\n\" + pinState + \"\\n\");\r\n   \r\n }\r\n}\r\n\r\n\r\n//////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\nWEMOS D1 R2 side\r\n\r\n#include <ESP8266WiFi.h>\r\n\r\nWiFiServer server(85);////////////////////////////Arduino  Side!!\r\n\r\n#include \"DHT.h\"   // dht  1.1.1   !!!!!\r\n#define DHTPIN D2\r\n#define DHTTYPE DHT22\r\nDHT dht(DHTPIN, DHTTYPE);\r\n\r\nconst char* ssid = \".......\";\r\nconst char* password = \"........\";\r\n\r\n\r\nString temp;\r\nfloat humidity_h;\r\nfloat temp_c;\r\nString value ;\r\nunsigned long dht_read_time = 0;\r\nunsigned long dht_read_time_when = 5000;\r\nint ledState = LOW;\r\nunsigned long previousMillis = 0;\r\nunsigned long interval = 100;\r\nconst int led = D6;\r\nlong kul;\r\nString data;\r\nString pinState(int pin) {\r\n  pinMode(pin, INPUT);\r\n  pinMode(pin, HIGH);\r\n  switch (digitalRead(pin)) {\r\n    case 0: return \"LOW\";\r\n    case 1: return \"HIGH\";\r\n  }\r\n}\r\n\r\n\r\nvoid Strobe() {\r\n  unsigned long currentMillis = millis();\r\n  if (currentMillis - previousMillis >= interval) {\r\n    previousMillis = currentMillis;\r\n    if (ledState == LOW)\r\n      ledState = HIGH;\r\n    else\r\n      ledState = LOW;\r\n    digitalWrite(led, ledState);\r\n  }\r\n}\r\n\r\n\r\nvoid setup(void) {\r\n  Serial.begin(115200);\r\n  WiFi.begin(ssid, password);\r\n  dht.begin();\r\n  Serial.println(\"\");\r\n  pinMode ( led, OUTPUT );\r\n  digitalWrite ( led, 0 );\r\n \r\n  while (WiFi.status() != WL_CONNECTED) {\r\n    delay(500);\r\n    Serial.print(\".\");\r\n  }\r\n  Serial.println(\"\");\r\n  Serial.print(\"Connected to \");\r\n  Serial.println(ssid);\r\n  Serial.print(\"IP address: \");\r\n  Serial.println(WiFi.localIP());\r\n  server.begin();\r\n}\r\n\r\n\r\nvoid dht_read() {\r\n  if (millis() - dht_read_time > dht_read_time_when) {\r\n    dht_read_time = millis();\r\n    temp_c = dht.readTemperature();\r\n    humidity_h = dht.readHumidity();\r\n  }\r\n}\r\n\r\nvoid accept_request() {\r\n  WiFiClient client = server.available();\r\n  if (!client) {\r\n    return;\r\n  }\r\n  Serial.println(\"new client\");\r\n  while (!client.available()) {\r\n    delay(1);\r\n  }\r\n  char c = client.read();\r\n  switch (c) {\r\n    case 'h':\r\n      value = String(temp_c, 1);\r\n      delay(100);\r\n      break;\r\n    case 'l':\r\n      value = String(humidity_h, 1);\r\n      delay(100);\r\n      break;\r\n    case 'p':\r\n      value = pinState(D7);\r\n      delay(100);\r\n      break;\r\n    default:\r\n      value = \"\";\r\n      delay(100);\r\n      break;\r\n  }\r\n  if (!value.equals(\"\")) {\r\n    client.print(value);\r\n    delay(1);\r\n    Serial.print(c);\r\n    Serial.println(\": \" + value);\r\n  }\r\n  delay(1);\r\n  Serial.println(\"Client disonnected\");\r\n}\r\n\r\n\r\nvoid loop(void) {\r\n  dht_read();\r\n  accept_request();\r\n  Strobe();\r\n \r\n\r\n  if (millis() - kul > 1000) {\r\n    kul = millis();\r\n    Serial.print(\"Free heap:\");\r\n    Serial.println(ESP.getFreeHeap(), DEC);\r\n  }\r\n}"}}