Skip to content

Commit

Permalink
feat: add
Browse files Browse the repository at this point in the history
  • Loading branch information
dawnwinterLiu committed Nov 14, 2022
1 parent c39ae46 commit 9bf96bf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
11 changes: 5 additions & 6 deletions apps/dgiot_parse/etc/dgiot_parse.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ parse.delete_field = ACL,objectId,updatedAt,createdAt
##--------------------------------------------------------------------
## parse config
##--------------------------------------------------------------------
parse.parse_server = http://prod.dgiotcloud.cn:1337
parse.timescale_server = http://127.0.0.1:1338
parse.parse_server = http://dev.iotn2n.com:1337
parse.parse_path = /parse/
parse.parse_appid = c15005097b3eea431d5b334ee8ace1a3
parse.parse_master_key = 349910a0e70a0deace2f5b0ccb30e897
parse.parse_js_key = 8ef8e49492098ceb871c2c0cc486f00b
parse.parse_rest_key = 782482b57aa77215bbf7ee031a82c20a
parse.parse_appid = 434511aaf315b9cd30dfa4115b83148a
parse.parse_master_key = 00ee00579f9577f0aad6661a1fa948ec
parse.parse_js_key = 37d679c52858cb624120365029b159eb
parse.parse_rest_key = f28f70ea0aae4006cfd11d77e92152cc

##--------------------------------------------------------------------
## parse cache
Expand Down
29 changes: 28 additions & 1 deletion apps/dgiot_tdengine/src/dgiot_tdengine.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
-export([transaction/2, format_data/5]).
-export([get_reportdata/3]).
-export([export/2, import/2, save_tdpools/1, tdpool_connect/1]).
-export([save_sql/1, get_values/3]).
-export([save_sql/1, format_sql/3, get_values/3]).

%% dgiot_tdengine:export().
export(ChannelId, #{<<"deviceid">> := DeviceId} = Body) ->
Expand Down Expand Up @@ -372,3 +372,30 @@ save_sql(Sql) ->
Topic = <<"$dg/taos/tdpool/", ClientId/binary, "/sql">>,
dgiot_mqtt:publish(ClientId, Topic, Sql)
end.

format_sql(ProductId, DevAddr, Data) ->
case dgiot_bridge:get_product_info(ProductId) of
{ok, #{<<"thing">> := Properties}} ->
DeviceId = dgiot_parse_id:get_deviceid(ProductId, DevAddr),
Now = maps:get(<<"createdat">>, Data, now),
Length = maps:size(Data),
io:format("~s ~p SortFrame ~p.~n", [?FILE, ?LINE, Length]),
NewValues =
lists:foldl(fun(Index, Acc) ->
case maps:find(Index, Data) of
{ok, X} ->
Values = dgiot_tdengine_field:check_fields(X, Properties),
Acc ++ dgiot_tdengine:get_values(ProductId, Values, Now);
_ ->
Acc
end
end, " ", lists:seq(1, Length)),
TdChannelId = dgiot_parse_id:get_channelid(dgiot_utils:to_binary(2), <<"TD">>, <<"TD资源通道"/utf8>>),
DB = dgiot_tdengine:get_database(TdChannelId, ProductId),
TableName = ?Table(DeviceId),
Using1 = <<" using ", DB/binary, "_", ProductId/binary>>,
TagFields = <<" TAGS ('_", DevAddr/binary, "')">>,
<<"INSERT INTO ", DB/binary, TableName/binary, Using1/binary, TagFields/binary, " VALUES ", NewValues/binary>>;
_ ->
""
end.
1 change: 1 addition & 0 deletions data/loaded_plugins.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
{dgiot_bacnet, {{enable_plugin_dgiot_bacnet}}}.
{dgiot_factory, {{enable_plugin_dgiot_factory}}}.
{dgiot_printer, {{enable_plugin_dgiot_printer}}}.
{dgiot_zhcltech, {{enable_plugin_dgiot_zhcltech}}}.
2 changes: 2 additions & 0 deletions rebar.config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ overlay_vars_rel(RelType) ->
, {enable_plugin_dgiot_bacnet, true}
, {enable_plugin_dgiot_factory, true}
, {enable_plugin_dgiot_printer, true}
, {enable_plugin_dgiot_zhcltech, true}
, {vm_args_file, VmArgs}
].

Expand Down Expand Up @@ -355,6 +356,7 @@ relx_plugin_apps_per_rel(cloud) ->
, dgiot_bacnet
, dgiot_factory
, dgiot_printer
, dgiot_zhcltech
];
relx_plugin_apps_per_rel(edge) ->
[].
Expand Down

0 comments on commit 9bf96bf

Please sign in to comment.