fix event

This commit is contained in:
anlicheng 2023-09-07 15:35:42 +08:00
parent 0d30cd471e
commit 2465fa5bab
2 changed files with 71 additions and 0 deletions

View File

@ -412,6 +412,19 @@ handle_cast({handle, {event, Event0}}, State = #state{uuid = UUID, aes = AES, ha
lager:debug("[iot_host] uuid: ~p, get event: ~p", [UUID, EventText]),
case catch jiffy:decode(EventText, [return_maps]) of
#{<<"event_type">> := ?EVENT_DEVICE, <<"params">> := #{<<"device_uuid">> := DeviceUUID, <<"status">> := Status}} ->
%%
Timestamp = iot_util:timestamp_of_seconds(),
FieldsList = [#{
<<"key">> => <<"device_status">>,
<<"value">> => Status,
<<"unit">> => <<"">>,
<<"type">> => <<"SOE">>,
<<"name">> => <<"设备状态"/utf8>>,
<<"timestamp">> => Timestamp
}],
iot_router:route(DeviceUUID, FieldsList, Timestamp),
lager:debug("[iot_host] uuid: ~p, route fields: ~p", [UUID, FieldsList]),
DevicePid = iot_device:get_pid(DeviceUUID),
iot_device:change_status(DevicePid, Status);
Event when is_map(Event) ->

58
docs/zhongdian_mqtt.md Normal file
View File

@ -0,0 +1,58 @@
# 中电mqtt通讯规约
## 服务器地址
MQTT服务器IP172.30.6.161
MQTT服务器端口1883
MQTT服务器账号admin
MQTT服务器密码public
## topic
南向:
MQTT ClientID: CET/NX
发布Topic:CET/NX/upload
订阅Topic:CET/NX/downlod
中电:
MQTT ClientID:CET/NX
订阅Topic:CET/NX/upload
发布Topic:CET/NX/download
## 数据格式
```text
{
"version": "1.0",
"location_code": "string",
"ts ": 1688606685,
"properties": [
{
"type": "AI",
"key": "A相电流",
"value": 0.25,
"unit": "A",
"timestamp": 1688354258
},
{
"type": "AI",
"key": "A相电压",
"value": 220.5,
"unit": "V",
"timestamp": 1688354258
},
{
"type": "SOE",
"key": "电压越限",
"value": 1,
"unit": "V",
"timestamp": 1688354258
}
]
}
南向上送数据
CET应答
{
"location_code": string, //(点位编码信息),
"ts ":1688606685 ,
"result":1(int)
}
```