Tuya IoT Link SDK for Embedded C

TuyaIoTLinkSDKforEmbeddedC是一款跨平台的嵌入式物联网SDK,采用C语言编写,适用于支持TCP/IP协议栈的设备。该SDK提供了包括设备连接、上行下行通信及OTA在内的核心能力,并且不依赖于特定的操作系统。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Tuya IoT Link SDK for Embedded C

Table of Contents

Overview

Tuya IoTOS Link SDK provides core capabilities, such as device connection, uplink and downlink communication, and OTA across platforms and operating systems.
The SDK is implemented in the C programming language and does not depend on the specific device platform and OS environment. It only needs to support the TCP/IP protocol stack and provide the necessary system-dependent interfaces of the SDK to complete the integration.

Get started

Prerequisites

Ubuntu and Debian

sudo apt-get install make cmake libqrencode-dev

Clone the repository

git clone https://github.com/tuya/tuya-iot-link-sdk-embedded-c.git --recurse-submodules

Compile the code

mkdir build && cd build
cmake ..
make

Run the demo

./bin/switch_demo

Usage example

  1. Initialize a client object tuya_iot_client_t client. tuya_iot_config_t is used to initialize the product ID, authorization information, and other configuration parameters.
/* Instantiate the client */
tuya_iot_client_t client; 

/* Instantiate the config */
tuya_iot_config_t config = {
    .software_ver = "1.0.0",
    .productkey = <Product ID>,
    .uuid = <UUID>,
    .authkey = <AUTHKEY>,
    .event_handler = user_event_handler_on
};

/* Initialize the client */
tuya_iot_init(&client, &config);
  1. Define application layer event callbacks. The callback function is used for the application layer to receive SDK event notifications, such as data point (DP) delivery and cloud connection status notifications:
/* Tuya SDK event callback */
void user_event_handler_on(tuya_iot_client_t* client, tuya_event_msg_t* event)
{
    switch(event->id){
    case TUYA_EVENT_DP_RECEIVE:
        TY_LOGI("DP recv:%s", (const char*)event->data);
        /* After receiving the DP distribution, 
        the DP data needs to be reported to synchronize the APP status. */
        break;

    case TUYA_EVENT_MQTT_CONNECTED:
        TY_LOGI("Device MQTT Connected!");
        break;
    ...

    default:
        break;
    }
}
  1. Start the Tuya Link SDK service.
tuya_iot_start(&client);
  1. A loop is called to yield the current thread to the underlying Tuya Link SDK client.
tuya_iot_yield(&client);

Report example:

/* Boolean */
const char bool_value[] = {"{\"101\":true}"};
tuya_iot_dp_report_json(&client, bool_value);

/* Integer */
const char int_value[] = {"{\"102\":123}"};
tuya_iot_dp_report_json(&client, int_value);

/* String*/
const char string_value[] = {"{\"103\":\"helloworld\"}"};
tuya_iot_dp_report_json(&client, string_value);

/* Enum */
const char enum_value[] = {"{\"104\":\"auto\"}"};
tuya_iot_dp_report_json(&client, enum_value);

/* RAW */
const char raw_value[] = {"{\"105\":\"aGVsZA==\"}"};
tuya_iot_dp_report_json(&client, raw_value);

/* Multiple combinations */
const char multiple_value[] = {"{\"101\":true,\"102\":123,\"103\":\"hellowrold\",\"104\":\"auto\",\"105\":\"aGVsZA==\"}"};
tuya_iot_dp_report_json(&client, multiple_value);

License

Distributed under the MIT License. For more information, see LICENSE.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值