Explorar el Código

更新组件初始数据

xiwa hace 2 años
padre
commit
fc7510708e

+ 8 - 0
Dockerfile

@@ -0,0 +1,8 @@
+FROM openjdk:11-jre-slim
+WORKDIR /app
+ADD iot-standalone/target/iot-standalone-0.4.0-SNAPSHOT.tar /app
+ADD data/init /app/data/init
+ADD data/components /app/data/components
+ADD data/converters /app/data/converters
+EXPOSE 8086
+ENTRYPOINT ["java", "-classpath", ".:lib/*","cc.iotkit.Application"]

+ 238 - 0
data/components/3ababc5e-15e9-45a7-8f38-2a6afd45c780/component.js

@@ -0,0 +1,238 @@
+//api配置
+apiTool.config("127.0.0.1",8085,3000);
+
+this.onReceive=function(method,path,header,params,body){
+  //method:post、get、delete...
+  //path:请求路径
+  //header:http请求头数据,结构:{xx:xx,yy:yy}
+  //params:请求参数,结构:{xx:[...],yy:[...]}
+  //body:请求体,当提交的数据为json格式时使用,结构:{xx:xx,yy:yy}
+  apiTool.log("onReceive body:"+body);
+  var duHeader=body.header;
+  var namespace=duHeader.namespace;
+  var requestName=duHeader.name;
+  var messageId=duHeader.messageId;
+  var duPayload=body.payload;
+  var token=duPayload.accessToken;
+  var openUid=duPayload.openUid;
+  
+  //设备发现
+  if(namespace=="DuerOS.ConnectedHome.Discovery" && requestName=="DiscoverAppliancesRequest"){
+	var deviceIds=[];
+	var discoveredDevices=[];
+	var content={
+	  header:{
+		namespace:"DuerOS.ConnectedHome.Discovery",
+		name:"DiscoverAppliancesResponse",
+		messageId:messageId,
+		payloadVersion:1
+	  },
+	  payload:{
+		discoveredAppliances:discoveredDevices,
+		discoveredGroups:[{
+		  groupName:"客厅",
+		  applianceIds:deviceIds,
+		  groupNotes:"客厅分组控制",
+		  additionalGroupDetails:{}
+		}]
+	  }
+	};
+    var rst=apiTool.getSpaceDevices(token);
+	apiTool.log(JSON.stringify(rst));
+	if(rst && rst.status==200 && rst.data){
+	  var devices=rst.data;
+	  for(var i in devices){
+		var device=devices[i];
+		var did=device.deviceId;
+		var pk=device.productKey;
+		var dn=device.deviceName;
+		
+		//更新设备openUid
+		rst=apiTool.setOpenUid(token,did,"dueros",openUid);
+		if(!rst || rst.status!=200){
+		  continue;
+		}
+		
+		//插座
+		if(pk=="cGCrkK7Ex4FESAwe"){
+		  var powerstate=device.property.powerstate;
+		  discoveredDevices.push({
+			actions:["turnOn","turnOff"],
+			applianceTypes:["SOCKET"],
+			additionalApplianceDetails:{},
+			applianceId:device.deviceId,
+			friendlyDescription:"智能插座",
+			friendlyName:device.name,
+			isReachable:device.online,
+			manufacturerName:"海曼",
+			modelName:"S1",
+			version:"v1.0",
+			attributes:[
+			  {
+				name:"客厅的插座",
+				scale:"",
+				timestampOfSample:0,
+				uncertaintyInMilliseconds:10
+			  },
+			  {
+				name:"connectivity",
+				value:"REACHABLE",
+				scale:"",
+				timestampOfSample:0,
+				uncertaintyInMilliseconds:10
+			  },
+			  {
+				name:"turnOnState",
+				value:powerstate==1?"ON":"OFF",
+				scale:"",
+				timestampOfSample:0,
+				uncertaintyInMilliseconds:10,
+				legalValue:"(ON, OFF)"
+			  }
+			]
+		  });
+		}else if(pk=="Rf4QSjbm65X45753"){
+		  //开关
+		  var powerstate=device.property.powerstate;
+		  discoveredDevices.push({
+			actions:["turnOn","turnOff"],
+			applianceTypes:["SWITCH"],
+			additionalApplianceDetails:{},
+			applianceId:device.deviceId,
+			friendlyDescription:"智能开关",
+			friendlyName:device.name,
+			isReachable:device.online,
+			manufacturerName:"海曼",
+			modelName:"S1",
+			version:"v1.0",
+			attributes:[
+			  {
+				name:"客厅的开关",
+				scale:"",
+				timestampOfSample:0,
+				uncertaintyInMilliseconds:10
+			  },
+			  {
+				name:"connectivity",
+				value:"REACHABLE",
+				scale:"",
+				timestampOfSample:0,
+				uncertaintyInMilliseconds:10
+			  },
+			  {
+				name:"turnOnState",
+				value:powerstate==1?"ON":"OFF",
+				scale:"",
+				timestampOfSample:0,
+				uncertaintyInMilliseconds:10,
+				legalValue:"(ON, OFF)"
+			  }
+			]
+		  });
+		  
+		}
+	  }
+	}
+	
+	return {
+	  url:"",//不指定直接作为响应返回
+	  header:{
+		contentType:"application/json"
+	  },
+	  content:JSON.stringify(content)
+	}
+  }else if(namespace=="DuerOS.ConnectedHome.Control"){
+	//设备控制
+  	var appliance=duPayload.appliance;
+	var deviceId=appliance.applianceId;
+	var confirmName="UnsupportedOperationError";
+	var rst={status:500};
+	
+	//开关
+	if(requestName=="TurnOnRequest"){
+		//开
+		confirmName="TurnOnConfirmation";
+		rst=apiTool.setProperties(token,deviceId,{powerstate:1});
+	}else if(requestName=="TurnOffRequest"){
+		//关
+	  	confirmName="TurnOffConfirmation";
+		rst=apiTool.setProperties(token,deviceId,{powerstate:0});
+	}
+	
+	if(rst.status!=200){
+	  confirmName="UnsupportedOperationError";
+	  apiTool.log("device control failed:"+JSON.stringify(rst));
+	}
+	
+	var content={
+	  header: {
+		namespace: "DuerOS.ConnectedHome.Control",
+		name: confirmName,
+		messageId: messageId,
+		payloadVersion: "1"
+	  },
+	  payload: {
+		"attributes": []
+	  }
+	};
+	
+	return {
+	  url:"",
+	  header:{
+		contentType:"application/json"
+	  },
+	  content:JSON.stringify(content)
+	}
+  }else if(namespace=="DuerOS.ConnectedHome.Query"){
+	//属性查询
+	if(requestName=="ReportStateRequest"){
+	  var appliance=duPayload.appliance;
+	  var deviceId=appliance.applianceId;
+	  var property=appliance.attributeName;
+	  var propertyVal="";
+	  var success=false;
+	  if(property=="turnOnState"){
+		//开关状态查询
+		var rst= apiTool.getSpaceDeviceDetail(token,deviceId);
+		if(rst && rst.status==200 && rst.data.property){
+		  propertyVal=rst.data.property.powerstate==1?"ON":"OFF";
+		  success=true;
+		}
+	  }
+	  var content=success?{
+		"header": {
+		  "namespace": "DuerOS.ConnectedHome.Query",
+		  "name": "ReportStateResponse",
+		  "messageId": new Date().getTime()+"",
+		  "payloadVersion": "1"
+		},
+		"payload": {
+		  "attributes": [
+			{
+			  "name": property,
+			  "value": propertyVal,
+			  "scale": "",
+			  "timestampOfSample": new Date().getTime()/1000,
+			  "uncertaintyInMilliseconds": 0
+			}
+		  ]
+		}
+	  }:{};
+	  
+	  return {
+		url:"",
+		header:{
+		  contentType:"application/json"
+		},
+		content:JSON.stringify(content)
+	  }
+	}
+  }
+  return {
+	  url:"",//不指定直接作为响应返回
+	  header:{
+		contentType:"application/json"
+	  },
+	  content:""
+	}
+}

BIN
data/components/3ababc5e-15e9-45a7-8f38-2a6afd45c780/iot-http-biz-component-0.4.0-SNAPSHOT.jar


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
data/components/6c095554-35e7-4e9d-a8d2-bb919e9479f4/component.js


BIN
data/components/6c095554-35e7-4e9d-a8d2-bb919e9479f4/iot-emqx-component-0.4.0-SNAPSHOT.jar


BIN
data/components/eabb131d-8fd1-43a8-88d9-a198abfd3d42/iot-mqtt-component-0.3.1-SNAPSHOT.jar → data/components/eabb131d-8fd1-43a8-88d9-a198abfd3d42/iot-mqtt-component-0.4.0-SNAPSHOT.jar


+ 3 - 27
data/init/protocolComponent.json

@@ -1,47 +1,23 @@
 [
-  {
-    "id": "fee0e826-963f-4e53-a2cf-11e3e5f784ea",
-    "uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
-    "name": "移动Onenet Studio接入",
-    "type": "biz",
-    "protocol": "http",
-    "jarFile": "http-biz-component-0.1.0-SNAPSHOT.jar",
-    "config": "{\"port\":\"8086\"}",
-    "converter": "6260396d67aced2696184053",
-    "state": "stopped",
-    "createAt": 1652238780184
-  },
   {
     "id": "eabb131d-8fd1-43a8-88d9-a198abfd3d42",
     "uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
     "name": "MQTT标准协议组件",
     "type": "device",
     "protocol": "mqtt",
-    "jarFile": "iot-mqtt-component-0.3.1-SNAPSHOT.jar",
+    "jarFile": "iot-mqtt-component-0.4.0-SNAPSHOT.jar",
     "config": "{\"port\":1883,\"ssl\":false,\"type\":\"server\"}",
     "converter": "6260396d67aced2696184053",
     "state": "running",
     "createAt": 1650473458084
   },
-  {
-    "id": "cd8253c1-b489-434c-845d-d18c7b70dcea",
-    "uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
-    "name": "电信NB协议接入组件",
-    "type": "device",
-    "protocol": "http",
-    "jarFile": "ctwing-component-0.2.1-SNAPSHOT.jar",
-    "config": "{\"port\":\"8087\"}",
-    "converter": "62995ba4dbf51a5ec41d5f7b",
-    "state": "stopped",
-    "createAt": 1654235056032
-  },
   {
     "id": "6c095554-35e7-4e9d-a8d2-bb919e9479f4",
     "uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
     "name": "EMQX标准协议组件",
     "type": "device",
     "protocol": "mqtt",
-    "jarFile": "emqx-component-0.2.1-SNAPSHOT.jar",
+    "jarFile": "emqx-component-0.4.0-SNAPSHOT.jar",
     "config": "{\"port\":\"1884\",\"ssl\":false,\"type\":\"client\",\"subscribeTopics\":[\"/sys/+/+/s/#\",\"/sys/client/connected\",\"/sys/client/disconnected\",\"/sys/session/subscribed\",\"/sys/session/unsubscribed\"],\"authPort\":\"8088\",\"broker\":\"127.0.0.1\",\"clientId\":\"test\",\"username\":\"test\",\"password\":\"123\"}",
     "converter": "6260396d67aced2696184053",
     "state": "stopped",
@@ -53,7 +29,7 @@
     "name": "小度音箱接入组件",
     "type": "biz",
     "protocol": "http",
-    "jarFile": "http-biz-component-0.1.0-SNAPSHOT.jar",
+    "jarFile": "http-biz-component-0.4.0-SNAPSHOT.jar",
     "config": "{\"port\":\"8084\"}",
     "converter": "",
     "state": "stopped",

+ 17 - 0
docker-compose.yml

@@ -0,0 +1,17 @@
+version: '3.3'
+services:
+  ui:
+    image: uncleregan/iotkit-ui:0.3.4
+    container_name: iotkit-ce-ui
+    ports:
+      - 80:80
+    links:
+      - iotkit:iotkit
+  iotkit:
+    image: iotkits/iotkit:0.4.0
+    container_name: iotkit-cei
+    restart: on-failure
+    ports:
+      - 8086:8086 # API端口
+      - 1883-1890:1883-1890 # 预留
+      - 8000-8010:8000-8010 # 预留

+ 8 - 0
iot-components/iot-emqx-component/dependency-reduced-pom.xml

@@ -50,6 +50,8 @@
         <configuration>
           <source>11</source>
           <target>11</target>
+          <forceJavacCompilerUse>true</forceJavacCompilerUse>
+          <useIncrementalCompilation>false</useIncrementalCompilation>
         </configuration>
       </plugin>
     </plugins>
@@ -97,5 +99,11 @@
       <version>0.4.0-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
+    <dependency>
+      <groupId>cc.iotkit</groupId>
+      <artifactId>iot-data-service</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+      <scope>compile</scope>
+    </dependency>
   </dependencies>
 </project>

+ 1 - 1
iot-components/iot-http-biz-component/dependency-reduced-pom.xml

@@ -46,7 +46,7 @@
     <dependency>
       <groupId>org.projectlombok</groupId>
       <artifactId>lombok</artifactId>
-      <version>1.18.22</version>
+      <version>1.18.24</version>
       <scope>compile</scope>
     </dependency>
     <dependency>

+ 101 - 0
iot-components/iot-mqtt-component/dependency-reduced-pom.xml

@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <artifactId>iot-components</artifactId>
+    <groupId>cc.iotkit</groupId>
+    <version>0.4.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>iot-mqtt-component</artifactId>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-shade-plugin</artifactId>
+        <version>3.2.4</version>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <artifactSet>
+            <includes>
+              <include>io.vertx:vertx-core</include>
+              <include>io.vertx:vertx-mqtt</include>
+              <include>io.netty:netty-codec-mqtt</include>
+              <include>org.luaj:luaj-jse</include>
+            </includes>
+          </artifactSet>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>11</source>
+          <target>11</target>
+          <forceJavacCompilerUse>true</forceJavacCompilerUse>
+          <useIncrementalCompilation>false</useIncrementalCompilation>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+    <dependency>
+      <groupId>io.vertx</groupId>
+      <artifactId>vertx-core</artifactId>
+      <version>4.2.2</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>io.vertx</groupId>
+      <artifactId>vertx-mqtt</artifactId>
+      <version>4.2.2</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>io.netty</groupId>
+      <artifactId>netty-codec-mqtt</artifactId>
+      <version>4.1.72.Final</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.projectlombok</groupId>
+      <artifactId>lombok</artifactId>
+      <version>1.18.24</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.7.32</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.luaj</groupId>
+      <artifactId>luaj-jse</artifactId>
+      <version>3.0.1</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>cc.iotkit</groupId>
+      <artifactId>iot-common</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>cc.iotkit</groupId>
+      <artifactId>iot-component-base</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>cc.iotkit</groupId>
+      <artifactId>iot-data-service</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+      <scope>compile</scope>
+    </dependency>
+  </dependencies>
+</project>

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio