dgiot/apps/emqx_sn/priv/emqx_sn.schema
2021-05-22 03:06:00 +09:00

75 lines
2.0 KiB
Erlang

%%-*- mode: erlang -*-
%% emqx_sn config mapping
{mapping, "mqtt.sn.port", "emqx_sn.port", [
{default, "1884"},
{datatype, string}
]}.
{translation, "emqx_sn.port", fun(Conf) ->
case re:split(cuttlefish:conf_get("mqtt.sn.port", Conf, ""), ":", [{return, list}]) of
[Port] ->
{{0,0,0,0}, list_to_integer(Port)};
Tokens ->
Port = lists:last(Tokens),
IP = case inet:parse_address(lists:flatten(lists:join(":", Tokens -- [Port]))) of
{error, Reason} ->
throw({invalid_ip_address, Reason});
{ok, X} -> X
end,
Port1 = list_to_integer(Port),
{IP, Port1}
end
end}.
{mapping, "mqtt.sn.advertise_duration", "emqx_sn.advertise_duration", [
{default, "15s"},
{datatype, {duration, ms}}
]}.
{mapping, "mqtt.sn.gateway_id", "emqx_sn.gateway_id", [
{default, 1},
{datatype, integer}
]}.
{mapping, "mqtt.sn.username", "emqx_sn.username", [
{datatype, string}
]}.
{mapping, "mqtt.sn.password", "emqx_sn.password", [
{datatype, string}
]}.
{mapping, "mqtt.sn.idle_timeout", "emqx_sn.idle_timeout", [
{default, "30s"},
{datatype, {duration, ms}}
]}.
{mapping, "mqtt.sn.enable_stats", "emqx_sn.enable_stats", [
{datatype, flag}
]}.
{mapping, "mqtt.sn.enable_qos3", "emqx_sn.enable_qos3", [
{datatype, flag}
]}.
{mapping, "mqtt.sn.predefined.topic.$id", "emqx_sn.predefined", [
{datatype, string}
]}.
{translation, "emqx_sn.username", fun(Conf) ->
Username = cuttlefish:conf_get("mqtt.sn.username", Conf),
list_to_binary(Username)
end}.
{translation, "emqx_sn.password", fun(Conf) ->
Password = cuttlefish:conf_get("mqtt.sn.password", Conf),
list_to_binary(Password)
end}.
{translation, "emqx_sn.predefined", fun(Conf) ->
List = cuttlefish_variable:filter_by_prefix("mqtt.sn.predefined.topic", Conf),
TopicIdList = lists:sort([{list_to_integer(I), iolist_to_binary(TopicName)}
|| {["mqtt", "sn", "predefined", "topic", I], TopicName}
<- List, I =/= "0"])
end}.