From 2465fa5babf27f23a11f61e6de0c4fe386c738c6 Mon Sep 17 00:00:00 2001 From: anlicheng Date: Thu, 7 Sep 2023 15:35:42 +0800 Subject: [PATCH] fix event --- apps/iot/src/iot_host.erl | 13 +++++++++ docs/zhongdian_mqtt.md | 58 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 docs/zhongdian_mqtt.md diff --git a/apps/iot/src/iot_host.erl b/apps/iot/src/iot_host.erl index 4e3dc0b..6b67eaf 100644 --- a/apps/iot/src/iot_host.erl +++ b/apps/iot/src/iot_host.erl @@ -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) -> diff --git a/docs/zhongdian_mqtt.md b/docs/zhongdian_mqtt.md new file mode 100644 index 0000000..c055798 --- /dev/null +++ b/docs/zhongdian_mqtt.md @@ -0,0 +1,58 @@ +# 中电mqtt通讯规约 +## 服务器地址 + MQTT服务器IP:172.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) +} +```