I decided to jump into using the Network interface API, using WiFi.
I have quickly learnt through my failures that the WiFi connectivity API is at odds with the rest of the connectivity API’s. For example, I cannot use async callbacks. Is this correct?
There also seem to be other quirks but I will leave it be for now.
The problem I am having is that I am having little success connecting my humble ESP8266-07 module to my router.
When using the standard WiFi example, as referenced below, I get the scan results without problem.
Early on, I had a spot of beginners luck and had 1 successful connect using the example provided in the WiFi documentation, where I received the IP address and the rest of the connection parameters etc: Wi-Fi - API references and tutorials | Mbed OS 6 Documentation
But now I am at a loss after the nth failed attempt.
So when I use the command:
int ret = wifi.connect(MBED_CONF_APP_WIFI_SSID,MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
It generally always returns 0 almost immediately (unless I have a wiring issue when it returns a -3012 or NSAPI_ERROR_DEVICE_ERROR) .
In my experience when connecting a wifi module to a router, when using blocking logic, you should not get an immediate response as a router typically takes a good few seconds to check all credentials and assign an IP address etc. Usually first connect is slower etc. I note that the default timeout in the esp8266 code is 15 seconds. So it expects a delay.
So how do I fault find this sort of thing?
For example, there does not seem to be an obvious way of confirming if the password is correct etc. I tried testing this with arbitrary passwords and it seems that all you get is NSAPI_ERROR_IN_PROGRESS or NSAPI_ERROR_ALREADY error types. Is this a safe test condition as not sure what these error codes really mean.
I then tried adding in wifi.attach(&status_callback);
to see what responses I get.
I only ever receive one callback event, which NSAPI_STATUS_DISCONNECTED. No other callback is triggered. Should you get more etc.
So I am wondering what is a proven method to fault find WiFi SDK issues or otherwise here.
In my experience when using AT commands, like with cellular devices, it often relates to how your code interprets the AT response and the time given to wait for a response. Is it likely to be the same here. I am not sure where I would start. I assume it is ESP8266.cpp.
Any feedback is gladly welcomed.
Thanks.