fix
This commit is contained in:
parent
a2e320a6a9
commit
7a5c92b4f9
@ -15,6 +15,8 @@ start(_StartType, _StartArgs) ->
|
|||||||
io:setopts([{encoding, unicode}]),
|
io:setopts([{encoding, unicode}]),
|
||||||
%% 启动数据库
|
%% 启动数据库
|
||||||
start_mnesia(),
|
start_mnesia(),
|
||||||
|
%% 导入固定数据到mnesia
|
||||||
|
mnesia_data_importer:import_endpoints(),
|
||||||
|
|
||||||
%% 加速内存的回收
|
%% 加速内存的回收
|
||||||
erlang:system_flag(fullsweep_after, 16),
|
erlang:system_flag(fullsweep_after, 16),
|
||||||
|
|||||||
49
apps/iot/src/mnesia/mnesia_data_importer.erl
Normal file
49
apps/iot/src/mnesia/mnesia_data_importer.erl
Normal 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()
|
||||||
|
}).
|
||||||
Loading…
x
Reference in New Issue
Block a user