Search code examples
freertosmicrochippic32

FreeRTOS Wifi down event does not call vApplicationIPNetworkEventHook


I've been trying to find a solution to get amazon-freertos to detect WIFI network down so I can reconnect. I have to say I am still not fully in understanding of how it all should work.

From reading up it looks like the intended way is to wait for callback to vApplicationIPNetworkEventHook where the programmer should implement necessary reconnects. However the problem is that this callback function does not get called for network down events, it only get called for network up events.

Reading FreeRTOS guide I see that for vApplicationIPNetworkEventHook to get a callback for network down event the underlying driver must first tell the TCPIP stack of this event, and it goes on to say not all drivers implement this, so I think I have located the problem now.

My question is how should the driver inform the TCPIP stack? The driver logs the network down event (it doesn't do much more than that) so I can add some code there to alert the TCPIP stack, but how should that be done? I cannot find any instructions for how to make this change, any help or suggestion is much appreciated.

amazon-freertos: https://github.com/MicrochipTech/amazon-freertos MCU Test Board: Microchip curiosity_pic32mzw1

To add I think this should be the place (iot_wifi.c) to implement it:

WIFIReturnCode_t WIFI_RegisterNetworkStateChangeEventCallback( IotNetworkStateChangeEventCallback_t xCallback  )
{
    /** Needs to implement dispatching network state change events **/
    return eWiFiNotSupported;
}

The question is just how.

Thanks, Marcus


Solution

  • You can add a call to vApplicationIPNetworkEventHook() using eNetworkDown as the parameter.