json reorg, part 3

This commit is contained in:
Hans P. Reiser 2022-04-08 00:00:41 +00:00
parent cad5bd16cd
commit 551744aa29
2 changed files with 18 additions and 2 deletions

View File

@ -2422,6 +2422,20 @@ void loopDecoder() {
float dir = isnan(s->d.dir) ? 0 : s->d.dir;
//
raw[0] = '{';
// Use same JSON format as for MQTT and HTML map........
sonde2json(raw+1, 1023, s);
sprintf(raw+strlen(raw),
",\"active\":%d"
",\"validId\":%d"
",\"validPos\":%d"
" %s}\n",
(int)s->active,
s->d.validID,
s->d.validPos,
gps);
int len = strlen(raw);
#if 0
int len = snprintf(raw, 1024, "{"
"\"res\": %d,"
"\"type\": \"%s\","
@ -2477,6 +2491,8 @@ void loopDecoder() {
s->d.crefKT,
gps
);
#endif
//Serial.println("Writing rdzclient...");
if (len > 1024) len = 1024;
int wlen = rdzclient.write(raw, len);

View File

@ -73,14 +73,14 @@ int sonde2json(char *buf, int maxlen, SondeInfo *si)
s->countKT,
s->crefKT,
si->launchsite,
si->rxStat[0]
(int)si->rxStat[0]
);
if(n>=maxlen) return -1;
buf += n; maxlen -= n;
// add only if available
if(s->batteryVoltage > 0) {
n = snprintf(buf, maxlen, "\"bat\": %.1f,", s->batteryVoltage);
n = snprintf(buf, maxlen, ",\"bat\": %.1f", s->batteryVoltage);
if(n>=maxlen) return -1;
buf += n; maxlen -= n;
}