Explorar el Código

添加模拟消息发送

xiwa hace 3 años
padre
commit
a3adfcf5c9

+ 17 - 0
manager/src/main/java/cc/iotkit/manager/controller/DeviceController.java

@@ -2,6 +2,8 @@ package cc.iotkit.manager.controller;
 
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.DeviceUtil;
+import cc.iotkit.common.utils.UniqueIdUtil;
+import cc.iotkit.comps.service.DeviceBehaviourService;
 import cc.iotkit.dao.*;
 import cc.iotkit.manager.service.DataOwnerService;
 import cc.iotkit.manager.service.DeviceService;
@@ -47,6 +49,8 @@ public class DeviceController {
     @Lazy
     @Autowired
     private DevicePropertyDao devicePropertyDao;
+    @Autowired
+    private DeviceBehaviourService behaviourService;
 
     @PostMapping("/{deviceId}/service/{service}")
     public String invokeService(@PathVariable("deviceId") String deviceId,
@@ -175,4 +179,17 @@ public class DeviceController {
         dataOwnerService.checkOwner(device);
         deviceDao.updateTag(deviceId, tag);
     }
+
+    @PostMapping("/{deviceId}/simulateSend")
+    public void simulateSend(
+            @PathVariable("deviceId") String deviceId,
+            @RequestBody ThingModelMessage message) {
+        DeviceInfo device = deviceRepository.findByDeviceId(deviceId);
+        dataOwnerService.checkOwner(device);
+
+        message.setMid(UniqueIdUtil.newRequestId());
+        message.setOccurred(System.currentTimeMillis());
+        message.setTime(System.currentTimeMillis());
+        behaviourService.reportMessage(message);
+    }
 }

+ 3 - 2
protocol-gateway/mqtt-client-simulator/src/main/java/cc/iotkit/simulator/Application.java

@@ -11,8 +11,8 @@ public class Application {
     public static void main(String[] args) throws IOException {
 
         if (args.length == 0) {
-            Mqtt.broker = "tcp://127.0.0.1:1883";
-//            Mqtt.broker = "tcp://120.76.96.206:1883";
+//            Mqtt.broker = "tcp://127.0.0.1:1883";
+            Mqtt.broker = "tcp://120.76.96.206:1883";
         } else {
             Mqtt.broker = args[0];
         }
@@ -29,6 +29,7 @@ public class Application {
             //插座
             gateway2.addSubDevice("cGCrkK7Ex4FESAwe", "ABE12300001", "S1");
             gateway2.addSubDevice("cGCrkK7Ex4FESAwe", "ABE12300002", "S1");
+            gateway2.addSubDevice("6kYp6jszrDns2yh4", "ABE12400001", "S1");
             gateway2.start();
         }).start();
 

+ 4 - 4
rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceCondition.java

@@ -47,14 +47,14 @@ public class DeviceCondition {
             if ("*".equals(identifier)) {
                 return true;
             }
-            Object left = parameter.get(identifier);
-            if (left == null) {
-                return false;
-            }
             //任意匹配
             if ("*".equals(comparator)) {
                 return true;
             }
+            Object left = parameter.get(identifier);
+            if (left == null) {
+                return false;
+            }
             return Expression.eval(comparator, left, value);
         }
     }