合并
This commit is contained in:
commit
b22d115273
@ -17,6 +17,11 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tuya</groupId>
|
<groupId>com.tuya</groupId>
|
||||||
<artifactId>tuya-spring-boot-starter</artifactId>
|
<artifactId>tuya-spring-boot-starter</artifactId>
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.qiuguo.iot.user.api.controller.device;
|
package com.qiuguo.iot.user.api.controller.device;
|
||||||
|
|
||||||
import cn.hutool.crypto.digest.MD5;
|
import cn.hutool.crypto.digest.MD5;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.qiuguo.iot.base.enums.DeviceTypeEnum;
|
import com.qiuguo.iot.base.enums.DeviceTypeEnum;
|
||||||
import com.qiuguo.iot.base.utils.StringUtils;
|
import com.qiuguo.iot.base.utils.StringUtils;
|
||||||
import com.qiuguo.iot.data.entity.device.DeviceInfoEntity;
|
import com.qiuguo.iot.data.entity.device.DeviceInfoEntity;
|
||||||
@ -35,7 +36,7 @@ public class DeviceController {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private DeviceBatchService deviceBatchService;
|
private DeviceBatchService deviceBatchService;
|
||||||
|
|
||||||
|
|
||||||
@Value("${device.timeout}")
|
@Value("${device.timeout}")
|
||||||
private Long timeOut;//2分钟
|
private Long timeOut;//2分钟
|
||||||
|
|||||||
@ -1,13 +1,15 @@
|
|||||||
package com.qiuguo.iot.user.api.service;
|
package com.qiuguo.iot.user.api.service;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
import com.tuya.connector.api.annotations.Body;
|
import com.tuya.connector.api.annotations.Body;
|
||||||
import com.tuya.connector.api.annotations.DELETE;
|
import com.tuya.connector.api.annotations.DELETE;
|
||||||
import com.tuya.connector.api.annotations.GET;
|
import com.tuya.connector.api.annotations.GET;
|
||||||
import com.tuya.connector.api.annotations.POST;
|
import com.tuya.connector.api.annotations.POST;
|
||||||
import com.tuya.connector.api.annotations.PUT;
|
import com.tuya.connector.api.annotations.PUT;
|
||||||
import com.tuya.connector.api.annotations.Path;
|
import com.tuya.connector.api.annotations.Path;
|
||||||
import java.util.Map;
|
import com.tuya.connector.api.annotations.Query;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XXX
|
* XXX
|
||||||
@ -23,19 +25,19 @@ public interface TuyaDeviceConnector {
|
|||||||
|
|
||||||
// 查询空间下设备列表
|
// 查询空间下设备列表
|
||||||
@GET("/v2.0/cloud/thing/space/device")
|
@GET("/v2.0/cloud/thing/space/device")
|
||||||
JSONObject getDevicesBySpaceIds(String spaces);
|
JsonArray getDevicesBySpaceIds(@Query("space_ids") String spaces,@Query("page_size") Integer size);
|
||||||
|
|
||||||
// 控制设备动作
|
// 控制设备动作
|
||||||
@POST("/v2.0/cloud/thing/{device_id}/shadow/actions")
|
@POST("/v1.0/iot-03/devices/{device_id}/commands")
|
||||||
JSONObject controlDevice(@Path("device_id") String deviceId, @Body JSONObject commands);
|
Object controlDevice(@Path("device_id") String deviceId, @Body JSONObject commands);
|
||||||
|
|
||||||
// 创建空间
|
// 创建空间
|
||||||
@POST("/v2.0/cloud/space/creation")
|
@POST("/v2.0/cloud/space/creation")
|
||||||
JSONObject creatSpace(@Body JSONObject jsonObject);
|
Long creatSpace(@Body JSONObject jsonObject);
|
||||||
|
|
||||||
// 删除空间
|
// 删除空间
|
||||||
@DELETE("/v2.0/cloud/space/{space_id}")
|
@DELETE("/v2.0/cloud/space/{space_id}")
|
||||||
JSONObject deleteSpace(@Path("space_id") String spaceId);
|
Boolean deleteSpace(@Path("space_id") String spaceId);
|
||||||
|
|
||||||
// 查询空间
|
// 查询空间
|
||||||
@GET("/v2.0/cloud/space/{space_id}")
|
@GET("/v2.0/cloud/space/{space_id}")
|
||||||
@ -43,6 +45,10 @@ public interface TuyaDeviceConnector {
|
|||||||
|
|
||||||
// 修改空间信息
|
// 修改空间信息
|
||||||
@PUT("/v2.0/cloud/space/{space_id}")
|
@PUT("/v2.0/cloud/space/{space_id}")
|
||||||
JSONObject updateSpace(@Path("space_id") String spaceId, @Body JSONObject JSONObject);
|
Boolean updateSpace(@Path("space_id") String spaceId, @Body JSONObject JSONObject);
|
||||||
|
|
||||||
|
// 获取设备支持的指令集
|
||||||
|
@GET("/v1.0/iot-03/devices/{device_id}/functions")
|
||||||
|
Object getFunctions(@Path("device_id") String deviceId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.qiuguo.iot.user.api.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XXX
|
||||||
|
*
|
||||||
|
* @author weiyachao
|
||||||
|
* @since 2023/9/19 15:13
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class TuyaDeviceService {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,4 +1,13 @@
|
|||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.qiuguo.iot.user.api.IotBoxUserApiApplication;
|
||||||
|
import com.qiuguo.iot.user.api.service.TuyaDeviceConnector;
|
||||||
import com.tuya.connector.api.annotations.Path;
|
import com.tuya.connector.api.annotations.Path;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XXX
|
* XXX
|
||||||
@ -6,11 +15,83 @@ import com.tuya.connector.api.annotations.Path;
|
|||||||
* @author weiyachao
|
* @author weiyachao
|
||||||
* @since 2023/9/5 16:03
|
* @since 2023/9/5 16:03
|
||||||
*/
|
*/
|
||||||
|
@SpringBootTest(classes = IotBoxUserApiApplication.class)
|
||||||
|
@Slf4j
|
||||||
public class UserTest {
|
public class UserTest {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public String deviceId = "6c4a153095be2b7f8baofp";
|
||||||
|
|
||||||
|
public String spaceId = "163257138";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TuyaDeviceConnector tuyaDeviceConnector;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void 获取设备支持的指令集() {
|
||||||
|
Object functions = tuyaDeviceConnector.getFunctions(deviceId);
|
||||||
|
System.out.println(functions);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void 修改空间() {
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("name", "testname");
|
||||||
|
Boolean jsonObject1 = tuyaDeviceConnector.updateSpace(spaceId, jsonObject);
|
||||||
|
System.out.println(jsonObject1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void 查询空间() {
|
||||||
|
//40001900
|
||||||
|
JSONObject spaceInfo = tuyaDeviceConnector.getSpaceInfo("163258893");
|
||||||
|
System.out.println(spaceInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void 删除空间() {
|
||||||
|
//40001900
|
||||||
|
Boolean jsonObject = tuyaDeviceConnector.deleteSpace("163258893");
|
||||||
|
System.out.println(jsonObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void 创建空间() {
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("name", "space1_2");
|
||||||
|
jsonObject.put("description", "space1_2的空间描述");
|
||||||
|
Long jsonObject1 = tuyaDeviceConnector.creatSpace(jsonObject);
|
||||||
|
System.out.println(jsonObject1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void 控制设备动作() {
|
||||||
|
JSONObject commands = new JSONObject();
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("code", "switch_led");
|
||||||
|
jsonObject.put("value", true);
|
||||||
|
JSONObject js2 = new JSONObject();
|
||||||
|
js2.put("code", "work_mode");
|
||||||
|
js2.put("value", "colour");
|
||||||
|
JSONObject js3 = new JSONObject();
|
||||||
|
js3.put("code", "bright_value_v2");
|
||||||
|
js3.put("value", 10);
|
||||||
|
commands.put("commands", Arrays.asList( js3));
|
||||||
|
|
||||||
|
Object controlDevice = tuyaDeviceConnector.controlDevice(deviceId,commands);
|
||||||
|
System.out.println(controlDevice);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void 查询空间下设备列表() {
|
||||||
|
JsonArray devicesBySpaceIds = tuyaDeviceConnector.getDevicesBySpaceIds(spaceId, 20);
|
||||||
|
System.out.println(devicesBySpaceIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void 查询设备信息() {
|
||||||
|
JSONObject byid = tuyaDeviceConnector.getByid(deviceId);
|
||||||
|
System.out.println(byid);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -385,3 +385,5 @@ Caused by: java.util.concurrent.TimeoutException: null
|
|||||||
2023-11:39:27.537 [reactor-tcp-nio-2] DEBUG o.h.e.r.e.r.r.R2dbcReactiveSqlExecutor - [lambda$null$9,146] []- ==> Updated: 1
|
2023-11:39:27.537 [reactor-tcp-nio-2] DEBUG o.h.e.r.e.r.r.R2dbcReactiveSqlExecutor - [lambda$null$9,146] []- ==> Updated: 1
|
||||||
2023-11:41:50.880 [reactor-http-nio-4] WARN r.n.h.s.HttpServerOperations - [warn,299] []- [a269f4cd, L:/127.0.0.1:8091 - R:/127.0.0.1:63946] Decoding failed: FULL_REQUEST(decodeResult: failure(java.lang.IllegalArgumentException: text is empty (possibly HTTP/0.9)), version: HTTP/1.0, content: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 0, cap: 0))
|
2023-11:41:50.880 [reactor-http-nio-4] WARN r.n.h.s.HttpServerOperations - [warn,299] []- [a269f4cd, L:/127.0.0.1:8091 - R:/127.0.0.1:63946] Decoding failed: FULL_REQUEST(decodeResult: failure(java.lang.IllegalArgumentException: text is empty (possibly HTTP/0.9)), version: HTTP/1.0, content: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 0, cap: 0))
|
||||||
GET /bad-request HTTP/1.0
|
GET /bad-request HTTP/1.0
|
||||||
|
2023-13:09:09.449 [reactor-http-nio-13] WARN r.n.h.s.HttpServerOperations - [warn,299] []- [4cc312c1, L:/192.168.8.175:8091 - R:/192.168.8.246:52336] Decoding failed: FULL_REQUEST(decodeResult: failure(java.lang.IllegalArgumentException: text is empty (possibly HTTP/0.9)), version: HTTP/1.0, content: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 0, cap: 0))
|
||||||
|
GET /bad-request HTTP/1.0
|
||||||
|
|||||||
@ -385,3 +385,5 @@ Caused by: java.util.concurrent.TimeoutException: null
|
|||||||
2023-11:39:27.537 [reactor-tcp-nio-2] DEBUG o.h.e.r.e.r.r.R2dbcReactiveSqlExecutor - [lambda$null$9,146] []- ==> Updated: 1
|
2023-11:39:27.537 [reactor-tcp-nio-2] DEBUG o.h.e.r.e.r.r.R2dbcReactiveSqlExecutor - [lambda$null$9,146] []- ==> Updated: 1
|
||||||
2023-11:41:50.880 [reactor-http-nio-4] WARN r.n.h.s.HttpServerOperations - [warn,299] []- [a269f4cd, L:/127.0.0.1:8091 - R:/127.0.0.1:63946] Decoding failed: FULL_REQUEST(decodeResult: failure(java.lang.IllegalArgumentException: text is empty (possibly HTTP/0.9)), version: HTTP/1.0, content: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 0, cap: 0))
|
2023-11:41:50.880 [reactor-http-nio-4] WARN r.n.h.s.HttpServerOperations - [warn,299] []- [a269f4cd, L:/127.0.0.1:8091 - R:/127.0.0.1:63946] Decoding failed: FULL_REQUEST(decodeResult: failure(java.lang.IllegalArgumentException: text is empty (possibly HTTP/0.9)), version: HTTP/1.0, content: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 0, cap: 0))
|
||||||
GET /bad-request HTTP/1.0
|
GET /bad-request HTTP/1.0
|
||||||
|
2023-13:09:09.449 [reactor-http-nio-13] WARN r.n.h.s.HttpServerOperations - [warn,299] []- [4cc312c1, L:/192.168.8.175:8091 - R:/192.168.8.246:52336] Decoding failed: FULL_REQUEST(decodeResult: failure(java.lang.IllegalArgumentException: text is empty (possibly HTTP/0.9)), version: HTTP/1.0, content: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 0, cap: 0))
|
||||||
|
GET /bad-request HTTP/1.0
|
||||||
|
|||||||
@ -385,3 +385,5 @@ Caused by: java.util.concurrent.TimeoutException: null
|
|||||||
2023-11:39:27.537 [reactor-tcp-nio-2] DEBUG o.h.e.r.e.r.r.R2dbcReactiveSqlExecutor - [lambda$null$9,146] []- ==> Updated: 1
|
2023-11:39:27.537 [reactor-tcp-nio-2] DEBUG o.h.e.r.e.r.r.R2dbcReactiveSqlExecutor - [lambda$null$9,146] []- ==> Updated: 1
|
||||||
2023-11:41:50.880 [reactor-http-nio-4] WARN r.n.h.s.HttpServerOperations - [warn,299] []- [a269f4cd, L:/127.0.0.1:8091 - R:/127.0.0.1:63946] Decoding failed: FULL_REQUEST(decodeResult: failure(java.lang.IllegalArgumentException: text is empty (possibly HTTP/0.9)), version: HTTP/1.0, content: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 0, cap: 0))
|
2023-11:41:50.880 [reactor-http-nio-4] WARN r.n.h.s.HttpServerOperations - [warn,299] []- [a269f4cd, L:/127.0.0.1:8091 - R:/127.0.0.1:63946] Decoding failed: FULL_REQUEST(decodeResult: failure(java.lang.IllegalArgumentException: text is empty (possibly HTTP/0.9)), version: HTTP/1.0, content: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 0, cap: 0))
|
||||||
GET /bad-request HTTP/1.0
|
GET /bad-request HTTP/1.0
|
||||||
|
2023-13:09:09.449 [reactor-http-nio-13] WARN r.n.h.s.HttpServerOperations - [warn,299] []- [4cc312c1, L:/192.168.8.175:8091 - R:/192.168.8.246:52336] Decoding failed: FULL_REQUEST(decodeResult: failure(java.lang.IllegalArgumentException: text is empty (possibly HTTP/0.9)), version: HTTP/1.0, content: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 0, cap: 0))
|
||||||
|
GET /bad-request HTTP/1.0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user