-
Notifications
You must be signed in to change notification settings - Fork 220
OS Error 118 on sock.connect(addr) #212
Comments
I've just found that wlan.isconnected() is always True so it's not usocket issue. I was using my ESP8266 wifi script which seems to not working on ESP32. |
Can you post the full code? Or at least enough to reproduce the issue? |
I suspect this is related to #166 (comment) with the inconsistent errno definitions ... |
import network I'm not connected yet. In ESP8266 in this stage it's showing False so i was entering following if: And making the connection. This OS Error 118 is effect of above - cannot connect to socket while not connected to network. Anyway I've moved wifi_sta.ifconfig() into "if" and it works. |
and following code will throw OS Error 118: import usocket as socket |
@PikWay your report here is not 100% clear on what your issue is. The above code with the "OSError: 118" is simply due to the network/wifi not being connected.
Yes, you must be connected to wifi for the socket to connect to a remote machine. What else do you expect it to do? |
@dpgeorge Ok. Will try to make it clearer. Agree that if trying to bind to socket on disconnected network should throw error. Problem is with determining is network connected when using static IP. So if network.WLAN.ifconfig was invoked with addressing tuple - network.WLAN.isconnected will return True before connecting to WiFi. |
The problem is, that in contrast to the ESP8266 port there is no dedicated API telling whether the device is connected. So other indications must be used, like esp_wifi_sta_get_ap_info(). That seems to work, but it is unclear to me whether this can fail even if a device is connected. Anyway, the function could look like:
|
The option above is only a little bit better. It will not flag "connected" after setting the IP adress. But if after connecting the connection is lost, it will still indicate an exiting connection. |
Why not to use this variable: static bool wifi_sta_connected = false;? Also I can see some events in logs, set to different values during wifi connection lifecycle. |
That's more simple but fails too, because it will tell you immediately that a connection was made, before it is established, even if it gets never done. One advantage: after a wlan.disconnect() it flags disconnecet. |
OK. Found a solution which seems solid. Edit: made a PR |
Robert solution works. Issue to close. |
You can close it yourself. Just push the 'close' button. |
I'm trying to do simple socket conn and on sock.connect(addr) I'm getting OS Error 118. I really don't know what this means because it's absent in uerrno.
ESP is running on firmware: esp32-20171029-v1.9.2-283-gdba3796e
The text was updated successfully, but these errors were encountered: