Skip to main content

Tuya IoT Client API Reference

Overview

tuya_iot.h defines the Tuya IoT client: configuration, lifecycle (init, start, yield, stop, destroy), cloud activation, MQTT, DP reporting, and events. Cloud apps use this layer on top of TAL (Wi-Fi, network, KV).

Source: TuyaOpen/src/tuya_cloud_service/cloud/tuya_iot.h

Audience: Developers extending Tuya Cloud demos such as switch_demo or the IoT light sample.

note

Tuya Cloud needs a valid license key and product setup. See Equipment authorization.

Configuration

TypeRole
tuya_iot_config_tProduct key, UUID, auth key, software version, optional modules, event_handler, network_check, ota_handler.
tuya_iot_license_tUUID and auth key for license read.
tuya_activated_data_tDevice ID, keys, schema, timezone after activation.
tuya_event_msg_tEvent id, type, and value for event_handle_cb_t.

Lifecycle

FunctionDescription
tuya_iot_license_readRead license from storage.
tuya_iot_initInitialize from config.
tuya_iot_startStart cloud service.
tuya_iot_yieldPump the client (call regularly).
tuya_iot_stopStop service.
tuya_iot_resetReset client.
tuya_iot_destroyFree resources.
tuya_iot_reconnectReconnect MQTT.

Data points

FunctionDescription
tuya_iot_dp_report_jsonReport DP JSON.
tuya_iot_dp_report_json_with_timeReport with timestamp JSON.
tuya_iot_dp_report_json_asyncAsync with callback and timeout.
tuya_iot_dp_report_json_with_notifySync with notify callback.

Incoming DPs use events such as TUYA_EVENT_DP_RECEIVE, TUYA_EVENT_DP_RECEIVE_CJSON, TUYA_EVENT_DP_RECEIVE_OBJ, TUYA_EVENT_DP_RECEIVE_RAW.

State and getters

FunctionDescription
tuya_iot_activatedActivation flag.
tuya_iot_activated_data_removeClear activation storage.
tuya_iot_token_get_port_registerCustom token hook.
tuya_iot_version_update_syncPush software version.
tuya_iot_extension_modules_version_updateExtension module version.
tuya_iot_devid_get, tuya_iot_localkey_get, tuya_iot_seckey_get, tuya_iot_timezone_getActivated device fields.
tuya_iot_client_getGlobal client pointer.
tuya_iot_is_connectedCloud connected.
tuya_iot_dispatch_eventDispatch helper.

Selected events

Examples from tuya_event_id_t: TUYA_EVENT_RESET, TUYA_EVENT_BIND_START, TUYA_EVENT_ACTIVATE_SUCCESSED, TUYA_EVENT_MQTT_CONNECTED, TUYA_EVENT_MQTT_DISCONNECT, TUYA_EVENT_UPGRADE_NOTIFY, TUYA_EVENT_TIMESTAMP_SYNC. See the header for the full list.

tuya_client_status_t reports coarse Wi-Fi and MQTT states.

References