Skip to content

Commit d21f7e1

Browse files
committed
Rename AppID to AppArgs for consistency and clarity
1 parent c91f265 commit d21f7e1

10 files changed

+41
-41
lines changed

doc/Administration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ For each device, which may connect to your network, you can set:
5858
* *DevEUI* of the device
5959
* *Region* that determines the LoRaWAN regional parameters
6060
* *Application* identifier corresponding to one of the [Handlers](Handlers.md) configured.
61-
* *AppID*, which is a string with application-specific configuration.
61+
* *Arguments*, which is an opaque string with application-specific settings.
6262
* *AppEUI* and *AppKey*
6363
* *FCnt Check* to be used for this device
6464
* *Strict 16-bit* (default) or *Strict 32-bit* indicate a standard compliant counter.
@@ -81,7 +81,7 @@ For each device, which is connected (has a link) to the network, you can set:
8181
* *DevEUI* of the device
8282
* *Region* that determines the LoRaWAN regional parameters
8383
* *Application* identifier corresponding to one of the [Handlers](Handlers.md) configured.
84-
* *AppID*, which is a string with application-specific configuration.
84+
* *Arguments*, which is an opaque string with application-specific settings.
8585
* *NwkSKey* and *AppSKey*
8686
* *FCnt Check* to be used for this device (see the Devices section for more explanation).
8787

doc/Handlers.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ The `init/1` will be called upon server initialization. It shall return either
5353
REST API or WebSockets). For more details see
5454
[Cowboy Routing](https://github.com/ninenines/cowboy/blob/master/doc/src/guide/routing.asciidoc).
5555

56-
### handle_join(DevAddr, App, AppID)
56+
### handle_join(DevAddr, App, AppArgs)
5757

5858
The `handle_join/3` will be called when a new node joins the network. The function
5959
shall return either `ok` or `{error, error_description}`.
6060

61-
### handle_rx(DevAddr, App, AppID, RxData)
61+
### handle_rx(DevAddr, App, AppArgs, RxData)
6262
The `handle_rx/4` will be called upon reception of a LoRaWAN frame:
6363
* *DevAddr* is the 4-byte device address
6464
* *App* is the application name defined in the `sys.config`
65-
* *AppID* is an opaque value assigned to the device
65+
* *AppArgs* is an opaque value assigned to the device
6666
* *RxData* is the #rxdata{} record with:
6767
* *port* number
6868
* *data* binary
@@ -92,9 +92,9 @@ The function may return:
9292

9393
For example:
9494
```erlang
95-
handle_rx(DevAddr, <<"my-app">>, AppID, #rxdata{last_lost=true}) ->
95+
handle_rx(DevAddr, <<"my-app">>, AppArgs, #rxdata{last_lost=true}) ->
9696
retransmit;
97-
handle_rx(DevAddr, <<"my-app">>, AppID, #rxdata{port=PortIn, data= <<"DataIn">>}) ->
97+
handle_rx(DevAddr, <<"my-app">>, AppArgs, #rxdata{port=PortIn, data= <<"DataIn">>}) ->
9898
%% application logic
9999
%% ...
100100
{send, #txdata{port=PortOut, data= <<"DataOut">>}}.

doc/WebSockets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ URL is used to select both the target device(s) as well as the desired format.
1010
--------------------|--------------------------------------------------------------------
1111
/devices/*123*/... | Connects to a device with a DevEUI=*123*.
1212
/links/*456*/... | Connects to a link (active node) with a DevAddr=*456*.
13-
/groups/*ABC*/... | Connects to all websocket devices whose **AppID** is set to *ABC*.
13+
/groups/*ABC*/... | Connects to all websocket devices whose **AppArgs** is set to *ABC*.
1414

1515
Multiple parallel connections may be established to one URL.
1616
When the device sends a frame, all connected clients will receive the application data.

priv/admin/admin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ myApp.config(['NgAdminConfigurationProvider', function (nga) {
149149
nga.field('deveui').label('DevEUI').isDetailLink(true),
150150
nga.field('region'),
151151
nga.field('app').label('Application'),
152-
nga.field('appid').label('AppID'),
152+
nga.field('appid').label('Arguments'),
153153
nga.field('last_join', 'datetime').label('Last Join'),
154154
nga.field('link', 'reference')
155155
.targetEntity(links)
@@ -169,7 +169,7 @@ myApp.config(['NgAdminConfigurationProvider', function (nga) {
169169
.targetEntity(applications)
170170
.targetField(nga.field('name'))
171171
.validation({ required: true }),
172-
nga.field('appid').label('AppID'),
172+
nga.field('appid').label('Arguments'),
173173
nga.field('appeui').label('AppEUI')
174174
.attributes({ placeholder: 'e.g. 0123456789ABCDEF' })
175175
.validation({ required: true, pattern: '[A-Fa-f0-9]{16}' }),
@@ -221,7 +221,7 @@ myApp.config(['NgAdminConfigurationProvider', function (nga) {
221221
nga.field('devaddr').label('DevAddr').isDetailLink(true),
222222
nga.field('region'),
223223
nga.field('app').label('Application'),
224-
nga.field('appid').label('AppID'),
224+
nga.field('appid').label('Arguments'),
225225
nga.field('fcntup', 'number').label('FCnt Up'),
226226
nga.field('fcntdown', 'number').label('FCnt Down'),
227227
nga.field('devstat.battery', 'number').label('Battery'),
@@ -241,7 +241,7 @@ myApp.config(['NgAdminConfigurationProvider', function (nga) {
241241
.targetEntity(applications)
242242
.targetField(nga.field('name'))
243243
.validation({ required: true }),
244-
nga.field('appid').label('AppID'),
244+
nga.field('appid').label('Arguments'),
245245
nga.field('nwkskey').label('NwkSKey')
246246
.attributes({ placeholder: 'e.g. FEDCBA9876543210FEDCBA9876543210' })
247247
.validation({ required: true, pattern: '[A-Fa-f0-9]{32}' }),

src/lorawan_application_handler.erl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ do_init([Application|Rest], Acc) ->
2424
Else -> Else
2525
end.
2626

27-
invoke_init({AppID, {App, Module}}) ->
28-
{ok, _Started} = application:ensure_all_started(App),
29-
apply(Module, init, [AppID]);
30-
invoke_init({AppID, Module}) when is_atom(Module) ->
31-
apply(Module, init, [AppID]).
27+
invoke_init({App, {AppName, Module}}) ->
28+
{ok, _Started} = application:ensure_all_started(AppName),
29+
apply(Module, init, [App]);
30+
invoke_init({App, Module}) when is_atom(Module) ->
31+
apply(Module, init, [App]).
3232

33-
handle_join(DevAddr, App, AppID) ->
34-
invoke_handler(handle_join, App, [DevAddr, App, AppID]).
33+
handle_join(DevAddr, App, AppArgs) ->
34+
invoke_handler(handle_join, App, [DevAddr, App, AppArgs]).
3535

36-
handle_rx(DevAddr, App, AppID, RxData) ->
37-
invoke_handler(handle_rx, App, [DevAddr, App, AppID, RxData]).
36+
handle_rx(DevAddr, App, AppArgs, RxData) ->
37+
invoke_handler(handle_rx, App, [DevAddr, App, AppArgs, RxData]).
3838

3939
invoke_handler(Fun, App, Params) ->
4040
{ok, Modules} = application:get_env(plugins),

src/lorawan_application_microchip_mote.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
init(_App) ->
1717
ok.
1818

19-
handle_join(_DevAddr, _App, _AppID) ->
19+
handle_join(_DevAddr, _App, _AppArgs) ->
2020
% accept any device
2121
ok.
2222

2323
% the data structure is explained in
2424
% Lora_Legacy_Mote_Firmware/Includes/Board/MOTEapp.c:520
25-
handle_rx(DevAddr, _App, _AppID, #rxdata{data= <<Light:5/binary, Temp:3/binary>>}) ->
25+
handle_rx(DevAddr, _App, _AppArgs, #rxdata{data= <<Light:5/binary, Temp:3/binary>>}) ->
2626
lager:debug("PUSH_DATA ~s ~s",[DevAddr, Light, Temp]),
2727
% display actual time
2828
{H, M, S} = time(),
2929
Time = lists:flatten(io_lib:format('~2..0b:~2..0b:~2..0b', [H, M, S])),
3030
{send, #txdata{port=2, data=list_to_binary(Time)}};
3131

32-
handle_rx(_DevAddr, _App, _AppID, RxData) ->
32+
handle_rx(_DevAddr, _App, _AppArgs, RxData) ->
3333
{error, {unexpected_data, RxData}}.
3434

3535
% end of file

src/lorawan_application_semtech_mote.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
init(_App) ->
1717
ok.
1818

19-
handle_join(_DevAddr, _App, _AppID) ->
19+
handle_join(_DevAddr, _App, _AppArgs) ->
2020
% accept any device
2121
ok.
2222

2323
% the data structure is explained in
2424
% https://github.com/Lora-net/LoRaMac-node/blob/master/src/apps/LoRaMac/classA/LoRaMote/main.c#L207
25-
handle_rx(DevAddr, _App, _AppID, #rxdata{port=2, data= <<LED, Press:16, Temp:16, _AltBar:16, Batt, _Lat:24, _Lon:24, _AltGps:16>>}) ->
25+
handle_rx(DevAddr, _App, _AppArgs, #rxdata{port=2, data= <<LED, Press:16, Temp:16, _AltBar:16, Batt, _Lat:24, _Lon:24, _AltGps:16>>}) ->
2626
lager:debug("PUSH_DATA ~w ~w ~w ~w",[DevAddr, Press, Temp, Batt]),
2727
% blink with the LED indicator
2828
{send, #txdata{port=2, data= <<((LED+1) rem 2)>>}};
2929

30-
handle_rx(_DevAddr, _App, _AppID, RxData) ->
30+
handle_rx(_DevAddr, _App, _AppArgs, RxData) ->
3131
{error, {unexpected_data, RxData}}.
3232

3333
% end of file

src/lorawan_application_websocket.erl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ init(_App) ->
1616
{"/ws/:type/:name/json", lorawan_ws_frames, [json]}
1717
]}.
1818

19-
handle_join(_DevAddr, _App, _AppID) ->
19+
handle_join(_DevAddr, _App, _AppArgs) ->
2020
% accept any device
2121
ok.
2222

23-
handle_rx(DevAddr, _App, AppID, #rxdata{last_lost=true} = RxData) ->
24-
send_to_sockets(DevAddr, AppID, RxData),
23+
handle_rx(DevAddr, _App, AppArgs, #rxdata{last_lost=true} = RxData) ->
24+
send_to_sockets(DevAddr, AppArgs, RxData),
2525
retransmit;
26-
handle_rx(DevAddr, _App, AppID, #rxdata{port=Port} = RxData) ->
27-
send_to_sockets(DevAddr, AppID, RxData),
26+
handle_rx(DevAddr, _App, AppArgs, #rxdata{port=Port} = RxData) ->
27+
send_to_sockets(DevAddr, AppArgs, RxData),
2828
lorawan_application_handler:send_stored_frames(DevAddr, Port).
2929

30-
send_to_sockets(DevAddr, AppID, RxData) ->
31-
Sockets = lorawan_ws_frames:get_processes(DevAddr, AppID),
32-
[Pid ! {send, DevAddr, AppID, RxData} || Pid <- Sockets].
30+
send_to_sockets(DevAddr, AppArgs, RxData) ->
31+
Sockets = lorawan_ws_frames:get_processes(DevAddr, AppArgs),
32+
[Pid ! {send, DevAddr, AppArgs, RxData} || Pid <- Sockets].
3333

3434
% end of file

src/lorawan_ws_frames.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ store_frame0(DevAddr, TxData, State) ->
8484
lorawan_application_handler:store_frame(DevAddr, TxData),
8585
{ok, State}.
8686

87-
websocket_info({send, _DevAddr, _AppID, #rxdata{data=Data}}, #state{format=raw} = State) ->
87+
websocket_info({send, _DevAddr, _AppArgs, #rxdata{data=Data}}, #state{format=raw} = State) ->
8888
{reply, {binary, Data}, State};
89-
websocket_info({send, DevAddr, _AppID, #rxdata{port=Port, data=Data}}, #state{format=json} = State) ->
89+
websocket_info({send, DevAddr, _AppArgs, #rxdata{port=Port, data=Data}}, #state{format=json} = State) ->
9090
Msg = [{devaddr, lorawan_mac:binary_to_hex(DevAddr)}, {port, Port}, {data, lorawan_mac:binary_to_hex(Data)}],
9191
{reply, {text, jsx:encode(Msg)}, State};
9292
websocket_info(Info, State) ->
9393
lager:warning("Unknown info ~w", [Info]),
9494
{ok, State}.
9595

96-
get_processes(DevAddr, AppID) ->
97-
get_processes0({?MODULE, links, DevAddr}) ++ get_processes0({?MODULE, groups, AppID}).
96+
get_processes(DevAddr, AppArgs) ->
97+
get_processes0({?MODULE, links, DevAddr}) ++ get_processes0({?MODULE, groups, AppArgs}).
9898

9999
get_processes0(Group) ->
100100
case pg2:get_members(Group) of

test/test_forwarder.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ rxpk(Base64Data) ->
3030

3131
push_data(MAC, Data) ->
3232
{ok, Socket} = gen_udp:open(0, [binary]),
33-
Token = crypto:rand_bytes(2),
33+
Token = crypto:strong_rand_bytes(2),
3434
% PUSH_DATA
3535
ok = gen_udp:send(Socket, "localhost", 1680, <<1, Token:2/binary, 0, MAC/binary, (jsx:encode(Data))/binary>>),
3636
R = receive
@@ -45,7 +45,7 @@ push_data(MAC, Data) ->
4545

4646
pull_data(MAC) ->
4747
{ok, Socket} = gen_udp:open(0, [binary]),
48-
Token = crypto:rand_bytes(2),
48+
Token = crypto:strong_rand_bytes(2),
4949
% PULL_DATA
5050
ok = gen_udp:send(Socket, "localhost", 1680, <<1, Token:2/binary, 2, MAC/binary>>),
5151
receive

0 commit comments

Comments
 (0)