RepositoryJavaCNChina
tuya

tuya/tuya-connector

tuya-connector helps you efficiently create cloud development projects regarding the OpenAPI or message subscription capabilities. You can put all the focus on business logic without taking care of server-side programming nor relational databases.

75stars
40forks
17issues
0views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: tuya

#1 Repository of the month

1
TINIX TRENDING·Topic: tuya-cloud

#1 Repository of the month

1
TINIX TRENDING·Topic: tuya-smart

#1 Repository of the month

English | 中文版

License: Apache 2 Version: 1.0.0

tuya-connector helps you efficiently create cloud development projects regarding the OpenAPI or message subscription capabilities. You can put all the focus on business logic without taking care of server-side programming nor relational databases.

demo vedio

Quick start

Integrate Spring Boot

<dependency>
  <groupId>com.tuya</groupId>
  <artifactId>tuya-spring-boot-starter</artifactId>
  <version>#{latest.version}</version>
</dependency>

<!-- Specify the Maven repository URL -->
<repository>
    <id>tuya-maven</id>
    <url>https://maven-other.tuya.com/repository/maven-public/</url>
</repository>

Configuration

# ClientId & SecretKey generated on the Tuya Cloud Development Platform
connector.ak=***
connector.sk=***

region configuration

# region configuration(default region is China if without configuration)
# more details, please check: com.tuya.connector.open.common.constant.TuyaRegion)
connector.region=CN

Usage

Call OpenAPI operations
  1. Create the Connector interface, which is the mapping class of OpenAPI.
public interface DeviceConnector {
    /**
     * query device info by device_id
     * @param deviceId
     * @return
     */
    @GET("/v1.0/devices/{device_id}")
    Device getById(@Path("device_id") String deviceId);
}
  1. Set @ConnectorScan for the class of the Spring Boot application. You can set @EnableMessaging to enable the message subscription capability.

Note: Since the connector SDK relies on the reflection mechanism, and starting from JDK 9, a modularization mechanism has been introduced. Therefore, when starting, you need to add the parameters --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED to avoid potential errors.

@ConnectorScan(basePackages = "com.xxx.connectors")
@EnableMessaging
@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}
  1. The Connector interface will be scanned and injected into the Spring container.
@Service
public class DeviceService {
    @Autowired
    private DeviceConnector device;

    public Device getById(String deviceId) {
        return device.getById(deviceId);
    }
}
Subscribe to message events
/**
 * device status data report event
 */
@EventListener
public void statusReportMessage(StatusReportMessage event) {
    log.info("### StatusReport event happened, eventInfo: {}", event);
}

How it works: implement extensions based on the connector framework.

Extension points of OpenAPI

  • ErrorProcessor

You can define the implementation class of ErrorProcessor to handle different error responses. For example, if a token expires, it can be automatically refreshed. The API operation will be tried again with the refreshed token. TokenInvalidErrorProcessor is the built-in implementation class of ErrorProcessor.

The extended ErrorProcessor must be injected into the Spring container to take effect.

  • ContextManager

The connector framework supports TuyaContextManager on which the automatic token refreshing depends. TuyaContextManager can prepare the context before API operations, and manage information including data source connection, tokens, and multilingual text.

  • TokenManager

TuyaTokenManager is the default token management mechanism and implements the TokenManager interface in the connector framework. The token information is cached on the premises.

To manage the token on the premises, you can extend TokenManager and inject it into the Spring container.

  • HeaderProcessor

TuyaHeaderProcessor implements the processing logic of the header for OpenAPI operations, including the required attribute values and signatures.

Extension points of messages

  • MessageDispatcher

TuyaMessageDispatcher implements MessageDispatcher interface for message dispatching in the connector framework. The dispatcher features message ordering and data decryption. It allows you to create specific message types and publish messages based on Spring's event mechanism.

  • MessageEvent

You can add ApplicationListener to listen for required events. The connector framework includes all the Tuya's message event types. The message data contains ciphertext messages and plaintext messages.

Message eventBizCodeDescription
StatusReportMessagestatusReportReport data to the cloud.
OnlineMessageonlineA device is online.
OfflineMessageofflineA device is offline.
NameUpdateMessagenameUpdateModify the device name.
DpNameUpdateMessagedpNameUpdateModify the name of a data point.
DeleteMessagedeleteRemove a device.
BindUserMessagebindUserBind the device to a user account.
UpgradeStatusMessageupgradeStatusThe update status.
AutomationExternalActionMessageautomationExternalActionAutomate an external action.
SceneExecuteMessagesceneExecuteExecute a scene.

Similar Projects

Discover other similar projects and AI models.

RepositoryJava
OpenAPITools/openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)

26.9k
Nov 27, 2026
RepositoryJava
traccar/traccar

Open source GPS tracking platform - self-hosted or managed, 200+ device protocols

8.2k
Nov 27, 2026
RepositoryJava
swagger-api/swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API

7.5k
Nov 27, 2026
RepositoryJavaScript
swagger-api/swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.

29.1k
Dec 2, 2026
RepositoryC
arendst/Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at

25.1k
Dec 1, 2026
RepositoryGo
grpc-ecosystem/grpc-gateway

gRPC to JSON proxy generator following the gRPC HTTP spec

20.0k
Dec 2, 2026
RepositoryTypeScript
scalar/scalar

Scalar is an open-source API platform:                                       🌐 Modern REST API Client                                        📖 Beautiful API References                                        ✨ 1st-Class OpenAPI/Swagger Support

16.5k
Nov 29, 2026
RepositoryGo
darrenburns/posting

The modern API client that lives in your terminal.

12.7k
Oct 16, 2026
RepositoryPython
vitalik/django-ninja

💨 Fast, Async-ready, Openapi, type hints based framework for building APIs

9.3k
Nov 17, 2026