TuyaOSNetworked Product FrameworkCapability MapActivate Devices over Bluetooth Without Internet

Activate Devices over Bluetooth Without Internet

Last Updated on : 2023-12-19 08:36:57download

Without a direct connection to the internet, a Bluetooth and Wi-Fi combo device can connect to the mobile app over Bluetooth. The mobile app then acts as a proxy to activate the device in the cloud. This feature is also known as PlugPlay pairing.

Feature description

To use this feature, go to the Tuya IoT Development Platform > Function Definition and enable PlugPlay in Advanced Functions.

Activate Devices over Bluetooth Without Internet

How it works:

  1. The device sends device information to the mobile app over Bluetooth.
  2. The mobile app sends the device information to the cloud to activate the device in the cloud and get the activation information. The device will be in the activated and bound state.
  3. Then, the mobile app can control and communicate with the device over Bluetooth.

Process

AppDeviceCloudThe user triggers Bluetooth pairing.Send advertising packets.Scan for Bluetooth advertising packets and discover the device.Connect to the device over Bluetooth.Connected.The user chooses to use PlugPlay pairing.Or when the device fails to connect to the Wi-Fi or the cloud,PlugPlay pairing is triggered.Query device information.Return device information.Send device information for activation.Return device DP description.Send device DP description.Data is received.The device is in the activated and bound state.The user controls the device using the app.Send a control command.Execute the command.Return the current status.AppDeviceCloud

Development guide

Runtime environment

Open tuya_iot_config.h and check if the following macro is defined.

/* Bluetooth service enablement */
#define ENABLE_BT_SERVICE 1

/* Bluetooth pairing enablement */
#define ENABLE_BT_ACTIVE 1

Requirements

  • The device must have enabled the PlugPlay feature.
  • No additional development or API calls is required to use this feature.

How to

The mobile app will trigger PlugPlay pairing in the following two cases.

  • Case 1: The following error occurs during Bluetooth pairing.

    /* Error code returned when the device failed to connect to the Wi-Fi or cloud. */
    typedef int AP_CFG_ERR_CODE;
    #define AP_CFG_SUCC 0
    #define AP_CFG_ERR_PCK 1
    #define AP_CFG_AP_NOT_FOUND 2
    #define AP_CFG_ERR_PASSWD 3
    #define AP_CFG_CANT_CONN_AP 4
    #define AP_CFG_DHCP_FAILED 5
    #define AP_CFG_CONN_CLOUD_FAILED 6
    #define AP_CFG_GET_URL_FAILED 7
    #define AP_CFG_GW_ACTIVE_FAILED 8
    #define AP_CFG_GW_ACTIVE_SUCCESS 9
    
  • Case 2: The user chooses to use PlugPlay pairing on the mobile app.

FAQs

Will the mobile app automatically trigger PlugPlay if pairing failed?

PlugPlay is triggered only when Bluetooth pairing failed.

If the device is paired over Wi-Fi, such as AP mode or Pegasus pairing, PlugPlay will not be triggered. And, the mobile app triggers PlugPlay only for devices that have this feature enabled.