Skip to content

Commit e6ca8f4

Browse files
committed
Do not encode null values to JSON for Semtech UDP backend.
The Semtech UDP Packet Forwarder interprets NULL as 0 (at least in the case of `tmst`), which can cause issues in some scenarios, e.g. https://support.chirpstack.io/questions/D1H4/gateway-s-rejects-class-b-package-s-packet-rejected-timestamp-seems-wrong-too-much-in-advance
1 parent 5c8ba2d commit e6ca8f4

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/backend/semtech_udp/structs.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,10 @@ pub struct TxPk {
783783
/// Concentrator board used for RX (unsigned integer).
784784
pub brd: u8,
785785
/// Send packet on a certain timestamp value (will ignore time).
786+
#[serde(skip_serializing_if = "Option::is_none")]
786787
pub tmst: Option<u32>,
787788
/// Send packet at a certain GPS time (GPS synchronization required).
789+
#[serde(skip_serializing_if = "Option::is_none")]
788790
pub tmms: Option<u64>,
789791
/// TX central frequency in MHz (unsigned float, Hz precision).
790792
pub freq: f64,
@@ -793,14 +795,19 @@ pub struct TxPk {
793795
/// LoRa datarate identifier (eg. SF12BW500) || FSK datarate (unsigned, in bits per second).
794796
pub datr: DataRate,
795797
/// LoRa ECC coding rate identifier.
798+
#[serde(skip_serializing_if = "Option::is_none")]
796799
pub codr: Option<CodeRate>,
797800
/// FSK frequency deviation (unsigned integer, in Hz).
801+
#[serde(skip_serializing_if = "Option::is_none")]
798802
pub fdev: Option<u16>,
799803
/// If true, disable the CRC of the physical layer (optional).
804+
#[serde(skip_serializing_if = "Option::is_none")]
800805
pub ncrc: Option<bool>,
801806
/// Lora modulation polarization inversion.
807+
#[serde(skip_serializing_if = "Option::is_none")]
802808
pub ipol: Option<bool>,
803809
/// RF preamble size (unsigned integer).
810+
#[serde(skip_serializing_if = "Option::is_none")]
804811
pub prea: Option<u16>,
805812
/// RF packet payload size in bytes (unsigned integer).
806813
pub size: u16,

tests/semtech_udp_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ async fn end_to_end() {
226226
let size = socket.recv(&mut buffer).await.unwrap();
227227
assert_eq!(&[2, 210, 4, 3], &buffer[..4]);
228228
let json = String::from_utf8_lossy(&buffer[4..size]);
229-
assert_eq!("{\"txpk\":{\"imme\":false,\"rfch\":0,\"powe\":16,\"ant\":0,\"brd\":0,\"tmst\":1001234,\"tmms\":null,\"freq\":868.3,\"modu\":\"LORA\",\"datr\":\"SF8BW125\",\"codr\":\"4/5\",\"fdev\":null,\"ncrc\":null,\"ipol\":false,\"prea\":null,\"size\":3,\"data\":\"AQID\"}}", json);
229+
assert_eq!("{\"txpk\":{\"imme\":false,\"rfch\":0,\"powe\":16,\"ant\":0,\"brd\":0,\"tmst\":1001234,\"freq\":868.3,\"modu\":\"LORA\",\"datr\":\"SF8BW125\",\"codr\":\"4/5\",\"ipol\":false,\"size\":3,\"data\":\"AQID\"}}", json);
230230

231231
// TX_ACK
232232
socket

0 commit comments

Comments
 (0)