mirror of
https://gitee.com/dgiiot/dgiot.git
synced 2024-12-02 04:08:54 +08:00
profile
This commit is contained in:
parent
006a046c82
commit
a100a25b9d
@ -235,22 +235,22 @@ get_wechat_map(SessionToken) ->
|
||||
get_device_info(Deviceid, SessionToken) ->
|
||||
case dgiot_parse:get_object(<<"Device">>, Deviceid, [{"X-Parse-Session-Token", SessionToken}], [{from, rest}]) of
|
||||
{ok, #{<<"product">> := #{<<"objectId">> := ProductId}, <<"basedata">> := Basedata} = Result} ->
|
||||
NewParams =
|
||||
{NewParams, ProductName} =
|
||||
case dgiot_parse:get_object(<<"Product">>, ProductId) of
|
||||
{ok, #{<<"config">> := #{<<"basedate">> := #{<<"params">> := Params}}}} ->
|
||||
lists:foldl(fun(Param, Acc) ->
|
||||
{ok, #{<<"config">> := #{<<"basedate">> := #{<<"params">> := Params}}, <<"name">> := Productname}} ->
|
||||
lists:foldl(fun(Param, {Acc, _Acc1}) ->
|
||||
Identifier = maps:get(<<"identifier">>, Param),
|
||||
case maps:find(Identifier, Basedata) of
|
||||
error ->
|
||||
Acc;
|
||||
{Acc, Productname};
|
||||
{ok, Value} ->
|
||||
Acc ++ [Param#{<<"value">> => Value}]
|
||||
{Acc ++ [Param#{<<"value">> => Value}], Productname}
|
||||
end
|
||||
end, [], Params);
|
||||
end, {[], <<>>}, Params);
|
||||
_ ->
|
||||
[]
|
||||
{[], <<" ">>}
|
||||
end,
|
||||
{ok, Result#{<<"params">> => NewParams}};
|
||||
{ok, Result#{<<"params">> => NewParams, <<"productname">> => ProductName}};
|
||||
_ ->
|
||||
{error, []}
|
||||
end.
|
||||
|
@ -42,7 +42,7 @@
|
||||
-define(FC_READ_IREGS, 16#04). %读输入寄存器
|
||||
|
||||
-define(FC_WRITE_COIL, 16#05). %写单个线圈寄存器
|
||||
-define(FC_WRITE_HREG, 16#06). %写单个保持寄存
|
||||
-define(FC_WRITE_HREG, 16#06). %写单个保持寄存器
|
||||
-define(FC_WRITE_COILS, 16#0f). %写多个线圈寄存器
|
||||
-define(FC_WRITE_HREGS, 16#10). %写多个保持寄存器
|
||||
|
||||
|
@ -66,14 +66,14 @@ handle_info({tcp, Buff}, #tcp{socket = Socket, state = #state{id = ChannelId, de
|
||||
{DevId1, Devaddr1} ->
|
||||
{DevId1, Devaddr1}
|
||||
end,
|
||||
Topic = <<"profile/", ProductId/binary, "/", DtuAddr/binary>>,
|
||||
Topic = <<"profile/", ProductId/binary, "/", Devaddr/binary>>,
|
||||
dgiot_mqtt:subscribe(Topic),
|
||||
{noreply, TCPState#tcp{buff = <<>>, state = State#state{devaddr = Devaddr, deviceId = DevId}}};
|
||||
_Error ->
|
||||
case re:run(Buff, Head, [{capture, first, list}]) of
|
||||
{match, [Head]} when length(List1) == Len ->
|
||||
create_device(DeviceId, ProductId, Buff, DTUIP, Dtutype),
|
||||
Topic = <<"profile/", ProductId/binary, "/", DtuAddr/binary>>,
|
||||
Topic = <<"profile/", ProductId/binary, "/", Buff/binary>>,
|
||||
dgiot_mqtt:subscribe(Topic),
|
||||
{noreply, TCPState#tcp{buff = <<>>, state = State#state{devaddr = Buff}}};
|
||||
Error1 ->
|
||||
@ -103,19 +103,18 @@ handle_info({tcp, Buff}, #tcp{state = #state{id = ChannelId, devaddr = DtuAddr,
|
||||
end,
|
||||
{noreply, TCPState#tcp{buff = <<>>, state = State#state{env = <<>>}}};
|
||||
|
||||
handle_info({deliver, Topic, Msg}, #tcp{state = #state{id = ChannelId} = State} = TCPState) ->
|
||||
?LOG(info, "Msg ~p", [Msg]),
|
||||
handle_info({deliver, _, Msg}, #tcp{state = #state{id = ChannelId} = State} = TCPState) ->
|
||||
Payload = dgiot_mqtt:get_payload(Msg),
|
||||
Topic = dgiot_mqtt:get_topic(Msg),
|
||||
case jsx:is_json(Payload) of
|
||||
true ->
|
||||
case binary:split(dgiot_mqtt:get_topic(Msg), <<$/>>, [global, trim]) of
|
||||
case binary:split(Topic, <<$/>>, [global, trim]) of
|
||||
[<<"profile">>, ProductId, _DtuAddr] ->
|
||||
%% 设置参数
|
||||
case Payload of
|
||||
#{<<"_dgiotprotocol">> := <<"modbus">>} ->
|
||||
Payloads = modbus_rtu:set_params(maps:without([<<"_dgiotprotocol">>], Payload), ProductId),
|
||||
lists:map(fun(X) ->
|
||||
?LOG(info, "X ~p", [X]),
|
||||
dgiot_tcp_server:send(TCPState, X)
|
||||
end, Payloads);
|
||||
_ ->
|
||||
@ -175,12 +174,11 @@ handle_info({deliver, Topic, Msg}, #tcp{state = #state{id = ChannelId} = State}
|
||||
false ->
|
||||
case binary:split(Topic, <<$/>>, [global, trim]) of
|
||||
[<<"profile">>, ProductId, _DtuAddr] ->
|
||||
%% 设置参数
|
||||
%% 设置参数
|
||||
case Payload of
|
||||
#{<<"_dgiotprotocol">> := <<"modbus">>} ->
|
||||
Payloads = modbus_rtu:set_params(maps:without([<<"_dgiotprotocol">>], Payload), ProductId),
|
||||
lists:map(fun(X) ->
|
||||
?LOG(info, "X ~p", [X]),
|
||||
dgiot_tcp_server:send(TCPState, X)
|
||||
end, Payloads);
|
||||
_ ->
|
||||
|
@ -137,8 +137,8 @@ set_params(Basedata, ProductId) ->
|
||||
<<"readHregs">> -> ?FC_READ_HREGS;
|
||||
<<"readIregs">> -> ?FC_READ_IREGS;
|
||||
<<"writeCoil">> -> ?FC_WRITE_COIL;
|
||||
<<"writeHreg">> -> ?FC_WRITE_COILS; %%需要校验,写多个线圈是什么状态
|
||||
<<"writeCoils">> -> ?FC_WRITE_HREG;
|
||||
<<"writeHreg">> -> ?FC_WRITE_HREG;
|
||||
<<"writeCoils">> -> ?FC_WRITE_COILS; %%需要校验,写多个线圈是什么状态
|
||||
<<"writeHregs">> -> ?FC_WRITE_HREGS; %%需要校验,写多个保持寄存器是什么状态
|
||||
_ -> ?FC_READ_HREGS
|
||||
end,
|
||||
|
@ -6,7 +6,7 @@ parse.delete_field = ACL,objectId,updatedAt,createdAt
|
||||
##--------------------------------------------------------------------
|
||||
## parse config
|
||||
##--------------------------------------------------------------------
|
||||
parse.parse_server = http://prod.iotn2n.com:1337
|
||||
parse.parse_server = http://47.105.106.54:1337
|
||||
parse.parse_path = /parse/
|
||||
parse.parse_appid = 1uqZbbdd_JMyQ45YLsUzYezMRPerMa80
|
||||
parse.parse_master_key = PADbN7p973quWLngikp6XvrDbL97u_vM
|
||||
|
Loading…
Reference in New Issue
Block a user