{"action":"created","issue":{"url":"https://api.github.com/repos/espruino/Espruino/issues/618","labels_url":"https://api.github.com/repos/espruino/Espruino/issues/618/labels{/name}","comments_url":"https://api.github.com/repos/espruino/Espruino/issues/618/comments","events_url":"https://api.github.com/repos/espruino/Espruino/issues/618/events","html_url":"https://github.com/espruino/Espruino/issues/618","id":109877509,"number":618,"title":"Handle WiFi connect while already connected ...","user":{"login":"nkolban","id":3421732,"avatar_url":"https://avatars.githubusercontent.com/u/3421732?v=3","gravatar_id":"","url":"https://api.github.com/users/nkolban","html_url":"https://github.com/nkolban","followers_url":"https://api.github.com/users/nkolban/followers","following_url":"https://api.github.com/users/nkolban/following{/other_user}","gists_url":"https://api.github.com/users/nkolban/gists{/gist_id}","starred_url":"https://api.github.com/users/nkolban/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nkolban/subscriptions","organizations_url":"https://api.github.com/users/nkolban/orgs","repos_url":"https://api.github.com/users/nkolban/repos","events_url":"https://api.github.com/users/nkolban/events{/privacy}","received_events_url":"https://api.github.com/users/nkolban/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-05T20:19:27Z","updated_at":"2015-10-05T22:08:53Z","closed_at":null,"body":"There appears to be an area of function that needs research and study.  In the ESP8266, we now have a function called `ESP8266WiFi.connect()` that connects the device to a WiFi AP.  This seems to work fine on a virgin ESP8266 boot but seems to fail for scripts that attempt to issue a connect the **next** time the script is run.   A suspicion is that the ESP8266 realizes that it is already connected and the underlying  ESP8266 `wifi_station_connect()` is treated as a no-op.  This also means that the callback functions that are meant to be invoked when the connection to the AP is established don't happen ...  and THAT prevents the callback function registered by the JS programmer when they use `ESP8266WiFi.connect()`  from being called.\r\n\r\nWe appear to have a couple of choices.   One would be to look and see if we are already connected to the target AP and if so, do nothing but drive the callback that says we are connected.   The other choice might be to perform all the disconnect logic and THEN perform the current connection logic.\r\n\r\nI don't know which of these is yet the desired semantics.   Discussion on this is open and comments here are welcome."},"comment":{"url":"https://api.github.com/repos/espruino/Espruino/issues/comments/145683853","html_url":"https://github.com/espruino/Espruino/issues/618#issuecomment-145683853","issue_url":"https://api.github.com/repos/espruino/Espruino/issues/618","id":145683853,"user":{"login":"igrr","id":4349050,"avatar_url":"https://avatars.githubusercontent.com/u/4349050?v=3","gravatar_id":"","url":"https://api.github.com/users/igrr","html_url":"https://github.com/igrr","followers_url":"https://api.github.com/users/igrr/followers","following_url":"https://api.github.com/users/igrr/following{/other_user}","gists_url":"https://api.github.com/users/igrr/gists{/gist_id}","starred_url":"https://api.github.com/users/igrr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/igrr/subscriptions","organizations_url":"https://api.github.com/users/igrr/orgs","repos_url":"https://api.github.com/users/igrr/repos","events_url":"https://api.github.com/users/igrr/events{/privacy}","received_events_url":"https://api.github.com/users/igrr/received_events","type":"User","site_admin":false},"created_at":"2015-10-05T22:08:52Z","updated_at":"2015-10-05T22:08:52Z","body":"When user calls `ESP8266WiFi.connect()`, you might not be connected to the AP yet (connection might be in progress). Still, you can get current config from SDK by calling `wifi_station_get_config`. If both SSID and PSK match to those provided by user, do nothing and wait for WiFi callback to fire (there is an issue with WiFi status callbacks in SDK 1.4 reported by @tve; you could poll WiFi status until the issue is resolved).\r\nIf SSID or PSK do not match, call `wifi_station_set_config` as usual."}}