Step 3: Authorize Devices
Device authorization writes a TuyaOpen license โ a UUID and an AuthKey โ into your device so it can connect to the Tuya IoT Cloud. Every device needs a unique license before it can pair and come online.
For what a license is and how to obtain one, see TuyaOpen dedicated license.
You can authorize a device in two ways:
- Run the authorization command over the serial monitor.
- Modify the configuration header file.
Use the command method when your firmware supports the auth CLI. Use the header-file method when it does not, or when you prefer to bake the license into the build.
Run the authorization commandโ
-
Start the serial monitor:
tos.py monitor -b 115200tipSelect the serial port used for flashing.
tipRun this command from the application project path (where you run
tos.py build), and only after the project has compiled successfully. -
Type
authand press Enter. The tool prints the expected usage:[INFO]: Run Tuya Uart Tool.--------------------1. /dev/ttyACM12. /dev/ttyACM0--------------------Select serial port: 2[INFO]: Open Monitor. (Quit: Ctrl+c)authauthUse like: auth uuidxxxxxxxxxxxxxxxx keyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxtuya> -
Write the
uuidandauthkeywith theauthcommand. A successful write printsAuthorization write succeeds.:tuya>auth uuid9f6a6xxxxxxxxxxx cGuDnU2YxjHJldjxxxxxxxxxxxxxxxxxauth uuid9f6a6xxxxxxxxxxx cGuDnU2YxjHJldjxxxxxxxxxxxxxxxxxAuthorization write succeeds. -
Verify the write with the
auth-readcommand. The device echoes the storeduuidandauthkey:tuya>auth-readauth-readuuid9f6a6xxxxxxxxxxxcGuDnU2YxjHJldjxxxxxxxxxxxxxxxxx -
Reboot the device for the authorization to take effect.
If the device does not support the auth command, use the header-file method below instead.
Modify the header fileโ
-
Locate the
tuya_config.hfile in your project directory. The exact directory varies by project โ check thesrcorincludedirectory. -
Set the authorization fields:
#define TUYA_OPENSDK_UUID "uuidxxxxxxxxxxxxxxxx" // Change to the correct uuid#define TUYA_OPENSDK_AUTHKEY "keyxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" // Change to the correct authkey -
Rebuild the firmware, flash it to the device, and power on the device.