IoT -- BLE Configure WiFi Microcontroller
by xidameng in Circuits > Arduino
509 Views, 0 Favorites, 0 Comments
IoT -- BLE Configure WiFi Microcontroller
How many times we find it frustrating to upload the firmware to your WiFi microcontroller all over again just to change its WiFi configuration(like SSID and password). Worry no more ! If you are using a WiFi microcontroller that is also equiped with BLE, then just with a few simple taps you can configure the WiFi configuration over the air, here is how
Supplies
Ameba RTL8722 x 1
Smartphone x 1
Code
#include "BLEDevice.h"
#include "BLEWifiConfigService.h"
BLEWifiConfigService configService;
void setup() {
Serial.begin(115200);
BLE.init();
BLE.configServer(1);
configService.addService();
configService.begin();
// Wifi config service requires a specific advertisement format to be recognised by the app // The advertisement needs the local BT address, which can only be obtained after starting peripheral mode // Thus, we stop advertising to update the advert data, wait for advertising to stop, then restart advertising with new data
BLE.beginPeripheral();
BLE.configAdvert()->stopAdv();
BLE.configAdvert()->setAdvData(configService.advData());
BLE.configAdvert()->updateAdvertParams();
delay(100);
BLE.configAdvert()->startAdv();
}
void loop() {
delay(1000);
}
Guide
In this example, a WiFi configuration service is set up on the Ameba Bluetooth stack. A mobile phone with the configuration app connects to the Ameba device using BLE and configures the Ameba to connect to the correct WiFi access point.
Ensure that the Realtek WiFi configuration app(see above) is installed on your mobile phone, it is available at: – Google Play Store: https://play.google.com/store/apps/details?id=com... Apple App Store: https://play.google.com/store/apps/details?id=com...
Upload the code provided earlier and press the reset button on Ameba once the upload is finished. On your mobile phone, open the Realtek WiFiConfig app and tap the round button to scan for Ameba boards.
Select the correct Ameba board from the scan results. The app will connect to the Ameba board and ask the board to scan for WiFi networks and send the scan results back to the app using BLE.
If your phone is currently connected to a WiFi network, the app will ask for the WiFi password to connect the Ameba board to the same WiFi network. Tap “Select AP” to choose another WiFi network, or enter the password and tap continue to connect Ameba to the selected WiFi network.
After the Ameba board connects to the WiFi network, the following message will be shown. Tap “Try another AP” to connect to another WiFi network or tap “Confirm” to keep the current WiFi network and disconnect BLE from the Ameba board.