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
This commit is contained in:
Chris Kuethe 2025-01-09 11:00:26 -08:00 committed by GitHub
parent 24bc2b9a1c
commit d814117a12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 4 deletions

View File

@ -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");

View File

@ -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,

View File

@ -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