Blink an LED on ESP32 board with Tuya Link SDK

tuya link sdk

Tuya is an All-in-one IoT Platform that enables the user to build smart IoT solutions by connecting devices efficiently, securely, and reliably. This is a getting started article to set up the Tuya platform with the Espressif’s ESP32 boards via tuya link SDK. Further, we use it to control an LED through an Android device. When the switch in the Tuya Smart App is turned ON, the LED connected to the ESP32 board glows and vice versa.

Prerequisites

Hardware:

  • ESP32 board
  • LED with suitable ballast resistor
  • Breadboard, micro-USB cable, and connecting wires

Software:

GitHub Link: https://github.com/JayeshRajam/Tuya-ledapp.git

The ESP32 board is placed on a breadboard. The positive terminal of the LED is connected to digital pin 5 of the ESP32 board and the negative terminal is connected to the ground pin via the ballast resistor as shown in the following circuit diagram.

esp32 board hardware connections for tuya link sdk

Software Setup: Tuya IoT Platform

Login to your Tuya Account or if you don’t have an account then create one using the SignUp option.

Tuya Login Page

Once Logged In, an overview of the platform is visible. Click the Create button to start a new Project.

Tuya Dashboard

To develop the application for ESP32 click on ‘Can’t find the category?’. The following custom creation menu should appear.

Tuya Custom Category Creation

Fill the required fields as done above and click Create. A pop-up box will appear, just close it to get the following screen.

Tuya Function Dashboard

Here, we’ll add a custom function of the following settings.

Custom Function Creation

Click OK. The function will now be visible.

Tuya link SDK custom function visible

Tuya Smart Application Graphical User Interface (GUI) now needs to be developed. For that, simply switch to the Device Panel tab and select ‘Create Blank Panel’.

Device Panel Tab

Following are the steps to complete the UI Studio procedure.

You can always test and release the application before moving further. You can also visit this article to know more about the Tuya platform for designing and manufacturing smart home solutions.

Note: The testing procedure requires you to install and login to the Tuya Smart Application on your Android and enter the same login email id here.

UI test and release

UI Testing ProcessOnce back to the Tuya IoT platform, it’s now time to generate a license for Link SDK.

license generation for link SDK

Select Link SDK Cloud Access Mode from the Hardware Development Tab. Click on the ‘Select’ button provided to place the License order. Click ’Get 2 Free Licenses’ and complete the steps to finally download a .xlsx file with uuid and key.

Now it’s time to install tuyaos-link-sdk to avail connectivity to Tuya Smart Application via Python 3.x. On your Windows PC run the following commands to clone the GitHub repository and install the tuyaos-link-sdk.


tuyaos-link-sdk install python

Open the ledapp.py file from the GitHub repo in the editor. Edit and change the productid, uuid, authkey and the COM port of your connected ESP32 device in the file. We’ll further use this file in the output section of this article.

Software Setup: Tuya Smart Application

Install the Tuya Smart App from the Google Play Store of your Android Device.
Tuya Smart App Google Play Store

Login to your Account or if you don’t have one create one!

Tuya Smart Account Login

Now from the add device section click the scanner button to scan the QR code generated by the ledapp.py file.

Tuya Smart Add device  Tuya Smart Add device Options

Tuya Smart Scan

Now the ESP Application will be added to the All Devices section of the Tuya Smart App.

Tuya Smart App ESP Application

The Arduino IDE here is used to process the serial message from the desktop Python on the ESP32 board similar to the PhysicalPixel Built-in Example.
Add the ESP32 board in the Arduino IDE

Arduino IDE Boards ESP32

Board Manager URL: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json

When the incoming Byte over serial is ‘H’, the program turns the LED on. The LED is turned off when the incoming Byte is ‘L’. Remember to set the proper GPIO pin to which the LED is connected.

Output

Run the ledapp.py file using the command


Tuya link SDK Output 1.jpg

Tuya link SDK Output 2

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK 5 ITX Rockchip RK3588 mini-ITX motherboard
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
21 Comments
oldest
newest
Tim
Tim
2 years ago

I’m not sure how secure Tuya really is but I hope it is at least minimally secure as I have a bunch of devices which use SmartLife/Tuya.

Thanks for the article, it’s interesting seeing how it can be used on personal devices.

2 years ago

Can check the docs anytime for Tuya Security and Compliance
https://www.tuya.com/rule#:~:text=privacy%20and%20compliance%20requirements

Alex WK
Alex WK
2 years ago

Hi,
thanks for the article.
That is a good starting point for homr-brew application to add within the TUYA-space.
But what are te restrictions of ’Get 2 Free Licenses’ ?
How many devices (same/different) can I develop.
Note: Only for my home, not commercial use…
Regards Alex

2 years ago

Its just a Generic License

Screenshot 2021-12-14 002111.jpg
2 years ago

Hope, this answers your query.

Screenshot 2021-12-14 002235.jpg
solipso
solipso
2 years ago

Good luck building your network infrastructure based on some anonymous cloud provider somewhere in a communist country.

Rainer
Rainer
2 years ago

Hi there !

Maybe it is interesting for you to have a look at this video first:

https://media.ccc.de/v/35c3-9723-smart_home_-_smart_hack

This talk was primarily held in German language, but:

This Talk was translated into multiple languages. The files available for download contain all languages as separate audio-tracks. Most desktop video players allow you to choose between them.
Please look for “audio tracks” in your desktop video player.

And maybe you then want to use this SW-tool:
https://github.com/ct-Open-Source/tuya-convert

Best regards
Rainer

2 years ago

Thanks

Rainer
Rainer
2 years ago

No problem.
Your welcome.

Whenever possible I, for myself, try to use TASMOTA.
And I also will prefer devices, that are supported by TASMOTA.

https://github.com/arendst/Tasmota

https://www.cnx-software.com/?s=tasmota&post_type=post

Regards
Rainer

Ydalir
Ydalir
2 years ago

Have a Link at tuyas Cookie information. You ganz 813 companies to deal with your data. I am not talking against guys, but in a should have a closer look at this before accepting cookies or opening an account

Josef
Josef
2 years ago

Hello alltogether
does the system work also with zigbee devices? This is a real jungle with all the smart home devices.

2 years ago

A Tuya Zigbee page is available at https://www.tuya.com/solution/communication/zigbee
It can be explored.

hajeekkss
hajeekkss
2 years ago

Hey!
do you help me regarding “how to send sensor bool data to the tuya sdk with esp32 to link it with the respecting datatype”
thanks..

Julio Cesar
2 years ago

I don’t understand, what code should I flash on the ESP32?
BTW, could I use ESP8266?

Kenji0630
Kenji0630
2 years ago

hello,
I am interested in a cloud IoT system called Smartlife (tuya), and I am researching various things.

Is it possible to write the function of the “ledapp.py” part to the ESP32 module in the above article?

On the tuya IoT platform site, once you get the PID, you get the firmware automatically generated on the psm site along with the UUID etc. and download it to the module. Can you make this firmware yourself?

RLG
1 year ago

Hello good morning from Spain.
 I think I have everything, although it is a bit tangled.
 when executing the ledapp.py it gives an error.
 import serial
ModuleNotFoundError: No module named ‘serial’
Thank you.

Jean-Luc Aufranc (CNXSoft)
Admin

That probably means you need to install the Python serial module first:

RLG
1 year ago

Good morning;
 Thanks for the help, it ends well and the QR code appears.
 The sw is already uploaded to the ESP32 through Arduino.
When scanning the code to register the device says that it cannot be found, check if the device is connected or the QR code is correct.
 any ideas ??
Thank you very much for your help.
Sorry for my english is with google.

Jean-Luc Aufranc (CNXSoft)
Admin

Try to check the serial console on the ESP32 device to make sure there aren’t any error messages.

Armando
Armando
7 months ago

Hi,
Thanks for your interesting article. When I try to run the ledapp.py it gives me the following error.
 File “C:\Users\Desktop\tuyaos-link-sdk-python\ledapp.py”, line 7
  <!DOCTYPE html>
  ^
SyntaxError: invalid syntax

Would you know why that is?

Jean-Luc Aufranc (CNXSoft)
Admin

It looks like you may have downloaded the web page hosting ledapp.py instead of the raw file.

Boardcon Rockchip RK3588S SBC with 8K, WiFI 6, 4G LTE, NVME SSD, HDMI 2.1...