The device broadcasts an access point (AP). The mobile app connects to the device’s AP and sends the Wi-Fi credentials and pairing token to the device for activation.
Process
App Router Cloud Device Connect to the router's Wi-Fi. Connected. Get the token. Return the token. Device broadcasts an AP. Connect to the device's AP. Connected. Get the IP address. Return the IP address, such as xxx.xxx.176.xxx Send a UDP packet, with the type field being 0x11. Receive the UDP packet. Send the Wi-Fi credentials and the pairing token. Connect to the router's Wi-Fi. Return the IP address after being connected. Poll for activated devices by the token. Request activation. Activated. MQTT is connected. Return the activated devices. Query device information. Return device information. App Router Cloud Device Development guide
Prerequisites
You have a Tuya-enabled app, router, and device ready.
The device supports two Wi-Fi modes: AP mode and station mode.
Device development
Set the pairing mode to wireless.
connect_mode = PARING_MODE_WIFI_AP
Set the connection mode to wireless.
TUYA_IPC_LINK_TYPE_E link_type = TUYA_IPC_LINK_WIFI;
ipc_sdk_run_var.net_info.link_type = link_type;
Adapt tkl_wifi.c
.
The development framework provides a set of APIs for Linux. You need to adapt the implementation to your specific hardware.
API call sequence
Start pairing
Switch to station mode
SDK calls tkl_wifi_get_mac
SDK calls tkl_wifi_start_ap
Set the SSID, password, and IP address following WF_AP_CFG_IF_S
SDK exchanges pairing information with the app
SDK gets pairing information
SDK calls tkl_wifi_stop_ap
SDK calls tkl_wifi_station_connect
SDK calls tkl_wifi_station_get_status and tkl_wifi_get_ip to poll for the network status
After connecting to the router, the device proactively notifies the SDK of the network status through WIFI_EVENT_CB
SDK completes cloud registration and activation
Get notified of the online status through ipc_status_change_cb
End pairing
FAQs
Why can’t the mobile app detect the device’s AP?
Check if the device operates in the AP mode.
Check if the AP name and IP network segment are set correctly with cfg
in tkl_wifi_start_ap
.
Why can’t the device be activated even when the mobile app connects to the device’s AP and sends the Wi-Fi credentials?
Check if the device has called tkl_wifi_station_connect
.
Check if the device can access the internet.
Check if the IP network segment is set correctly with cfg
in tkl_wifi_start_ap
.
Confirm that the IP address assigned to the app is in the 192.168.176.x
network segment.
Check if WIFI_EVENT_CB
proactively notifies the SDK of the status of the router connection.
Check the value of PID, UUID, and AUTHKEY.
How can I change the AP name?
The name of the AP defaults to SmartLife_xxxx
where SmartLife
is hard coded and xxxx
represents the MAC address of the device.
You can customize the AP name with WF_AP_CFG_IF_S
in tkl_wifi_start_ap
.
Tuya-enabled mobile apps can only detect APs with the prefix SmartLife
. If you have specific requirements, contact your project manager.