Selaa lähdekoodia

删除多余文件,修复init数据

tangfudong 2 vuotta sitten
vanhempi
commit
17d3bf586e

+ 85 - 47
data/components/2c089bb8-0412-449e-94f1-212d35a50219/component.js

@@ -1,7 +1,5 @@
 var mid=1;
 
-var access_token="";
-
 function getMid(){
 	mid++;
 	if(mid>10000){
@@ -9,58 +7,94 @@ function getMid(){
 	}
 	return mid;
 };
-function getPingData(data){
-	var ping={
-		productKey:"",
-		deviceName:"",
-		content:{
-			id:getMid(),
-			type:data
-		}
+function getPkDn(deviceKey){
+	var arr=deviceKey.split("_");
+	return {
+		pk:arr[1],
+		dn:deviceKey
 	};
+}
+function register(data){
+	var device=getPkDn(data.data.deviceName)
+	var subDevicesList=data.data.subDevices
+	var subDevices=[]
+	if(subDevicesList!=undefined&&subDevicesList.length>0){
+		apiTool.log("device:"+subDevicesList);
+		for (var i = 0; i < subDevicesList.length; i++) {
+			var deviceKey=subDevicesList[i]
+			var subDevice=getPkDn(deviceKey)
+			subDevices.push({
+				productKey:subDevice.pk,
+				deviceName:subDevice.dn,
+				model:''
+			})
+		}
+	}
+
+	var reply=
+		{
+			productKey:device.pk,
+			deviceName:device.dn,
+			mid:"0",
+			content:{
+				id:data.id,
+				type:data.type,
+				result:'success'
+			}
+		};
+	var data={
+		productKey:device.pk,
+		deviceName:device.dn
+	}
+	if(subDevices.length>0){
+		data['subDevices']=subDevices
+	}
+	apiTool.log("subDevices:"+JSON.stringify(data));
 	return {
-		type:"action",
-		data:{
-			productKey:"",
-			deviceName:"",
-			state:""
-		},
+		type:"register",
+		data:data,
 		action:{
 			type:"ack",
-			content:JSON.stringify(ping)
+			content:JSON.stringify(reply)
 		}
-	}
-};
+	};
+}
+
+function online(data){
+	apiTool.log("data:"+JSON.stringify(data));
+	var device=getPkDn(data.data.deviceName)
+	return {
+		type:"state",
+		data:{
+			productKey:device.pk,
+			deviceName:device.dn,
+			state:data.type
+		}
+	};
+}
+
+function offline(data){
+	var device=getPkDn(data.deviceKey)
+	return {
+		type:"state",
+		data:{
+			productKey:device.pk,
+			deviceName:device.dn,
+			state:data.type
+		}
+	};
+}
+
 //必须提供onReceive方法
 this.onReceive=function(head,type,payload){
 	var data=JSON.parse(payload)
-	if(data.type=="auth_required"){
-		var auth={
-			productKey:"",
-			deviceName:"",
-			content:{
-				type:"auth",
-				access_token:access_token
-			}
-		};
-		return {
-			type:"action",
-			data:{
-				productKey:"",
-				deviceName:"",
-				state:""
-			},
-			action:{
-				type:"ack",
-				content:JSON.stringify(auth)
-			}
-		}
-	}else if(data.type=="auth_ok"){
-		return getPingData(data.heartBeatData);
-	}else if(data.type=="pong"){
-		apiTool.log("receive pong!");
-	}else if("ping"==type){
-		return getPingData(data.heartBeatData);
+	if(data.type=="register"){
+		apiTool.log("data:"+payload);
+		return register(data)
+	}else if(data.type=="online"){
+		return online(data);
+	}else if(data.type=="offline"){
+		return offline(data);
 	}
 	return {
 		productKey:"",
@@ -69,4 +103,8 @@ this.onReceive=function(head,type,payload){
 		content:{
 		}
 	}
-};
+};
+
+this.onRegistered=function (data,status) {
+	apiTool.log("onRegistered调用");
+}

BIN
data/components/2c089bb8-0412-449e-94f1-212d35a50219/iot-websocket-component-0.4.3-SNAPSHOT.jar


+ 1 - 1
data/components/305a8b86-4566-4f2a-a57f-f84ca47471a1/component.js

@@ -1,7 +1,7 @@
 var mid=1;
 
 var gatewayPk="BRD3x4fkKxkaxXFt"
-var smartMeterPk="PjmkANSTDt85bZPj"
+var smartMeterPk="PwMfpXmp4ZWkGahn"
 
 function getMid(){
 	mid++;

+ 0 - 74
data/components/fee0e826-963f-4e53-a2cf-11e3e5f784ea/component.js

@@ -1,74 +0,0 @@
-var pidPkMap={
-  "H5Z31yKBmy":"3ptfx2dRescPAwTn",
-  "xOCy76jn6k":"jzC6eQGRse6hDZPB"
-}
-
-this.onReceive=function(method,path,header,params,body){
-  var type=header["Content-Type"];
-  if(type=="application/json"){
-	var msg=JSON.parse(body.msg);
-	var productId=msg.productId;
-	var deviceName=msg.deviceName;
-	var messageType=msg.messageType;
-	var data=msg.data;
-	var pk=pidPkMap[productId];
-	if(!pk){
-	  return {
-		url:"",
-		header:{
-		  contentType:"application/json"
-		},
-		content:"error"
-	  }
-	}
-
-	if(messageType=="lifeCycle"){
-	  //登录、登出
-	  var online=data.status=="online";
-	  deviceBehaviour.deviceStateChange(pk,deviceName,online);
-	}else if(messageType=="notify"){
-	  //设备消息
-	  //消息类型
-	  var notifyType=msg.notifyType;
-	  if(notifyType=="property"){
-		//属性上报
-		var propertyData={};
-		for(var p in data.params){
-		  propertyData[p]=data.params[p].value;
-		}
-		deviceBehaviour.reportMessage(JSON.stringify({
-		  mid:data.id,
-		  productKey:pk,
-		  deviceName:deviceName,
-		  type:"property",
-		  identifier:"report",
-		  data:propertyData
-		}));
-	  }else if(notifyType=="event"){
-		//事件上报
-		var identifier="";
-		var paramData={};
-		for(var p in data.params){
-		  identifier=p;
-		  paramData=data.params[p];
-		}
-
-		deviceBehaviour.reportMessage(JSON.stringify({
-		  mid:data.id,
-		  productKey:pk,
-		  deviceName:deviceName,
-		  type:"event",
-		  identifier:identifier,
-		  data:paramData.value
-		}));
-	  }
-	}
-  }
-  return {
-	url:"",
-	header:{
-	  contentType:"application/json"
-	},
-	content:JSON.stringify(params.msg)
-  }
-};

BIN
data/components/fee0e826-963f-4e53-a2cf-11e3e5f784ea/iot-http-biz-component-0.4.3-SNAPSHOT.jar


+ 5 - 0
data/init/category.json

@@ -43,5 +43,10 @@
     "id": "FreshAir",
     "name": "新风",
     "createAt": 1681444312184
+  },
+  {
+    "id": "SmartMeter",
+    "name": "智能电表",
+    "createAt": 1681444312184
   }
 ]

+ 4 - 4
data/init/thingModel.json

@@ -984,8 +984,8 @@
     }
   },
   {
-    "id": "a5fnnx3ksu7n2n0f",
-    "productKey": "a5fnnx3ksu7n2n0f",
+    "id": "bGdZt8ffBETtsirm",
+    "productKey": "bGdZt8ffBETtsirm",
     "model": {
       "properties": [
         {
@@ -1115,8 +1115,8 @@
     }
   },
   {
-    "id": "PjmkANSTDt85bZPj",
-    "productKey": "PjmkANSTDt85bZPj",
+    "id": "PwMfpXmp4ZWkGahn",
+    "productKey": "PwMfpXmp4ZWkGahn",
     "model": {
       "properties": [
         {