fix endpoint
This commit is contained in:
parent
52592330c3
commit
f2cc99427d
@ -15,6 +15,7 @@ start_link() ->
|
|||||||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||||
|
|
||||||
init([]) ->
|
init([]) ->
|
||||||
|
mnesia_endpoint:import_static_endpoints(),
|
||||||
Specs = lists:map(fun child_spec/1, mnesia_endpoint:get_all_endpoints()),
|
Specs = lists:map(fun child_spec/1, mnesia_endpoint:get_all_endpoints()),
|
||||||
|
|
||||||
{ok, {#{strategy => one_for_one, intensity => 1000, period => 3600}, Specs}}.
|
{ok, {#{strategy => one_for_one, intensity => 1000, period => 3600}, Specs}}.
|
||||||
|
|||||||
@ -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()
|
|
||||||
}).
|
|
||||||
@ -14,6 +14,43 @@
|
|||||||
%% API
|
%% API
|
||||||
-export([get_keys/0, get_all_endpoints/0, get_endpoint/1, insert/1, delete/1]).
|
-export([get_keys/0, get_all_endpoints/0, get_endpoint/1, insert/1, delete/1]).
|
||||||
-export([to_map/1, config_equals/2]).
|
-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()].
|
-spec get_keys() -> [Name :: binary()].
|
||||||
get_keys() ->
|
get_keys() ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user