The content of this page has been automatically translated by AI. If you encounter any problems while reading, you can view the corresponding content in Chinese.
LLSync Bluetooth-assisted network configuration feature is an official Combo chip solution for Wi-Fi + BLE launched by Tencent Cloud IoT. It creates a designated GATT service through BLE. Mobile phones connect to the GATT SERVER. Leveraging the wireless communication capability of BLE, it transmits information required for IoT device connection, such as SSID and PASSWORD, to the Combo chip or module of Wi-Fi + BLE, enabling devices to smoothly integrate into the IoT platform and then complete functions such as device binding.
The main process of porting Bluetooth-assisted network configuration is as follows:
Choose appropriate Combo chips or modules according to product features.
Create a Product through the Console
1. Refer to console operations to create a device.
2. Select the device network configuration method in the console. Once confirmed, you can connect the device Bluetooth by scanning the QR code to configure the network.
Get SDK
The Bluetooth-assisted network configuration feature uses C SDK and LLSync SDK. Download the latest version for use. You can download ESP32 to use the LLSync network configuration sample program for reference.
Port SDK
The Bluetooth-assisted network configuration feature uses the communication capabilities of WI-Fi and BLE, so it includes the porting of C SDK and LLSync SDK.
1. Porting the LLSync SDK mainly involves configuration compilation, HAL implementation, and API calls.
1.1 Configuration compilation
Modify the config/ble_qiot_config.h file to configure features relevant to network setup, ignoring standard Bluetooth functions.
// Configured as 0, broadcast by default after SDK initialization. Configured as 1, no broadcast after SDK initialization. Need to trigger broadcast through device UI operation (for example, pressing a key).
#define BLE_QIOT_BUTTON_BROADCAST (0)
#define __ORDER_LITTLE_ENDIAN__ (1234)
#define __ORDER_BIG_ENDIAN__ (4321)
// Device endianness definition.
#define __BYTE_ORDER__ (__ORDER_LITTLE_ENDIAN__)
// Serial port output function on the device side.
The maximum length of single data in the communication process between the device and the mini program is 128 by defaultfor the networking functionality.
#define BLE_QIOT_EVENT_MAX_SIZE (128)
// Take the smaller value between MTU and BLE_QIOT_EVENT_MAX_SIZE. LLSync will perform data sharding before sending.
#define BLE_QIOT_EVENT_BUF_SIZE (23)
// Configured as 1, the mini program attempts to set MTU after establishing a bluetooth connection, obtained through the ble_get_user_data_mtu_size API; configured as 0, the default MTU is 23.
#define BLE_QIOT_REMOTE_SET_MTU (1)
// Configured as 1, enable the LLSync networking feature
#define BLE_QIOT_LLSYNC_CONFIG_NET (1)
LLSync's network configuration feature does not require ota, data templates and other capabilities. The SDK will control the compilation through feature macros.
1.2 HAL implementation
The LLSync SDK dependency on the device HAL implementation is defined in inc/ble_qiot_import.h. This needs to be implemented on your own hardware platform.
/* Obtain device MAC address, for example:
int ble_get_mac(char *mac)
{
char *address = (char *)esp_bt_dev_get_address();
memcpy(mac, address, 6);
return 0;
}
*/
intble_get_mac(char*mac);
Set WIFI mode. Currently supported: wifi station. Example:
/* Request a connection to WIFI using the set WIFI information. Example:
ble_qiot_ret_status_t ble_combo_wifi_connect()
{
ESP_ERROR_CHECK(esp_wifi_connect());
return 0;
}
*/
ble_qiot_ret_status_tble_combo_wifi_connect();
inc/ble_qiot_import.h defines the implementation of the Bluetooth protocol stack HAL required by the LLSync SDK. You need to implement it on your own hardware platform.
/* Obtain the Bluetooth service through ble_get_qiot_services and add the Bluetooth service to the protocol stack. The service UUID used for the configuration function is 0xFFF0, and the characteristic value UUIDs are 0xFFE1 and 0xFFE3. You can also choose other methods to add the service to the protocol stack. The following is a sample code for adding a Bluetooth service on ESP32:
/* User-specified MTU. When BLE_QIOT_REMOTE_SET_MTU is set to 1, the mini program will modify the MTU and notify the device after connecting to the device. Otherwise, communicate using the default MTU (23).
uint16_t ble_get_user_data_mtu_size(void)
{
return 128;
}
*/
uint16_tble_get_user_data_mtu_size(void);
1.3 API call
The API provided to the outside by the LLSync SDK is defined in inc/ble_qiot_export.h.
/* Obtain the LLSync Bluetooth service. You can add the Bluetooth service to the Bluetooth protocol stack after obtaining the Bluetooth service in code.*/
/* Initialization API for LLSync SDK, mainly performing the addition of Bluetooth services. It is called within start_device_btcomboconfig by default. You can also choose to call it in other positions.*/
// The mini program cannot obtain the Bluetooth MTU API. After the device receives the MTU modification notification, call this API to notify the mini program. For example:
case ESP_GATTS_MTU_EVT:
ESP_LOGI(LLSYNC_LOG_TAG,"ESP_GATTS_MTU_EVT, MTU %d", param->mtu.mtu);
After setting WIFI Mode, the device side replies to the mini program with the setting results. A result of 0 indicates successful setting,while others indicate an error. Example:
/* After setting WIFI information, the device side replies to the mini program with the setting results. A result of 0 indicates successful setting, while others indicate an error. Example:
2. C SDK porting, please refer to C SDK Usage Reference. C SDK has implemented the Distribution Network Code framework. You only need to implement the related HAL interfaces as required. To further simplify the adaptation steps, some C SDK HAL interfaces have already been implemented under the directory qcloud-iot-explorer-BLE-sdk-embedded/lib/qcloud_iot_c_sdk. You need to copy and overwrite the corresponding files in the directories qcloud-iot-explorer-sdk-embedded-c/platform and qcloud-iot-explorer-sdk-embedded-c/sdk_src/wifi_config.
You also need to implement the following HAL interfaces to complete the adaptation work of the network configuration feature.
/* Startup API for the COMBO device networking feature. By default, it calls the LLSync SDK initialization API. Modifications are needed as required. Sample code */
intstart_device_btcomboconfig(void)
{
// TODO other init (for example, Bluetooth protocol stack initialization)
ble_qiot_explorer_init();// init llsync sdk
return QCLOUD_RET_SUCCESS;
}
*/
intstart_device_btcomboconfig(void);
/* COMBO device network configuration feature stop API. By default, it calls the LLSync broadcast stop API. Modifications are needed as required. For example,
int stop_device_btcomboconfig(void)
{
ble_qiot_advertising_stop();
// TODO other deinit
return QCLOUD_RET_SUCCESS;
}
*/
intstop_device_btcomboconfig(void)
/* After the WIFI connection is successful, report to the mini program. You need to get the current WIFI connection information and call the ble_event_report_wifi_connect api to report. Example
/* Retrieve WIFI connection status. It is recommended to consider WIFI connected successfully only after obtaining an IP address. Example
bool HAL_Wifi_IsConnected(void)
{
// TODO, retrun true when you got ip
return false;
}
*/
bool HAL_Wifi_IsConnected(void);
/* Operation interface for network configuration error log. The following interfaces can be implemented when it is required to solidify log storage. When an error occurs, the device stores logs. When the device restarts, the logs are read to prevent loss of error information.
Select and configure the network connection feature in qcloud-iot-explorer-sdk-embedded-c/sdk_src/internal/inc/qcloud_wifi_config.h.
#define WIFI_ERR_LOG_POST 1 // Submit Wi-Fi configuration error log to the mini program on error
#define WIFI_LOG_UPLOAD 1 // Submit configuration process log to the mini program on configuration error
#define WIFI_PROV_BT_COMBO_CONFIG_ENABLE 1 // Select the LLSync networking feature. Networking options such as soft ap and airkiss need to be disabled.
5. Verify Bluetooth Assisted Network Configuration Functionality
1. After BLE adaptation is completed, device broadcast information and Bluetooth service information can be viewed through Nrf Connect.
2. Mini program LLSync network configuration example.