
Documentation Center
Once the data is extracted, it calculates the distance between the RAK10701 Field Tester location and the different
gateways that received the LoRaWAN packet. This version of the decoder can handle up to 10 gateways, but it
can be extended.
In the next step, it analyzes the different distances and RSSI levels to find the closest and farthest gateway and
the lowest and highest RSSI and SNR levels.
The result of the decoding is then put into different data fields that are used by Chirpstack for the visualization and
by the rule, we will define to create the downlink to the RAK10701 Field Tester.
11. The next step is to create the different data fields that are filled by the data decoder. This is done in the Fields
section of the device configuration, just below the data encoder section.
Figure 70: Creation of data field
The following fields are required:
Field Name
Identifier (returned value from the decoder)
Field Type
function
distance
(
lat1
,
lon1
,
lat2
,
lon2
)
{
if
((
lat1
==
lat2
)
&&
(
lon1
==
lon2
))
{
return
0
;
}
else
{
var
radlat1
=
Math
.
PI
*
lat1
/
180
;
var
radlat2
=
Math
.
PI
*
lat2
/
180
;
var
theta
=
lon1
-
lon2
;
var
radtheta
=
Math
.
PI
*
theta
/
180
;
var
dist
=
Math
.
sin
(
radlat1
)
*
Math
.
sin
(
radlat2
)
+
Math
.
cos
(
radlat1
)
*
Math
.
cos
(
radlat2
)
if
(
dist
>
1
)
{
dist
=
1
;
}
dist
=
Math
.
acos
(
dist
);
dist
=
dist
*
180
/
Math
.
PI
;
dist
=
dist
*
60
*
1.1515
;
dist
=
dist
*
1.609344
;
return
dist
;
}
}
js