
Documentation Center
This decoder is not only decoding data from the LoRaWAN packet but is as well reading gateway information from
the additional data that the LoRaWAN server added to the data it forwarded to Datacake.
Each LoRaWAN server uses a different format for this additional information, so there is a code section that tries to
detect whether the data came from a Chirpstack LSN, from TTN, or from a Helium Console:
case
6
:
decoded
.
hotspot_06
=
"("
+
gw_lat
[
5
]
+
","
+
gw_long
[
5
]
+
")"
;
case
5
:
decoded
.
hotspot_05
=
"("
+
gw_lat
[
4
]
+
","
+
gw_long
[
4
]
+
")"
;
case
4
:
decoded
.
hotspot_04
=
"("
+
gw_lat
[
3
]
+
","
+
gw_long
[
3
]
+
")"
;
case
3
:
decoded
.
hotspot_03
=
"("
+
gw_lat
[
2
]
+
","
+
gw_long
[
2
]
+
")"
;
case
2
:
decoded
.
hotspot_02
=
"("
+
gw_lat
[
1
]
+
","
+
gw_long
[
1
]
+
")"
;
case
1
:
decoded
.
hotspot_01
=
"("
+
gw_lat
[
0
]
+
","
+
gw_long
[
0
]
+
")"
;
default
:
break
;
}
decoded
.
maxMod
=
parseInt
((
decoded
.
maxDistance
/
250
),
10
);
decoded
.
minMod
=
parseInt
((
decoded
.
minDistance
/
250
),
10
);
decoded
.
maxDistance
=
parseInt
((
decoded
.
maxMod
*
250
),
10
);
decoded
.
minDistance
=
parseInt
((
decoded
.
minMod
*
250
),
10
);
if
(
decoded
.
maxDistance
<=
1
)
{
decoded
.
maxDistance
=
parseInt
(
250
,
10
);
}
if
(
decoded
.
minDistance
<=
1
)
{
decoded
.
minDistance
=
parseInt
(
250
,
10
);
}
return
decoded
;
}
return
null
;
}
var
server_type
=
0
;
// Check if payload comes from TTN
if
(
typeof
(
rawPayload
.
uplink_message
)
!=
"undefined"
)
{
console
.
log
(
"Found TTN format"
);
server_type
=
1
;
}
// Check if payload comes from Helium
else
if
(
typeof
(
rawPayload
.
hotspots
)
!=
"undefined"
)
{
console
.
log
(
"Found Helium format"
);
server_type
=
2
;
}
// Check if payload comes from Chirpstack
else
if
(
typeof
(
rawPayload
.
rxInfo
)
!=
"undefined"
)
{
console
.
log
(
"Found Chirpstack format"
);
server_type
=
3
;
decoded
.
is_chirpstack
=
1
;
}
else
{
console
.
log
(
"Unknown raw format"
);
}
js