2 years, 1 month ago.

How to properly register a WiFi Status Callback?? Odin-W2-EVK / EmBitz / mbed-os-example-wifi

Hello friends,

as mentioned above i am working with the u-blox Odin-W2-EVK and the EmBitz IDE I have been modifying the existing mbed-os-example-wifi to evaluate the module and I've done good so far! since yesterday i've been trying to register a callback for the wifi status and I encountered some issues which i can't figure out.

Whenever i register the callback function and try to run my code, I can't connect to any wireless network anymore. (i have several to choose from and i'm positive its not an issue from the networks!) I reverted my code back to the original mbed-os-example-wifi to rule out any errors in other parts of my code and tried the callback again but the result is the same. if i comment out the call to register the callback, the wifi connection works instantly. if i comment it back in, I am getting callbacks to my function as expected, but when the wifi connection is supposed to happen i get these 3 callbacks in quick succession and the connection fails:

cbWLAN_STATUS_CONNECTING

cbWLAN_STATUS_CONNECTED

cbWLAN_STATUS_DISCONNECTED

in my original program i could catch and print the error code and it always was this one:

NSAPI_ERROR_DEVICE_ERROR        = -3012,     /*!< failure interfacing with the network processor */

These are the declarations:

I found this function in the cb_wlan.h...

/**
 * Register a status indication callback.
 * @note There may be multiple clients connected.
 *
 * @param statusIndication Callback function.
 * @param callbackContext Context pointer, will be sent back in callback.
 * @return @ref cbSTATUS_OK if call successful, otherwise cbSTATUS_ERROR.
 */
cbRTSL_Status cbWLAN_registerStatusCallback(cbWLAN_statusIndication statusIndication, void *callbackContext);

...and the definition for the @param statusIndication Callback function

typedef void (*cbWLAN_statusIndication)(void *callbackContext, cbWLAN_StatusIndicationInfo status, void *data);

These are the modifications i made to the main function to register for the callback:

cbWLAN_registerStatusCallback(WifiCallback, NULL);

i set the context pointer to NULL because I couldn't understand how to use it. I'm guessing either that is the problem or I'm supposed to do something with the two void pointers in the callback function signature!

i wrote this Callback function matching the expected pattern and I'm just printing out the callbacks i'm getting for now

void WifiCallback(void* ptr1, cbWLAN_StatusIndicationInfo status, void* ptr2)
{
    switch(status)
    {
        case cbWLAN_STATUS_STOPPED:
            printf("\r\ncbWLAN_STATUS_STOPPED");
            break;
        case cbWLAN_STATUS_STARTED:
            printf("\r\ncbWLAN_STATUS_STARTED");
            break;
        case cbWLAN_STATUS_ERROR:
            printf("\r\ncbWLAN_STATUS_ERROR");
            break;
        case cbWLAN_STATUS_DISCONNECTED:
            printf("\r\ncbWLAN_STATUS_DISCONNECTED");
            break;
        case cbWLAN_STATUS_CONNECTING:
            printf("\r\ncbWLAN_STATUS_CONNECTING");
            break;
        case cbWLAN_STATUS_CONNECTED:
            printf("\r\ncbWLAN_STATUS_CONNECTED");
            break;
        case cbWLAN_STATUS_CONNECTION_FAILURE:
            printf("\r\ncbWLAN_STATUS_CONNECTION_FAILURE");
            break;
        case cbWLAN_STATUS_AP_UP:
            printf("\r\ncbWLAN_STATUS_AP_UP");
            break;
        case cbWLAN_STATUS_AP_DOWN:
            printf("\r\ncbWLAN_STATUS_AP_DOWN");
            break;
        case cbWLAN_STATUS_AP_STA_ADDED:
            printf("\r\ncbWLAN_STATUS_AP_STA_ADDED");
            break;
        case cbWLAN_STATUS_AP_STA_REMOVED:
            printf("\r\ncbWLAN_STATUS_AP_STA_REMOVED");
            break;
        default:
            printf("\r\nDEFAULT");
    }
}
Comment on this question

1 Answer

2 years ago.

You're not using mbed OS APIs, you're using Ublox Odin APIs. Unfortunately mbed OS doesn't have corresponding functionality available. You can ask this question directly to Ublox or via mbed OS github repository we can make sure it gets to Ublox engineers.


You need to log in to post a question