From a408ae546140d925f59f036967f73ea59eecc710 Mon Sep 17 00:00:00 2001 From: "Hansi, dl9rdz" Date: Tue, 26 Jan 2021 20:57:31 +0100 Subject: [PATCH] always send json data after each frame for rdzwx-go --- RX_FSK/RX_FSK.ino | 46 ++++++++++++++++++++++++++++++---------------- RX_FSK/version.h | 2 +- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino index 8a163e3..b6a4394 100644 --- a/RX_FSK/RX_FSK.ino +++ b/RX_FSK/RX_FSK.ino @@ -1858,12 +1858,20 @@ void loopDecoder() { } Serial.println(""); } +#if 0 if (!rdzclient.connected()) { rdzclient = rdzserver.available(); if(rdzclient.connected()) { Serial.println("RDZ JSON socket: new connection"); } } +#else + if (rdzserver.hasClient()) { + Serial.println("TCP JSON socket: new connection"); + if(rdzclient) rdzclient.stop(); + rdzclient = rdzserver.available(); + } +#endif if(rdzclient.available()) { Serial.print("RDZ JSON socket: received "); while(rdzclient.available()) { @@ -1882,10 +1890,10 @@ void loopDecoder() { Serial.println(""); } // wifi (axudp) or bluetooth (bttnc) active => send packet - if ((res & 0xff) == 0 && (connected || tncclient.connected() || rdzclient.connected() )) { + SondeInfo *s = &sonde.sondeList[rxtask.receiveSonde]; + if ((res & 0xff) == 0 && (connected || tncclient.connected() )) { //Send a packet with position information // first check if ID and position lat+lonis ok - SondeInfo *s = &sonde.sondeList[rxtask.receiveSonde]; if (s->validID && ((s->validPos & 0x03) == 0x03)) { const char *str = aprs_senddata(s, sonde.config.call, sonde.config.udpfeed.symbol); @@ -1905,10 +1913,27 @@ void loopDecoder() { Serial.print("sending: "); Serial.println(raw); tncclient.write(raw, rawlen); } - if (rdzclient.connected()) { + } + + + // send to MQTT if enabled + if (connected && mqttEnabled) { + Serial.println("Sending sonde info via MQTT"); + mqttclient.publishPacket(s); + } + + // also send to web socket + //TODO + } + // always send data, even if not valid.... + if (rdzclient.connected()) { Serial.println("Sending position via TCP as rdzJSON"); char raw[1024]; + const char *typestr = s->typestr; + if(*typestr==0) typestr = sondeTypeStr[s->type]; int len = snprintf(raw, 1024, "{" + "\"res\": %d," + "\"type\": \"%s\"," "\"active\": %d," "\"freq\": %.2f," "\"id\": \"%s\"," @@ -1929,12 +1954,13 @@ void loopDecoder() { "\"validTime\": %d," "\"rssi\": %d," "\"afc\": %d," - "\"rxStat\": \"%s\"," "\"launchKT\": %d," "\"burstKT\": %d," "\"countKT\": %d," "\"crefKT\": %d" "}\n", + res&0xff, + typestr, (int)s->active, s->freq, s->id, @@ -1955,7 +1981,6 @@ void loopDecoder() { (int)s->validTime, s->rssi, s->afc, - s->rxStat, s->launchKT, s->burstKT, s->countKT, @@ -1963,17 +1988,6 @@ void loopDecoder() { ); rdzclient.write(raw, len>1024?1024:len); - } - } - - // send to MQTT if enabled - if (connected && mqttEnabled) { - Serial.println("Sending sonde info via MQTT"); - mqttclient.publishPacket(s); - } - - // also send to web socket - //TODO } Serial.print("updateDisplay started... "); if (forceReloadScreenConfig) { diff --git a/RX_FSK/version.h b/RX_FSK/version.h index 150bffa..fa26990 100644 --- a/RX_FSK/version.h +++ b/RX_FSK/version.h @@ -1,4 +1,4 @@ const char *version_name = "rdzTTGOsonde"; -const char *version_id = "devel20210124"; +const char *version_id = "devel20210126"; const int SPIFFS_MAJOR=2; const int SPIFFS_MINOR=8;