mirror of
https://gitee.com/dgiiot/dgiot.git
synced 2024-11-30 19:28:09 +08:00
parse
This commit is contained in:
parent
a1bdeecd1f
commit
d1ca020167
@ -94,6 +94,9 @@ encode_data(Data, Address, SlaveId, ProductId) ->
|
||||
is16(<<"0X", Data/binary>>) when size(Data) == 4 ->
|
||||
Data;
|
||||
|
||||
is16(<<"0X", Data/binary>>) when size(Data) > 4 ->
|
||||
Data;
|
||||
|
||||
is16(<<"0X", Data/binary>>) ->
|
||||
<<"00", Data/binary>>;
|
||||
|
||||
|
@ -275,8 +275,6 @@ string2value(Str, Type, Specs) ->
|
||||
save_pnque(DtuProductId, DtuAddr, ProductId, DevAddr) ->
|
||||
DtuId = dgiot_parse:get_deviceid(DtuProductId, DtuAddr),
|
||||
Topic = <<"thing/", ProductId/binary, "/", DevAddr/binary>>,
|
||||
Args = dgiot_data:get({?TASK_ARGS, DtuProductId}),
|
||||
supervisor:start_child(dgiot_task, [Args#{<<"dtuid">> => DtuId}]),
|
||||
dgiot_mqtt:subscribe(Topic),
|
||||
case dgiot_data:get(?DGIOT_PNQUE, DtuId) of
|
||||
not_find ->
|
||||
@ -284,7 +282,9 @@ save_pnque(DtuProductId, DtuAddr, ProductId, DevAddr) ->
|
||||
Pn_que ->
|
||||
New_Pn_que = dgiot_utils:unique_2(Pn_que ++ [{ProductId, DevAddr}]),
|
||||
dgiot_data:insert(?DGIOT_PNQUE, DtuId, New_Pn_que)
|
||||
end.
|
||||
end,
|
||||
Args = dgiot_data:get({?TASK_ARGS, DtuProductId}),
|
||||
supervisor:start_child(dgiot_task, [Args#{<<"dtuid">> => DtuId}]).
|
||||
|
||||
get_pnque(DtuId) ->
|
||||
case dgiot_data:get(?DGIOT_PNQUE, DtuId) of
|
||||
|
@ -247,7 +247,8 @@ save_td(#task{app = _App, tid = Channel, product = ProductId, devaddr = DevAddr,
|
||||
false ->
|
||||
Payload = jsx:encode(#{<<"thingdata">> => Data, <<"appdata">> => AppData}),
|
||||
Topic = <<"topo/", ProductId/binary, "/", DevAddr/binary, "/post">>,
|
||||
dgiot_mqtt:publish(ProductId, Topic, Payload),
|
||||
dgiot_mqtt:publish(DevAddr, Topic, Payload),
|
||||
dgiot_mqtt:publish(DevAddr, <<"报警">>, Data),
|
||||
dgiot_tdengine_adapter:save(ProductId, DevAddr, Data),
|
||||
dgiot_bridge:send_log(Channel, "from_dev=> ~ts: ~ts ", [unicode:characters_to_list(Topic), unicode:characters_to_list(jsx:encode(Data))]);
|
||||
true ->
|
||||
|
@ -457,6 +457,7 @@ check_fields(Data, #{<<"properties">> := Props}) -> check_fields(Data, Props);
|
||||
check_fields(Data, Props) -> check_fields(Data, Props, #{}).
|
||||
check_fields(Data, Props, Acc) when Data == []; Props == [] -> Acc;
|
||||
check_fields(Data, [#{<<"identifier">> := Field, <<"dataType">> := #{<<"type">> := Type} = DataType} = Prop | Other], Acc) ->
|
||||
LowerField = list_to_binary(string:to_lower(binary_to_list(Field))),
|
||||
case check_field(Data, Prop) of
|
||||
undefined ->
|
||||
check_fields(Data, Other, Acc);
|
||||
@ -470,12 +471,13 @@ check_fields(Data, [#{<<"identifier">> := Field, <<"dataType">> := #{<<"type">>
|
||||
undefined ->
|
||||
Acc1;
|
||||
Value1 ->
|
||||
Acc1#{?Struct(Field, Field1) => Value1}
|
||||
LowerField1 = list_to_binary(string:to_lower(binary_to_list(Field1))),
|
||||
Acc1#{?Struct(LowerField, LowerField1) => Value1}
|
||||
end
|
||||
end, Acc, SubFields),
|
||||
check_fields(Data, Other, Acc2);
|
||||
_ ->
|
||||
check_fields(Data, Other, Acc#{Field => Value})
|
||||
check_fields(Data, Other, Acc#{LowerField => Value})
|
||||
end
|
||||
end.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user