代码拉取完成,页面将自动刷新
%
% Copyright (c) 2016-2019 Petr Gotthard <petr.gotthard@centrum.cz>
% All rights reserved.
% Distributed under the terms of the MIT License. See the LICENSE file.
%
-module(lorawan_connector_http_in).
-export([init/2]).
-export([is_authorized/2]).
-export([allowed_methods/2]).
-export([content_types_accepted/2]).
-export([resource_exists/2]).
-export([handle_downlink/2]).
-include("lorawan_db.hrl").
-record(state, {connector, bindings}).
init(Req, [Connector]) ->
Bindings = lorawan_admin:parse(cowboy_req:bindings(Req)),
{cowboy_rest, Req, #state{connector=Connector, bindings=Bindings}}.
is_authorized(Req, State) ->
case lorawan_admin:handle_authorization(Req, {[], [{<<"device:send">>, '*'}]}) of
{true, _AuthFields} ->
{true, Req, State};
Else ->
{Else, Req, State}
end.
allowed_methods(Req, State) ->
{[<<"OPTIONS">>, <<"PUT">>, <<"POST">>], Req, State}.
content_types_accepted(Req, State) ->
{[
{{<<"application">>, <<"octet-stream">>, '*'}, handle_downlink},
{{<<"application">>, <<"json">>, '*'}, handle_downlink},
{{<<"application">>, <<"x-www-form-urlencoded">>, '*'}, handle_downlink}
], Req, State}.
handle_downlink(Req, #state{connector=Connector, bindings=Bindings}=State) ->
{ok, Msg, Req2} = cowboy_req:read_body(Req),
case lorawan_connector:decode_and_downlink(Connector, Msg, Bindings) of
ok ->
{true, Req2, State};
{error, {Object, Error}} ->
lorawan_utils:throw_error(Object, Error),
{stop, cowboy_req:reply(400, Req2), State};
{error, Error} ->
lorawan_utils:throw_error({connector, Connector#connector.connid}, Error),
{stop, cowboy_req:reply(400, Req2), State}
end.
resource_exists(Req, State) ->
{true, Req, State}.
% end of file
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。