From d814117a1223d891422569d0a5b828f416729558 Mon Sep 17 00:00:00 2001 From: Chris Kuethe Date: Thu, 9 Jan 2025 11:00:26 -0800 Subject: [PATCH] Make RSSI conversion in sonde2json runtime selectable (#506) This allows the MQTT reporter to log RSSI in dBm, while not confusing existing clients like rdzwx-go --- RX_FSK/src/conn-mqtt.cpp | 2 +- RX_FSK/src/json.cpp | 11 +++++++++-- RX_FSK/src/json.h | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/RX_FSK/src/conn-mqtt.cpp b/RX_FSK/src/conn-mqtt.cpp index 60ba385..d4277dd 100644 --- a/RX_FSK/src/conn-mqtt.cpp +++ b/RX_FSK/src/conn-mqtt.cpp @@ -269,7 +269,7 @@ void MQTT::publishPacket(SondeInfo *si) char payload[1024]; payload[0] = '{'; - int n = sonde2json(payload+1, 1023, si); + int n = sonde2json(payload+1, 1023, si, true); if(n<0) { // ERROR LOG_E(TAG, "publishPacket: sonde2json failed, string too long"); diff --git a/RX_FSK/src/json.cpp b/RX_FSK/src/json.cpp index 74c4ab6..05ff58b 100644 --- a/RX_FSK/src/json.cpp +++ b/RX_FSK/src/json.cpp @@ -33,10 +33,17 @@ int float2json(char **buf, int *maxlen, const char *fmt, float value) { // - MQTT // - rdzJSON (for Android app) // - Web map -int sonde2json(char *buf, int maxlen, SondeInfo *si) +int sonde2json(char *buf, int maxlen, SondeInfo *si, bool rssi_as_dbm) { SondeData *s = &(si->d); int n; + float rssi_conversion = 1.0; + + // this allows callers to get the raw reading and convert it themselves (mobile app) + // or to request the conversion to be done internally for the benefit of downstream + // consumers (mqtt subsystem, and anything else that calls this function) + if (rssi_as_dbm) + rssi_conversion = -0.5; n = float2json(&buf, &maxlen, "\"lat\": %.5f,", s->lat); if(n<0) return -1; @@ -85,7 +92,7 @@ int sonde2json(char *buf, int maxlen, SondeInfo *si) s->time, s->sats, si->freq, - si->rssi/-2.0, + si->rssi * rssi_conversion, si->afc, s->launchKT, s->burstKT, diff --git a/RX_FSK/src/json.h b/RX_FSK/src/json.h index 608e924..2a05ad4 100644 --- a/RX_FSK/src/json.h +++ b/RX_FSK/src/json.h @@ -3,6 +3,6 @@ #include "Sonde.h" -int sonde2json(char *buf, int maxlen, SondeInfo *si); +int sonde2json(char *buf, int maxlen, SondeInfo *si, bool rssi_as_dbm=false); #endif