AmazonFreeRTOS Bluetooth Questions

0

Hello, I'm working on a mobile app (iOS app) that communicates with a device that is running the AmazonFreeRTOS firmware. I've downloaded the AmazonFreeRTOS and AmazonFreeRTOSDemo projects and incorporated them into my app, mostly successfully, but with a couple of minor issues.

The only goal of my iOS app is to configure the device to connect to a Wifi network. So I'm only interested in the "NetworkConfigControl" service. The device I'm using for testing is an Espressif ESP32 dev board.

My app is able to detect the ESP32 via Bluetooth, pair with it, and obtain from it a list of Wifi networks by sending the ListNetworkReq message and listening for ListNetworkResp responses. This part works well.

When I want to connect to a network, I send a SaveNetworkReq message containing the Wifi password for that network. About 50% of the time, I get back an acknowledgement (SaveNetworkResp) that tells me it succeeded. The other half of the time, I get no response. However, I know that it succeeded because I can see that the device is connected to my Wifi network (it appears in my router's device table). I'm also no longer able to see the device advertising anything via Bluetooth.

The firmware developer I'm working with claims that this is the expected behavior. He says that once the ESP32 has established a Wifi connection, it will drop the Bluetooth connection. This seems odd to me.

Another question I have is -- when I send the SaveNetworkReq, there is a flag in that request that says "Connect immediately or just save for later". I've been setting this flag to true. If I set it to false, would that solve the problem? But if I do set it to false, what command do I need to send to have it connect later?

Thanks, Frank

Frank
asked 2 years ago273 views
1 Answer
0

Hi Frank.

When the WiFi connects, the stock demo firmware automatically stops the BLE provisioning. However, there is a delay that I think should allow you to get a response to your SaveNetworkReq before the BLE is stopped: https://github.com/aws/amazon-freertos/blob/main/demos/wifi_provisioning/aws_wifi_connect_task.c#L101 . The stock demo firmware delay is 5s; perhaps it's been reduced in your system?

For the connect now flag, this is where it's used: https://github.com/aws/amazon-freertos/blob/main/libraries/ble/src/services/wifi_provisioning/iot_ble_wifi_provisioning.c#L596 . The _connectNetwork() function then calls WIFI_ConnectAP().

If you don't connect when you add the network, I see two ways to connect later.

Firstly, the application firmware can trigger a connection to a previously saved network by calling IotBleWifiProv_Connect(): https://github.com/aws/amazon-freertos/blob/main/libraries/ble/src/services/wifi_provisioning/iot_ble_wifi_provisioning.c#L974 . That's done from here: https://github.com/aws/amazon-freertos/blob/main/demos/wifi_provisioning/aws_wifi_connect_task.c#L129 . And this appears to only happen when the system boots up: https://github.com/aws/amazon-freertos/blob/main/demos/wifi_provisioning/aws_wifi_connect_task.c#L162 . In the stock demo firmware anyway.

Secondly, it seems if you send another add/save network request for a WiFi network you already added/provisioned previously, it will be connected: https://github.com/aws/amazon-freertos/blob/main/libraries/ble/src/services/wifi_provisioning/iot_ble_wifi_provisioning.c#L749

I hope this helps. I haven't played with this code before. This is just a reading of the source.

profile pictureAWS
EXPERT
Greg_B
answered 2 years ago
  • Hi, thanks for the response. I've had success with the latter approach, that is, I'm setting the connect flag to false initially and then later saving it again with a value of true. This at least lets my user choose a network and get it connected. Once it's connected though, if I try to list networks again, I get no response from the device (not even a failure response).

  • I've also noticed another issue. At my office we have a 2.4ghz network and a 5ghz network. My ESP32 dev board shows me both of them when I try to list networks (assuming I'm not already connected) but it can only connect to the 2.4ghz network. If I try to connect to the other one, it appears to succeed, but my device never connects to IOT services.

  • Once it's connected though, if I try to list networks again, I get no response from the device (not even a failure response).

    Once WiFi is connected, the Bluetooth provisioning service is stopped, so none of the BLE commands can work, including ListNetworks.

  • Is there some way I can test to see if WiFi is connected, short of trying to list networks and waiting for it to time out?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions