Documentation Center
📝
NOTE:
This decoder script can be found on
RUI3-Field-Tester GitHub repository
decoder script for TTN and Helium.
4. After creating the device profile, you can now create an application and add the RAK10701 device. And then
attached the
Device-profile
you created. You have to take note of the DEVEUI and APPKEY in this section.
These parameters must match the ones in our RAK10701 Field Tester.
function
Decode
(
fPort
,
bytes
,
variables
)
{
var
decoded
=
{};
// avoid sending Downlink ACK to integration (Cargo)
if
((
fPort
===
1
)
||
(
fPort
===
2
)){
var
lonSign
=
(
bytes
[
0
]
>>
7
)
&
0x01
?
-
1
:
1
;
var
latSign
=
(
bytes
[
0
]
>>
6
)
&
0x01
?
-
1
:
1
;
var
encLat
=
((
bytes
[
0
]
&
0x3f
)
<<
17
)
+
(
bytes
[
1
]
<<
9
)
+
(
bytes
[
2
]
<<
1
)
+
(
bytes
[
3
]
>>
7
);
var
encLon
=
((
bytes
[
3
]
&
0x7f
)
<<
16
)
+
(
bytes
[
4
]
<<
8
)
+
bytes
[
5
];
var
hdop
=
bytes
[
8
]
/
10
;
var
sats
=
bytes
[
9
];
var
maxHdop
=
2
;
var
minSats
=
5
;
if
((
hdop
<
maxHdop
)
&&
(
sats
>=
minSats
))
{
// Send only acceptable quality of position to mappers
decoded
.
latitude
=
latSign
*
(
encLat
*
108
+
53
)
/
10000000
;
decoded
.
longitude
=
lonSign
*
(
encLon
*
215
+
107
)
/
10000000
;
decoded
.
altitude
=
((
bytes
[
6
]
<<
8
)
+
bytes
[
7
])
-
1000
;
decoded
.
accuracy
=
(
hdop
*
5
+
5
)
/
10
decoded
.
hdop
=
hdop
;
decoded
.
sats
=
sats
;
}
else
{
decoded
.
error
=
"Need more GPS precision (hdop must be <"
+
maxHdop
+
" & sats must be >= "
+
minSats
+
") current hdop: "
+
hdop
+
" & sats:"
+
sats
;
decoded
.
latitude
=
latSign
*
(
encLat
*
108
+
53
)
/
10000000
;
decoded
.
longitude
=
lonSign
*
(
encLon
*
215
+
107
)
/
10000000
;
decoded
.
altitude
=
((
bytes
[
6
]
<<
8
)
+
bytes
[
7
])
-
1000
;
decoded
.
accuracy
=
(
hdop
*
5
+
5
)
/
10
decoded
.
hdop
=
hdop
;
decoded
.
sats
=
sats
;
}
return
decoded
;
}
return
null
;
js