Network manager recommendation

FreeOurToes wrote on November 26, 2019:

Hi,

Previously I had an application where in main.c I connect to wifi and then start my application. But I noticed that in new Demos are using aws_iot_demo_network.c network manager that allows to configure callbacks on network changes. The implementation of callbacks seems quite complete to me but it’s tailored to be used within Demos.

Could I get a recommendation on how I could implement network manager into my applications? And in general is it worth doing it?

Thanks

ravishankar-AWS wrote on November 26, 2019:

Hi,

Network manager is useful, when your board supports multiple network connections and the application needs to switch between connections.
A common example for a board which supports BLE and WiFi is WiFi provisioning over BLE. Application needs to first listen to a BLE connection, provision WiFi credentials (SSID and password) over BLE, and then connect to provisioned WiFi network and send data to cloud.

This can be done using network manager in following steps:

  1. Subscribe to WIFI and BLE network state change:
    AwsIotNetworkManager_SubscribeForStateChange( NET_WIFI | NET_BLE, networkCallback … )

  2. Enter provisioning mode by enabling both WiFi and BLE networks:
    AwsIotNetworkManager_EnableNetwork( NET_WIFI | NET_BLE )

  3. On a BLE connection, provision the WiFi credentials (SSID and password), connect to the WiFi network. (This is already handled if you use the network manager and WiFi provisioning library for BLE).

  4. On a new WiFi connection, exit provisioning mode by disabling BLE network:
    AwsIotNetworkManager_DisableNetwork(NET_BLE)

  5. Start sending data to cloud over the WiFi connection.

Currently network manager is part of the demo as its used only by the demo applications of Amazon FreeRTOS. The functionalities are supported on ESP32 and NRF52840 boards.

Please let us know if you have any questions.

FreeOurToes wrote on November 27, 2019:

Thank you.

So it’s for switching between networks.

Are wifi reconnects being managed in network manager too?

Also, I noticed that functions
AwsIotNetworkManager_SubscribeForStateChange, AwsIotNetworkManager_EnableNetwork as being called inside initialization at iot_demo_freertos.c but at OTA demo vStartOTAUpdateDemoTask they are being called again.

Is there is a reason why OTA demo task is having another subscription? Does it mean that there are two active callback functions waiting for network changes? Is it possible that they could clash? let me know if I am missing something. Tthanks

ravishankar-AWS wrote on November 27, 2019:

Yes, WiFi disconnect and reconnect can be done in a similar way. We provide a demo application which reconnects to provisioned WiFi networks using network manager subscriptions here:

Essentially applications can subscribe for a WiFi network state change callback and trigger re-connection on a disconnect event from network manager.

+“Also, I noticed that functions+
+AwsIotNetworkManager_SubscribeForStateChange, AwsIotNetworkManager_EnableNetwork as being called inside initialization at iot_demo_freertos.c but at OTA demo vStartOTAUpdateDemoTask they are being called again. Is there is a reason why OTA demo task is having another subscription? Does it mean that there are two active callback functions waiting for network changes? Is it possible that they could clash?”+

No they wont clash and cause a problem. Startup code handles enabling networks and waiting for a network connection before calling the demos. You can subscribe to different callbacks and perform your callback specific operations in the demo.

1 Like

Hello,
I saw the above corresponding and I’m trying to see how I can use those instruction in my application.
My target is STM32L475 with Inventek WiFi module.
My code base is 202002 release.
Since I have only one network connection - WiFi, and I want to keep my system as simple as possible (as well as as small as possible - flash wise) I first tried to avoid using the network manager, I thought, as the above mention, that it is related only to the demos (and indeed it reside under the demo sub tree) but I realized that it will be harder for me not to use it then to use it in a limited way (with only one network).
Now, since I’m using it. I’m trying to get the most out of it and I want to use the the reconnect mechanism in it.
First, I must mention, that the wifi port I’m using (for the Invetek) does not have WIFI_RegisterNetworkStateChangeEventCallback implemented but I can identify a disconnection in my application logic and I want to trigger manually a reconnect using the network manager but I can’t figure out how to do it, even after I look on the aws_wifi_connect_task as suggested above.
Can you please elaborate on how I can implement a WiFi reconnected using the network manager?
Thanks

1 Like

Network Manager support requires registering for events from WiFi driver and it is supported currently only on Espressif ESP32 port.
As far as I understand, you already have application logic to determine when a network gets disconnected, you can trigger re-connection to an access point by simply calling WIFI_ConnectAP() API (with retries if necessary). An example can be found here.
aws_wifi_connect_task.c provides an example to reconnect to provisioned WiFi networks during network disconnect event.

Thank you for your reply, can you please explain if there is a way to totally avoid using the manager? As I wrote, I found it difficult to disconnect it from my app.