Skip to content

Commit

Permalink
release: Configuration modification
Browse files Browse the repository at this point in the history
  • Loading branch information
AvantLiu committed Oct 14, 2021
1 parent ef4a240 commit 3020ce6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 17 deletions.
14 changes: 12 additions & 2 deletions apps/dgiot_api/src/utils/dgiot_rest_check.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
%%%===================================================================

check_request(Context, Req) ->

Params = maps:get(check_request, Context, []),
check_request_params(Params, Req, #{}).

Expand Down Expand Up @@ -154,6 +155,14 @@ validate(Rule = {<<"type">>, <<"datetime">>}, Name, Value) ->
validation_error(Rule, Name, Err)
end;

validate(Rule = {<<"type">>, <<"GeoPoint">>}, Name, Value) ->
case is_map(Value) of
true -> ok;
false ->
Err = <<"value:", Value/binary, " is not GeoPoint.">>,
validation_error(Rule, Name, Err)
end;

validate(Rule = {<<"enum">>, Values}, Name, Value) ->
Err = <<"value:", Value/binary, " is not enum.">>,
try
Expand Down Expand Up @@ -233,9 +242,10 @@ validate(schema, Schema, Data) ->
{error, [{schema_invalid, _, Reason}]} ->
?LOG(error,"validate_with_schema ~p,~p,~p~n", [Schema, Data, Reason]),
validation_error(schema, schema, schema_invalid);
{error, [{data_invalid, _, Error, _, Names}]} ->
{error, [{data_invalid, _, Error, _, _Names}]} ->
?LOG(error,"validate_with_schema ~p,~p,~p~n", [Schema, Data, Error]),
validation_error(schema, Names, Error);
%% validation_error(schema, Names, Error);
ok;
{ok, _} ->
ok
end;
Expand Down
6 changes: 4 additions & 2 deletions apps/dgiot_modbus/src/dgiot_modbus_tcp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ handle_info({tcp, Buff}, #tcp{socket = Socket, state = #state{id = ChannelId, de
Topic = <<"profile/", ProductId/binary, "/", Devaddr/binary>>,
dgiot_bridge:send_log(ChannelId, ProductId, Devaddr, "DTU revice from ~p", [dgiot_utils:binary_to_hex(Buff)]),
dgiot_mqtt:subscribe(Topic),
{noreply, TCPState#tcp{buff = <<>>, register = true, clientid = DevId, state = State#state{devaddr = Devaddr, deviceId = DevId}}};
DtuId = dgiot_parse:get_deviceid(ProductId, DtuAddr),
{noreply, TCPState#tcp{buff = <<>>, register = true, clientid = DtuId, 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, "/", Buff/binary>>,
dgiot_bridge:send_log(ChannelId, ProductId, Buff, "DTU revice from ~p", [dgiot_utils:binary_to_hex(Buff)]),
dgiot_mqtt:subscribe(Topic),
{noreply, TCPState#tcp{buff = <<>>, register = true, clientid = DeviceId, state = State#state{devaddr = Buff}}};
DtuId = dgiot_parse:get_deviceid(ProductId, DtuAddr),
{noreply, TCPState#tcp{buff = <<>>, register = true, clientid = DtuId, state = State#state{devaddr = Buff}}};
Error1 ->
?LOG(info, "Error1 ~p Buff ~p ", [Error1, dgiot_utils:to_list(Buff)]),
{noreply, TCPState#tcp{buff = <<>>}}
Expand Down
51 changes: 38 additions & 13 deletions apps/dgiot_topo/src/dgiot_topo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,13 @@ get_attrs(Type, ProductId, ClassName, Attrs, DeviceId, KonvatId, Shapeid, Identi
end,
Text2;
{ok, Text1} ->
case dgiot_data:get({topogps, dgiot_parse:get_shapeid(ProductId, Id)}) of
not_find ->
dgiot_utils:to_binary(Text1);
Gpsaddr ->
Gpsaddr
end
%% case dgiot_data:get({topogps, dgiot_parse:get_shapeid(ProductId, Id)}) of
%% not_find ->
%% dgiot_utils:to_binary(Text1);
%% Gpsaddr ->
%% Gpsaddr
%% end
get_value(ProductId, Id, Text1)
end,
NewAttrs = Attrs#{<<"id">> => dgiot_parse:get_shapeid(DeviceId, Id), <<"text">> => <<Text/binary, " ", Unit/binary>>, <<"draggable">> => false},
save(Type, NewAttrs),
Expand Down Expand Up @@ -302,18 +303,42 @@ get_optshape(ProductId, DeviceId, Payload) ->
Type1 ->
Type1
end,
BinV =
case dgiot_data:get({topogps, dgiot_parse:get_shapeid(ProductId, K)}) of
not_find ->
dgiot_utils:to_binary(V);
Gpsaddr ->
Gpsaddr
end,
BinV = get_value(ProductId, K, V),
Unit = get_unit(ProductId, K),
Acc ++ [#{<<"id">> => dgiot_parse:get_shapeid(DeviceId, K), <<"text">> => <<BinV/binary, " ", Unit/binary>>, <<"type">> => Type}]
end, Topo, Payload),
base64:encode(jsx:encode(#{<<"konva">> => Shape})).

get_value(ProductId, K, V) ->
Props = dgiot_tdengine_handler:get_props(ProductId),
case maps:find(K, Props) of
error ->
dgiot_utils:to_binary(V);
{ok, #{<<"dataType">> := #{<<"type">> := Type} = DataType}} ->
Specs = maps:get(<<"specs">>, DataType, #{}),
case Type of
Type1 when Type1 == <<"enum">>; Type1 == <<"bool">> ->
Value = maps:get(dgiot_utils:to_binary(V), Specs, V),
dgiot_utils:to_binary(Value);
Type3 when Type3 == <<"geopoint">> ->
Addr =
case dgiot_data:get({topogps, dgiot_parse:get_shapeid(ProductId, K)}) of
not_find ->
dgiot_utils:to_binary(V);
Gpsaddr ->
Gpsaddr
end,
dgiot_utils:to_binary(Addr);
Type4 when Type4 == <<"float">>; Type4 == <<"double">> ->
Precision = maps:get(<<"precision">>, Specs, 3),
dgiot_utils:to_binary(dgiot_utils:to_float(V, Precision));
_ ->
dgiot_utils:to_binary(V)
end;
_ ->
dgiot_utils:to_binary(V)
end.

push(ProductId, Devaddr, DeviceId, Payload) ->
Base64 = get_optshape(ProductId, DeviceId, Payload),
Url = dgiot_data:get(topourl),
Expand Down
3 changes: 3 additions & 0 deletions dgiot.ipr
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,8 @@
<mapping directory="$PROJECT_DIR$/_build/emqx/plugins/grpc_plugin" vcs="Git" />
<mapping directory="$PROJECT_DIR$/_build/emqx/plugins/pc" vcs="Git" />
<mapping directory="$PROJECT_DIR$/_build/emqx/plugins/relup_helper" vcs="Git" />
<mapping directory="$PROJECT_DIR$/apps/dgiot_jieshun" vcs="Git" />
<mapping directory="$PROJECT_DIR$/apps/dgiot_mingcheng" vcs="Git" />
<mapping directory="$PROJECT_DIR$/apps/dgiot_xinchuangwei" vcs="Git" />
</component>
</project>

0 comments on commit 3020ce6

Please sign in to comment.