IoT Platform provides a solution to bind cameras without requiring communication between an app and a device on the same local network. This solution can be used as a backup method for network configuration if an app fails to discover and bind a device because of local network issues or router settings.
Network configuration process
The network configuration process is as follows.
The mobile app generates a QR code image.
The QR code contains the SSID, password, BSSID, and a 3-byte random number of the Wi-Fi network to which the mobile phone is connected.
The camera scans and parses the QR code.
The device calls the
awss_connectfunction in the IoT Platform software development kit (SDK). For more information about this function, see the Device-side API and implementation section in this topic. The device obtains the SSID, password, BSSID, and random number from the QR code and generates a token based on specific rules. For more information, see Rules for generating a token.The device reports the generated token to the cloud.
The app calls the Query device certificate information by token API operation to send polling messages to the cloud. After the app receives a success response, it sends a request to bind the device.
Device-side API and implementation
During device development, you must call the awss_connect function to parse the QR code, generate a token, and report the token to the cloud. The header file for this function is #include "connect_ap.h".
The prototype of the awss_connect function is as follows:
awss_connect(char ssid[HAL_MAX_SSID_LEN], char passwd[HAL_MAX_PASSWD_LEN], uint8_t *bssid, uint8_t bssid_len, uint8_t *token, uint8_t token_len, bind_token_type_t token_type)The following table describes the function parameters.
Parameter | Type | Description |
ssid | char | The SSID of the router. |
passwd | char | The password of the router. |
bssid | uint8_t * | The BSSID of the router, which is the MAC address. |
bssid_len | uint8_t | The length of the BSSID. |
token | uint8_t * | The token generated by the IoT Platform SDK based on specific rules. |
token_len | uint8_t | The length of the generated token. |
token_type | bind_token_type_t | The type of the generated token. Note This parameter is available only in IoT Platform SDK 1.6.0 and later. Ignore this parameter for SDK versions earlier than 1.6.0. |
The following code provides an example of how to use the awss_connect function. The parameter values are set as follows:
char* ref_ssid = "ssid";
char* ref_passwd = "passwd";
uint8_t ref_bssid[6] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
uint8_t ref_token[3] = {0xaa, 0xbb, 0xcc};
uint8_t ref_token_type = TOKEN_TYPE_NOT_CLOUD;The following code shows an example of a function call.
awss_connect(ref_ssid, ref_passwd, ref_bssid, 6, ref_token, 3, ref_token_type);Rules for generating a token
A QR code usually contains the BSSID, password, and random fields. To generate a token, concatenate the fields from the QR code and then use the first 16 bytes of the resulting string.
According to the QR code specification, the random field is required. The following table describes the rules for generating a token in different scenarios.
Scenario | Concatenation rule |
The QR code contains a BSSID and a password. | sha256(bssid(hex)+random(hex)+password(hex)) |
The QR code contains a password but no BSSID. | sha256(random(hex)+password(hex)) |
The QR code contains neither a BSSID nor a password. | sha256(random(hex)) |
The following example shows how to generate a token. The QR code fields are set as follows:
BSSID: C8:3A:35:23:08:31
SSID: myname
password: 12345678
RandomHex: 911182The QR code for this example is: {"v":"Ali_1","s":"myname","p":"12345678","b":"C83A35230831","t":"911182"} .
The device call is as follows:
char* ref_ssid = "myname";
char* ref_passwd = "12345678";
uint8_t ref_bssid[6] = {0xc8, 0x3a, 0x35, 0x23, 0x08, 0x31};
uint8_t ref_token[3] = {0x91, 0x11, 0x82};
awss_connect(ref_ssid, ref_passwd, ref_bssid, 6, ref_token, 3);
sha origin data = c83a352308319111823132333435363738,
sha = 8f2f5a6476bfabb52de0ea644b469eb5c70c2f4c6c05a51b8e70cdbe54ae8cb7
token = 8F2F5A6476BFABB52DE0EA644B469EB5Bind a camera across sites
Obtain the current site of the app.
For more information, see:
Generate a network configuration QR code for the camera.
The QR code must contain information such as the SSID, password, BSSID, random number, and region ID.
The camera parses the network configuration QR code.
The QR code is parsed as follows:
Call the
iotx_guider_set_dynamic_region(info->region_id);function to connect the device to the corresponding site.Call the
awss_connectfunction to parse other information.
Bind the camera.