This commit is contained in:
anlicheng 2023-08-18 09:40:20 +08:00
parent a2e320a6a9
commit 7a5c92b4f9
2 changed files with 51 additions and 0 deletions

View File

@ -15,6 +15,8 @@ start(_StartType, _StartArgs) ->
io:setopts([{encoding, unicode}]),
%%
start_mnesia(),
%% mnesia
mnesia_data_importer:import_endpoints(),
%%
erlang:system_flag(fullsweep_after, 16),

View File

@ -0,0 +1,49 @@
%%%-------------------------------------------------------------------
%%% @author aresei
%%% @copyright (C) 2023, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 18. 8 2023 09:28
%%%-------------------------------------------------------------------
-module(mnesia_data_importer).
-author("aresei").
-include("iot.hrl").
%% API
-export([import_endpoints/0]).
import_endpoints() ->
zhongdian_mqtt_endpoint(),
ok.
zhongdian_mqtt_endpoint() ->
Mapper0 = "fun(LocationCode, Fields, Timestamp) ->
Data = #{
<<\"version\">> => <<\"1.0\">>,
<<\"location_code\">> => LocationCode,
<<\"ts\">> => Timestamp,
<<\"properties\">> => Fields
},
{ok, iolist_to_binary(jiffy:encode(Data, [force_utf8]))}
end.",
Mapper = list_to_binary(Mapper0),
{ok, MapperFun} = iot_util:parse_mapper(Mapper),
mnesia_endpoint:insert(#endpoint{
name = <<"zhongdian_mqtt">>,
title = <<"中电mqtt北向数据"/utf8>>,
matcher = <<".*">>,
mapper = Mapper,
mapper_fun = MapperFun,
config = #mqtt_endpoint{
host = <<"172.30.6.161">>,
port = 1883,
username = <<"admin">>,
password = <<"123456">>,
topic = <<"CET/NX/upload">>,
qos = 2
},
created_at = iot_util:timestamp_of_seconds()
}).