{"id":19858394,"url":"https://github.com/tuya/tuya-socket-android-sdk","last_synced_at":"2026-05-10T12:01:57.208Z","repository":{"id":103228849,"uuid":"322154949","full_name":"tuya/tuya-socket-android-sdk","owner":"tuya","description":"It is mainly aimed at Android developers in Tuya cloud products. The project aims to provide a local area network connection between an Android phone and a hardware device, and send dpCode in the local area network for device control communication.","archived":false,"fork":false,"pushed_at":"2021-02-20T09:16:18.000Z","size":140,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-01-11T14:25:49.414Z","etag":null,"topics":["tuya"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tuya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-17T02:16:01.000Z","updated_at":"2024-10-19T12:00:34.000Z","dependencies_parsed_at":"2024-01-20T23:45:12.881Z","dependency_job_id":null,"html_url":"https://github.com/tuya/tuya-socket-android-sdk","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuya%2Ftuya-socket-android-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuya%2Ftuya-socket-android-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuya%2Ftuya-socket-android-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuya%2Ftuya-socket-android-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tuya","download_url":"https://codeload.github.com/tuya/tuya-socket-android-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241255122,"owners_count":19934815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["tuya"],"created_at":"2024-11-12T14:23:18.555Z","updated_at":"2026-05-10T12:01:52.184Z","avatar_url":"https://github.com/tuya.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tuya Smart Socket SDK\n\n[English](README.md) | [中文版](README_zh.md)\n\n## Introduction\n\nTuya Smart Socket SDK is used for Android development of Tuya's cloud products. The project provides a local area network (LAN) connection between an Android phone and a device, and sends dpCode in the LAN for device control communication.\n\nThe following figure shows device connection and control process:\n\n![https://cdn.nlark.com/yuque/__puml/1de1d74497bdbb14a4debde42f3f3f34.svg](https://cdn.nlark.com/yuque/__puml/1de1d74497bdbb14a4debde42f3f3f34.svg)\n\n## Preparation\n\nYou can refer to the demo [localcontroldemo](localcontroldemo).\n\nAdd tuya maven url to `build.gradle` in root directory\n\n\tallprojects {\n\t    repositories {\n\t        maven {\n\t            url \"https://maven-other.tuya.com/repository/maven-releases/\"\n\t        }\n\t        google()\n\t        jcenter()\n\t    }\n\t}\n\nAdd dependency to `build.gradle` in module.\n\n\timplementation 'com.tuya.smart:socket-sdk:0.1.1'\n\n## 1. Initialization\n\nThe initialization interface is called when the application or Activity starts.\n\n    /**\n     * Initialize and register listener\n     * @param context context\n     * @param socketListener \n     */\n    void init(Context context, TuyaSocketListener socketListener);\n   \n\nThe methods in TuyaSocketListener is as follows:\n\t\n    /**\n     * Called on disconnection\n     * @param deviceId \n     * @param errorCode {@link com.tuya.sdk.lancontrol.api.ErrorCode}\n     */\n    void onDisconnected(String deviceId, int errorCode);\n\n    /**\n     * Called when connection succeeds\n     *\n     * @param deviceId \n     */\n    void onConnected(String deviceId);\n\n    /**\n     * Device control succeeded, and hardware reports the control success commands\n     * \n     * @param deviceId\n     * @param commands The control success commands\n     */\n    void onCommandsReceived(String deviceId, Map\u003cString, Object\u003e commands);\n\n\nExample:\n\n    TuyaSocketManager.getInstance().init(this, new TuyaSocketListener() {\n        @Override\n        public void onDisconnected(String deviceId, int errorCode) {\n            LogUtils.i(\"onDisconnected : deviceId = \" + deviceId + \"\\n errorCode = \" + errorCode);\n        }\n\n        @Override\n        public void onConnected(String deviceId) {\n            LogUtils.i(\"onConnected : deviceId = \" + deviceId);\n        }\n\n        @Override\n        public void onCommandsReceived(String deviceId, Map\u003cString, Object\u003e commands) {\n            LogUtils.i(\"onCommandsReceived : deviceId = \" + deviceId + \"\\n commands = \" + commands);\n        }\n    });\n\n\n## 2. Add device information\n\nAdd device information to the SDK, and the SDK will automatically establish a LAN connection with the device.\n\nThis parameter can be obtained through the cloud-connection interface `/ v1.0 / devices / schema`.\n\n    /**\n     * \n     * @param deviceInfoJsonString Data returned from interface /v1.0/devices/schema\n     */\n    void addDeviceInfo(String deviceInfoJsonString);\n\nExample:\n\n\tTuyaSocketManager.getInstance().addDeviceInfo(json);\n\n\n## 3. Device control\n\n    /**\n     * Send control commands\n     * \n     * @param deviceId Device ID\n     * @param commands Control commands\n     * @param resultCallback\n     */\n\tTuyaSocketManager.getInstance().publishCommands(String deviceId, Map\u003cString, Object\u003e commands, ResultCallback resultCallback);\n\n\nExample:\n\n    HashMap\u003cString, Object\u003e commands = new HashMap\u003c\u003e();\n    boolean value = new Random().nextBoolean();\n    commands.put(\"switch_1\", value);\n    TuyaSocketManager.getInstance().publishCommands(\"6ce35593d91e3d9aa2tlo4\", commands, new ResultCallback() {\n        @Override\n        public void onError(int errorCode, String errorMessage) {\n            LogUtils.i(\"publish onError \" + errorMessage);\n        }\n\n        @Override\n        public void onSuccess() {\n            LogUtils.i(\"publish onSuccess \");\n        }\n    });\n\n## 4. Disable connection\n\nWhen your app exits, you can disable all LAN connections:\n\n    // Close all device connections\n    TuyaSocketManager.getInstance().destroy(this);\n\n## Additional information\n\n`dpCodeValue` composition rules:\n\nTo learn more about data point (DP), you can refer to [Update device information](https://developer.tuya.com/en/docs/app-development/android-app-sdk/device-management/devicemanage?id=Ka6ki8r2rfiuu).\n`dpCode` is a DP that describes which functions can be controlled for a device. The schema returned in the `/v1.0/devices/schema` interface will return the DPs supported by a device. The typical DPs are described below.\n`dpCodeDict` is performed in the format `dpCode: dpValue`. `dpCode` can be obtained from the code field in the schema. `dpValue` needs to be sent according to the format supported by the `dp point`.\nThe following will take the demo in the interface document as an example to explain how dpCode is structured.\n\n1. Switch\n\n\t\"type\": \"bool\"\n\n\tFor example, `{\"switch_led\" : true}` or `{\"switch_led\" : true}`\n\t\t\n\t\t{\n\t\t    \"mode\": \"rw\",\n\t\t    \"code\": \"switch_led\",\n\t\t    \"name\": \"Switch \",\n\t\t    \"property\": {\n\t\t        \"type\": \"bool\"\n\t\t    },\n\t\t    \"iconname\": \"icon- dp_power2\",\n\t\t    \"id\": 20,\n\t\t    \"type\": \"obj\",\n\t\t    \"desc\": \"\"\n\t\t}\n\t\t\n2. Mode option (signal choice)\n\t\n\t\"type\": \"enum\"\n\t\n\tFor example, `{\"work_mode\" : \"white\"}` `{\"work_mode\" : \"colour\"} `\n\t\t\n\t\t{\n\t\t    \"mode\": \"rw\",\n\t\t    \"code\": \"work_mode\",\n\t\t    \"name\": \"Mode\",\n\t\t    \"property\": {\n\t\t        \"range\": [\"white\", \"colour\", \"scene\", \"music\"],\n\t\t        \"type\": \"enum\"\n\t\t    },\n\t\t    \"iconname\": \"i con-dp_list\",\n\t\t    \"id\": 21,\n\t\t    \"type\": \"obj\",\n\t\t    \"desc\": \"\"\n\t\t}\n3. Brightness value (send number)\n\t\n\t\"type\": \"value\"\n\t\n\tFor example, `{\"bright_value\": 400}`\n\t\n\tNote: The value has maximum, minimum, and step limit.\n\t\t\n\t\t{\n\t\t    \"mode\": \"rw\",\n\t\t    \"code\": \"bright_value\",\n\t\t    \"name\": \"Brightness\",\n\t\t    \"property\": {\n\t\t        \"min\": 10,\n\t\t        \"max\": 1000,\n\t\t        \"scale\": 0,\n\t\t        \"step\": 1,\n\t\t        \"type\": \"value\"\n\t\t    },\n\t\t    \"iconname \": \"icon-dp_sun\",\n\t\t    \"id\": 22,\n\t\t    \"type\": \"obj\",\n\t\t    \"desc\": \"\"\n\t\t}\n4. Color data (send string)\n\n\t\"type\": \"string\"\n\t\n\tFor example, `{\"colour_data\":\"000100010001\"} `\n\t\n\tThe above method is only one of the transfer methods, and the specific deValue varies by application scenarios \n\t\n\t\t{\n\t\t    \"mode\": \"rw\",\n\t\t    \"code\": \"colour_data\",\n\t\t    \"name\": \"Color\",\n\t\t    \"property\": {\n\t\t        \"type\": \"string\",\n\t\t        \"maxlen\": 255\n\t\t    },\n\t\t    \"iconname\": \"icon- dp_light\",\n\t\t    \"id\": 24,\n\t\t    \"type\": \"obj\",\n\t\t    \"desc\": \"\"\n\t\t}\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuya%2Ftuya-socket-android-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftuya%2Ftuya-socket-android-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuya%2Ftuya-socket-android-sdk/lists"}