Skip to content

Commit 57e0dba

Browse files
committed
Make altitude in Location optional
When specifying a device location in the TTN console and leaving the altitude at 0, it will not be part of the payload. Right now this causes the parser to fail. Regression test included.
1 parent 9349522 commit 57e0dba

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

src/v3/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ pub struct DataRateLora {
9999
pub struct Location {
100100
pub latitude: f64,
101101
pub longitude: f64,
102-
pub altitude: f64,
102+
#[serde(default)]
103+
#[serde(skip_serializing_if = "Option::is_none")]
104+
pub altitude: Option<f64>,
103105
pub source: String,
104106
}
105107

@@ -194,4 +196,15 @@ mod test {
194196

195197
assert!(matches!(uplink.payload, Payload::Uplink(_)));
196198
}
199+
200+
/// Regression test: Altitude in location may not be present.
201+
#[test]
202+
pub fn uplink_without_altitude() {
203+
let json = include_bytes!("../../test/v3/uplink3.json");
204+
let uplink: Message = serde_json::from_slice(json).unwrap();
205+
206+
println!("{:#?}", uplink);
207+
208+
assert!(matches!(uplink.payload, Payload::Uplink(_)));
209+
}
197210
}

test/v3/uplink3.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"end_device_ids": {
3+
"device_id": "some-device-id",
4+
"application_ids": { "application_id": "some-app" },
5+
"dev_eui": "FFFFFFFFFFFFFFFF",
6+
"join_eui": "0000000000000000",
7+
"dev_addr": "77777777"
8+
},
9+
"correlation_ids": ["gs:uplink:01JZG5HJ5E6Q6RS9QB9T9BZZXM"],
10+
"received_at": "2025-07-06T15:26:44.606958589Z",
11+
"uplink_message": {
12+
"session_key_id": "q2P5jLF9Qldmi11CkZU7bg==",
13+
"f_port": 3,
14+
"frm_payload": "aGVsbG8=",
15+
"rx_metadata": [
16+
{
17+
"gateway_ids": {
18+
"gateway_id": "some-gateway",
19+
"eui": "AAAAAAAAAAAAAAAA"
20+
},
21+
"time": "2025-07-06T15:26:44.342732906Z",
22+
"timestamp": 12854260,
23+
"rssi": -33,
24+
"channel_rssi": -33,
25+
"snr": 12,
26+
"location": {
27+
"latitude": 47.0000000000000,
28+
"longitude": 8.00000000000000,
29+
"altitude": 500,
30+
"source": "SOURCE_REGISTRY"
31+
},
32+
"uplink_token": "cmVkYWN0ZWQtdXBsaW5rLXRva2Vu",
33+
"received_at": "2025-07-06T15:26:44.344797626Z"
34+
}
35+
],
36+
"settings": {
37+
"data_rate": {
38+
"lora": {
39+
"bandwidth": 125000,
40+
"spreading_factor": 12,
41+
"coding_rate": "4/5"
42+
}
43+
},
44+
"frequency": "868300000",
45+
"timestamp": 12854260,
46+
"time": "2025-07-06T15:26:44.342732906Z"
47+
},
48+
"received_at": "2025-07-06T15:26:44.399177939Z",
49+
"consumed_airtime": "1.482752s",
50+
"locations": {
51+
"user": {
52+
"latitude": 47.55555555555555,
53+
"longitude": 8.555555555555555,
54+
"source": "SOURCE_REGISTRY"
55+
}
56+
},
57+
"version_ids": {
58+
"brand_id": "dragino",
59+
"model_id": "lsn50v2-d20",
60+
"hardware_version": "_unknown_hw_version_",
61+
"firmware_version": "1.1",
62+
"band_id": "EU_863_870"
63+
},
64+
"network_ids": {
65+
"net_id": "000013",
66+
"ns_id": "BBBBBBBBBBBBBBBB",
67+
"tenant_id": "ttn",
68+
"cluster_id": "eu1",
69+
"cluster_address": "eu1.cloud.thethings.network"
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)