fix endpoint

This commit is contained in:
anlicheng 2023-09-05 17:18:55 +08:00
parent 52592330c3
commit f2cc99427d
3 changed files with 38 additions and 49 deletions

View File

@ -15,6 +15,7 @@ start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
init([]) ->
mnesia_endpoint:import_static_endpoints(),
Specs = lists:map(fun child_spec/1, mnesia_endpoint:get_all_endpoints()),
{ok, {#{strategy => one_for_one, intensity => 1000, period => 3600}, Specs}}.

View File

@ -1,49 +0,0 @@
%%%-------------------------------------------------------------------
%%% @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().
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">>,
host = <<"115.236.153.181">>,
port = 36980,
username = <<"admin">>,
password = <<"123456">>,
topic = <<"CET/NX/upload">>,
qos = 2
},
created_at = iot_util:timestamp_of_seconds()
}).

View File

@ -14,6 +14,43 @@
%% API
-export([get_keys/0, get_all_endpoints/0, get_endpoint/1, insert/1, delete/1]).
-export([to_map/1, config_equals/2]).
-export([import_static_endpoints/0]).
%%
-spec import_static_endpoints() -> no_return().
import_static_endpoints() ->
zhongdian_mqtt_endpoint().
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 = 18083,
username = <<"admin">>,
password = <<"123456">>,
topic = <<"CET/NX/upload">>,
qos = 2
},
created_at = iot_util:timestamp_of_seconds()
}).
-spec get_keys() -> [Name :: binary()].
get_keys() ->