{"action":"created","issue":{"url":"https://api.github.com/repos/esp8266/Arduino/issues/513","labels_url":"https://api.github.com/repos/esp8266/Arduino/issues/513/labels{/name}","comments_url":"https://api.github.com/repos/esp8266/Arduino/issues/513/comments","events_url":"https://api.github.com/repos/esp8266/Arduino/issues/513/events","html_url":"https://github.com/esp8266/Arduino/issues/513","id":93354644,"number":513,"title":"ADC forcing WIFI to disconnect and lose SSID","user":{"login":"iisfaq","id":5828178,"avatar_url":"https://avatars.githubusercontent.com/u/5828178?v=3","gravatar_id":"","url":"https://api.github.com/users/iisfaq","html_url":"https://github.com/iisfaq","followers_url":"https://api.github.com/users/iisfaq/followers","following_url":"https://api.github.com/users/iisfaq/following{/other_user}","gists_url":"https://api.github.com/users/iisfaq/gists{/gist_id}","starred_url":"https://api.github.com/users/iisfaq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iisfaq/subscriptions","organizations_url":"https://api.github.com/users/iisfaq/orgs","repos_url":"https://api.github.com/users/iisfaq/repos","events_url":"https://api.github.com/users/iisfaq/events{/privacy}","received_events_url":"https://api.github.com/users/iisfaq/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-07-06T19:12:09Z","updated_at":"2015-07-08T08:29:35Z","closed_at":null,"body":"I have been following the ADC thread at https://github.com/esp8266/Arduino/issues/338\r\n\r\nI implemented the change to the analaogRead() function\r\n\r\n    extern int __analogRead(uint8_t pin) {\r\n        if (pin == 17){\r\n           return 0xffff & system_adc_read();\r\n        }\r\n       return digitalRead(pin) * 1023;\r\n    }\r\n\r\nThis gave me much more stable ADC readings when ADC is pinned to GND or 3.3V\r\n\r\nBut I have now found another issue.\r\n\r\nMy code is using the ADC along with an ACS712 Current Sensor to measure current in a 240V supply.\r\n\r\nThe code is pretty simple\r\n\r\nBasically Connect to WIFI, loop around calling analogRead and once per minute upload this data to a web site, and just display it every second to the serial port.\r\n\r\nWhen I am calling analogRead I get this type of output\r\n\r\nConnecting to CROWE\r\n......\r\nWiFi connected\r\nIP address: \r\n192.168.2.128\r\nInterval=1, WiFi.status=WL_CONNECTED=3\r\nInterval=2, WiFi.status=WL_CONNECTED=3\r\nInterval=3, WiFi.status=WL_CONNECTED=3\r\nInterval=4, WiFi.status=WL_CONNECTED=3\r\nInterval=5, WiFi.status=WL_DISCONNECTED=6\r\nInterval=6, WiFi.status=WL_DISCONNECTED=6\r\nInterval=7, WiFi.status=WL_DISCONNECTED=6\r\nInterval=8, WiFi.status=WL_DISCONNECTED=6\r\nInterval=9, WiFi.status=WL_DISCONNECTED=6\r\nInterval=10, WiFi.status=WL_DISCONNECTED=6\r\nInterval=11, WiFi.status=WL_DISCONNECTED=6\r\nInterval=12, WiFi.status=WL_NO_SSID_AVAIL=1\r\nInterval=13, WiFi.status=WL_NO_SSID_AVAIL=1\r\nInterval=14, WiFi.status=WL_NO_SSID_AVAIL=1\r\nInterval=15, WiFi.status=WL_NO_SSID_AVAIL=1\r\nInterval=16, WiFi.status=WL_NO_SSID_AVAIL=1\r\nInterval=17, WiFi.status=WL_NO_SSID_AVAIL=1\r\nInterval=18, WiFi.status=WL_NO_SSID_AVAIL=1\r\n\r\nif I simply do not call analogRead(A0) in the loop it stays connected forever.\r\n\r\nHere is the code I am using\r\n\r\n```\r\n#include <ESP8266WiFi.h>\r\n\r\nconst char* ssid     = \"CROWE\";\r\nconst char* password = \"abcd\";\r\n\r\nconst char* host = \"192.168.2.122\";\r\n\r\nString Statuses[] =  { \"WL_IDLE_STATUS=0\", \"WL_NO_SSID_AVAIL=1\", \"WL_SCAN_COMPLETED=2\", \"WL_CONNECTED=3\", \"WL_CONNECT_FAILED=4\", \"WL_CONNECTION_LOST=5\", \"WL_DISCONNECTED=6\"};\r\nunsigned long lastMillis = 0;\r\nunsigned long lastMillis2 = 0;\r\nint IntervalInSeconds = 1;\r\nint Errors = 0;\r\nint min = 1024;\r\nint max = -1024;\r\nint samples = 0;\r\nvoid setup() {\r\n\r\n  Serial.begin(115200);\r\n  Serial.println(\"ESP8266 Power Monitor\");\r\n\r\n  WiFi.mode(WIFI_STA);\r\n  WiFi.disconnect();\r\n\r\n  Connect();\r\n}\r\n\r\nvoid Connect()\r\n{\r\n  Serial.print(\"Connecting to \");\r\n  Serial.println(ssid);\r\n\r\n  WiFi.begin(ssid, password);\r\n\r\n  int Attempt = 0;\r\n  while (WiFi.status() != WL_CONNECTED) {\r\n    delay(500);\r\n    Attempt++;\r\n    Serial.print(\".\");\r\n    if (Attempt == 50)\r\n    {\r\n      Serial.println();\r\n      Serial.println(\"Could not connect to WIFI\");\r\n      return;\r\n    }\r\n  }\r\n\r\n  Serial.println(\"\");\r\n  Serial.println(\"WiFi connected\");\r\n  Serial.println(\"IP address: \");\r\n  Serial.println(WiFi.localIP());\r\n}\r\n\r\nvoid loop()\r\n{\r\n  yield() ; // Allow WIFI to do stuff\r\n\r\n  unsigned long CurrentMillis = millis();\r\n  if (CurrentMillis - lastMillis2 > 3)\r\n  {\r\n    lastMillis2 = CurrentMillis;\r\n\r\n    double sensorValue = 0;\r\n    for (int reading = 0; reading < 5; reading++)\r\n    {\r\n      sensorValue += analogRead(A0);\r\n    }\r\n    sensorValue /= 5;\r\n    if ((int)sensorValue < min)\r\n      min = (int)sensorValue;\r\n    if ((int)sensorValue > max)\r\n      max = (int)sensorValue;\r\n    samples++;\r\n  }\r\n\r\n  if (CurrentMillis - lastMillis > 900)\r\n  {\r\n    lastMillis = CurrentMillis;\r\n\r\n    Serial.print(\"Interval=\");\r\n    Serial.print(IntervalInSeconds);\r\n    Serial.print(\", WiFi.status=\");\r\n    Serial.print(Statuses[WiFi.status()]);\r\n\r\n    if (IntervalInSeconds >= 60)\r\n    {\r\n      IntervalInSeconds = 1;\r\n\r\n      Serial.print(\"connecting to \");\r\n      Serial.println(host);\r\n\r\n      if (WiFi.status() != WL_CONNECTED)\r\n        Connect();\r\n\r\n      if (WiFi.status() == WL_CONNECTED)\r\n      {\r\n        // Use WiFiClient class to create TCP connections\r\n        WiFiClient client;\r\n        const int httpPort = 8080;\r\n        if (!client.connect(host, httpPort)) {\r\n          Serial.println(\"connection failed\");\r\n          return;\r\n        }\r\n\r\n        // We now create a URI for the request\r\n        String url = \"/Power/?Watts=\";\r\n        url += \"SOMENUMBER\";\r\n        url += \"&DeviceID=HomeTheatre\";\r\n\r\n        Serial.print(\"Requesting URL: \");\r\n        Serial.println(url);\r\n\r\n        // This will send the request to the server\r\n        client.print(String(\"GET \") + url + \" HTTP/1.1\\r\\n\" +\r\n                     \"Host: \" + host + \"\\r\\n\" +\r\n                     \"Connection: close\\r\\n\\r\\n\");\r\n        delay(50);\r\n\r\n        // Read all the lines of the reply from server and print them to Serial\r\n        while (client.available()) {\r\n          String line = client.readStringUntil('\\r');\r\n          Serial.print(line);\r\n        }\r\n        Serial.println();\r\n      }\r\n      else\r\n      {\r\n        Serial.print(\"Error Not Connected To WIFI, Error Count: \");\r\n        Serial.println(++Errors);\r\n      }\r\n    }\r\n    else\r\n      Serial.println();\r\n\r\n    IntervalInSeconds = IntervalInSeconds + 1;\r\n    min = 1024;\r\n    max = -1024;\r\n    samples = 0;\r\n  }\r\n}\r\n```\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/esp8266/Arduino/issues/comments/119492261","html_url":"https://github.com/esp8266/Arduino/issues/513#issuecomment-119492261","issue_url":"https://api.github.com/repos/esp8266/Arduino/issues/513","id":119492261,"user":{"login":"iisfaq","id":5828178,"avatar_url":"https://avatars.githubusercontent.com/u/5828178?v=3","gravatar_id":"","url":"https://api.github.com/users/iisfaq","html_url":"https://github.com/iisfaq","followers_url":"https://api.github.com/users/iisfaq/followers","following_url":"https://api.github.com/users/iisfaq/following{/other_user}","gists_url":"https://api.github.com/users/iisfaq/gists{/gist_id}","starred_url":"https://api.github.com/users/iisfaq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iisfaq/subscriptions","organizations_url":"https://api.github.com/users/iisfaq/orgs","repos_url":"https://api.github.com/users/iisfaq/repos","events_url":"https://api.github.com/users/iisfaq/events{/privacy}","received_events_url":"https://api.github.com/users/iisfaq/received_events","type":"User","site_admin":false},"created_at":"2015-07-08T08:29:35Z","updated_at":"2015-07-08T08:29:35Z","body":"No worries, I only know English..... You are far better than me!!! \r\n\r\nI am using this for the board\r\n\r\nhttp://arduino.esp8266.com/package_esp8266com_index.json\r\n\r\nso I take it there is a different url that I should use which is newer.\r\n\r\nAny chance you know the URL already?\r\n\r\n"}}