Giter VIP home page Giter VIP logo

tuya-iot-link-sdk-embedded-c's Introduction

Tuya IoT Link SDK for Embedded C(beta)

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.

tuya-iot-link-sdk-embedded-c's People

Contributors

0x1abin avatar mhtcc520 avatar peiqi-xu avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.