Skip to content

Commit 0ce10c6

Browse files
committed
Fixed the rounding error when calculating the centre frequency
1 parent dcaf12b commit 0ce10c6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

examples/lorawan-nano-gateway/nanogateway.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ def _lora_cb(self, lora):
245245
rx_data = self.lora_sock.recv(256)
246246
stats = lora.stats()
247247
packet = self._make_node_packet(rx_data, self.rtc.now(), stats.rx_timestamp, stats.sfrx, self.bw, stats.rssi, stats.snr)
248+
packet = self._frequency_rounding_fix(packet, self.frequency)
248249
self._push_data(packet)
249250
self._log('Received packet: {}', packet)
250251
self.rxfw += 1
@@ -259,6 +260,17 @@ def _lora_cb(self, lora):
259260
coding_rate=LoRa.CODING_4_5,
260261
tx_iq=True
261262
)
263+
264+
def _frequency_rounding_fix(self, packet, frequency):
265+
266+
float_frequency = str(frequency)[0:3] + '.' + str(frequency)[3]
267+
268+
start = packet.find("freq\":")
269+
end = packet.find(",", start)
270+
271+
pkt = packet[:start + 7] + float_frequency + packet[end:]
272+
273+
return pkt
262274

263275
def _freq_to_float(self, frequency):
264276
"""

0 commit comments

Comments
 (0)