Could someone point me at the source for this so I can see whether there are other control parameters available for WiFi.connect();
that aren’t documented?
There are no other options.
@rickkas7 - is there any way to know if the stored credentials are wrong once WiFi.connect();
has been called? I can see from the log handler with trace on that [hal] is reporting back connection failure with error 1064 ( which I think is WICED credentials error). Is there a way I can get this error code back to the application? I am trying to avoid the situation that during the WAP setup the wrong password is entered and then the device keeps trying and trying to connect and blocks out application thread activity. So far all I can do is check for WiFi.ready()
and if not within a timeout period then call WiFi.off()
. The same happens if a WAP entered that is valid and then the device is moved out of range or the WAP is turned off - the device just tenaciously tries to connect. The problem with using WiFi.off()
is that what if the WAP is back in range or turned back on - then how will the device know this? It could run a timed function to try WiFi.connect()
but this would be blocking the application when it might need to be running?
Surely the network_connect function could check for WICED error codes (like 1064) and stop trying?
I’m not positive that error is propagated up, but if you are using 0.8.0 you can get some connection failure errors. An example of this is in DeviceKeyHelper where the specific cloud connection error is determined.
You’d probably check DIAG_NAME_NETWORK_CONNECTION_ERROR_CODE instead to get the WiFi error. I’m not positive this will work, but it might.
@rickkas7 Thanks, I will try this.
I came upon this on the Adafruit WICED Feather WiFi page;
There are hundreds of other possible error codes, and they can't all be documented here, but using the .errno() and .errstr() functions in AdafruitFeather you can get either the 16-bit error code or a string that provides a basic description for that error code.
The following code shows how you might use a combination of .errno() and .errstr() to handle common error codes:
Is this something that might be implemented on the Photon?
I don’t think the WICED errno is exposed through the hal. However, the return values from some functions is the WICED errno value.
Hey @rickkas7 - I have tried to get this error code but I just seem to be receiving 0 see log below.
0000010140 [hal.wlan] INFO: Using external antenna
0000010164 [app] TRACE: 1 stored credentials giving 5000 mS timeout
0000010164 [app] TRACE: DIAG_ID_NETWORK_CONNECTION_ERROR_CODE = 0
0000010164 [app] TRACE: network.connection.error 0
0000010166 [hal.wlan] TRACE: connect cancel
0000010196 [hal.wlan] INFO: Bringing WiFi interface up with DHCP
0000010196 [hal.wlan] TRACE: connect cancel
The code I adapted from your example is as follows:
// based upon Rick Kas code
uint32_t getNetworkConnectionError()
{
int32_t value;
if (getSystemDiagValue(DIAG_ID_NETWORK_CONNECTION_ERROR_CODE, value))
{
Log.trace("DIAG_ID_NETWORK_CONNECTION_ERROR_CODE = %d", value);
}
else
{
Log.trace("No NETWORK_CONNECTION_ERROR_CODE found");
value = 0;
}
return value;
}
// based upon Rick Kas code
bool getSystemDiagValue(uint16_t id, int32_t &value)
{
union Data {
struct __attribute__((packed)) {
uint16_t idSize;
uint16_t valueSize;
uint16_t id;
int32_t value;
size_t offset;
} d;
uint8_t b[10];
};
Data data;
data.d.offset = data.d.value = 0;
struct {
static bool appender(void* appender, const uint8_t* data, size_t size) {
Data *d = (Data *)appender;
if ((d->d.offset + size) <= sizeof(Data::b)) {
memcpy(&d->b[d->d.offset], data, size);
d->d.offset += size;
}
return true;
}
} Callback;
system_format_diag_data(&id, 1, 1, Callback.appender, &data, nullptr);
//Log.trace("idSize=%u valueSize=%u id=%u value=%ld", data.d.idSize, data.d.valueSize, data.d.id, data.d.value);
value = data.d.value;
return (data.d.offset == sizeof(Data::b));
}
Any ideas why it is returning error code of 0?