diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino index 6d5435b..b4c3d9c 100644 --- a/RX_FSK/RX_FSK.ino +++ b/RX_FSK/RX_FSK.ino @@ -60,7 +60,7 @@ WiFiClient client; WiFiClient shclient; // Sondehub v2 unsigned long time_last_update = 0; /* SH_LOC_OFF: never send position information to SondeHub - SH_LOC_FIXED: send fixed position (if specified in config) or GPS position (if there is a GPS fix) as fixed station position (no chase mode) to sondehub + SH_LOC_FIXED: send fixed position (if specified in config) to sondehub SH_LOC_CHASE: always activate chase mode and send GPS position (if available) SH_LOC_AUTO: if there is no valid GPS position, or GPS position < MIN_LOC_AUTO_DIST away from known fixed position: use FIXED mode otherwise, i.e. if there is a valid GPS position and (either no fixed position in config, or GPS position is far away from fixed position), use CHASE mode. @@ -3115,40 +3115,52 @@ void sondehub_station_update(WiFiClient *client, struct st_sondehub *conf) { "{" "\"software_name\": \"%s\"," "\"software_version\": \"%s\"," - "\"uploader_callsign\": \"%s\"," - "\"uploader_contact_email\": \"%s\",", - version_name, version_id, conf->callsign, conf->email); + "\"uploader_callsign\": \"%s\",", + version_name, version_id, conf->callsign); w += strlen(w); - // We send GPS position: (a) in CHASE mode, (b) in FIXED mode if no fixed location has been specified in config - if (chase == SH_LOC_CHASE || (chase == SH_LOC_FIXED && (isnan(conf->lat) || isnan(conf->lon)) ) ) { + // Only send email if provided + if (conf->email != '\0') { + sprintf(w, + "\"uploader_contact_email\": \"%s\",", + conf->email); + w += strlen(w); + } + + // Only send antenna if provided + if (conf->antenna != '\0') { + sprintf(w, + "\"uploader_antenna\": \"%s\",", + conf->antenna); + w += strlen(w); + } + + // We send GPS position: (a) in CHASE mode, (b) in AUTO mode if no fixed location has been specified in config + if (chase == SH_LOC_CHASE) { if (gpsPos.valid && gpsPos.lat != 0 && gpsPos.lon != 0) { sprintf(w, "\"uploader_position\": [%.6f,%.6f,%d]," - "\"uploader_antenna\": \"%s\"," - "\"mobile\": true" - "}", - gpsPos.lat, gpsPos.lon, gpsPos.alt, conf->antenna); + "\"mobile\": true", + gpsPos.lat, gpsPos.lon, gpsPos.alt); + } else { + sprintf(w, "\"uploader_position\": [null,null,null]"); } + w += strlen(w); } // Otherweise, in FIXED mode we send the fixed position from config (if specified) else if (chase == SH_LOC_FIXED) { if ((!isnan(conf->lat)) && (!isnan(conf->lon))) { sprintf(w, - "\"uploader_position\": [%.6f,%.6f,%s]," - "\"uploader_antenna\": \"%s\"" - "}", - conf->lat, conf->lon, conf->alt[0] ? conf->alt : "null", conf->antenna); + "\"uploader_position\": [%.6f,%.6f,%s]", + conf->lat, conf->lon, conf->alt[0] ? conf->alt : "null"); + } else { + sprintf(w, "\"uploader_position\": [null,null,null]"); } + w += strlen(w); } - else { - // otherwise (in SH_LOC_NONE mode) we dont include any position info - sprintf(w, - "\"uploader_position\": [null,null,null]," - "\"uploader_antenna\": \"%s\"" - "}", - conf->antenna); - } + + // otherwise (in SH_LOC_NONE mode) we dont include any position info + sprintf(w, "}"); client->println("PUT /listeners HTTP/1.1"); client->print("Host: "); @@ -3210,6 +3222,12 @@ void sondehub_send_data(WiFiClient * client, SondeInfo * s, struct st_sondehub * // For all others, sec should always be 0 and time the exact time in seconds time_t t = s->time; + int chase = conf->chase; + // automatically decided if CHASE or FIXED mode is used (for config AUTO) + if (chase == SH_LOC_AUTO) { + if (SH_LOC_AUTO_IS_CHASE) chase = SH_LOC_CHASE; else chase = SH_LOC_FIXED; + } + while (client->available() > 0) { // data is available from remote server, process it... int cnt = client->readBytesUntil('\n', rs_msg, MSG_SIZE-1); @@ -3280,34 +3298,31 @@ void sondehub_send_data(WiFiClient * client, SondeInfo * s, struct st_sondehub * "\"manufacturer\": \"%s\"," "\"serial\": \"%s\"," "\"datetime\": \"%04d-%02d-%02dT%02d:%02d:%02d.000Z\"," - "\"lat\": %.6f," - "\"lon\": %.6f," - "\"alt\": %.3f," + "\"lat\": %.5f," + "\"lon\": %.5f," + "\"alt\": %.5f," "\"frequency\": %.3f," - "\"vel_h\": %.3f," - "\"vel_v\": %.3f," - "\"heading\": %.3f," - "\"rssi\": %.1f,", + "\"vel_h\": %.5f," + "\"vel_v\": %.5f," + "\"heading\": %.5f," + "\"rssi\": %.1f," + "\"frame\": %d," + "\"type\": \"%s\",", version_name, version_id, conf->callsign, timeinfo.tm_year + 1900, timeinfo.tm_mon + 1, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, manufacturer_string[realtype], s->ser, ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec, (float)s->lat, (float)s->lon, (float)s->alt, (float)s->freq, (float)s->hs, (float)s->vs, - (float)s->dir, -((float)s->rssi / 2) + (float)s->dir, -((float)s->rssi / 2), s->vframe, sondeTypeStrSH[realtype] ); w += strlen(w); + // Only send sats if not M20 if (realtype != STYPE_M20) { sprintf(w, "\"sats\": %d,", (int)s->sats); w += strlen(w); } - sprintf(w, "\"frame\": %d,", s->vframe); - w += strlen(w); - - sprintf(w, "\"type\": \"%s\",", sondeTypeStrSH[realtype]); - w += strlen(w); - /* if there is a subtype (DFM only) */ if ( TYPE_IS_DFM(s->type) && s->subtype > 0 && s->subtype < 16 ) { const char *t = dfmSubtypeStrSH[s->subtype]; @@ -3317,6 +3332,7 @@ void sondehub_send_data(WiFiClient * client, SondeInfo * s, struct st_sondehub * w += strlen(w); } + // Only send temp & humidity if provided if (((int)s->temperature != 0) && ((int)s->relativeHumidity != 0)) { sprintf(w, "\"temp\": %.1f," @@ -3326,38 +3342,41 @@ void sondehub_send_data(WiFiClient * client, SondeInfo * s, struct st_sondehub * w += strlen(w); } - if ((conf->chase == 0) && (!isnan(conf->lat)) && (!isnan(conf->lon))) { - if (conf->alt[0] != '\0') { + // Only send antenna if provided + if (conf->antenna != '\0') { + sprintf(w, + "\"uploader_antenna\": \"%s\",", + conf->antenna); + w += strlen(w); + } + + // We send GPS position: (a) in CHASE mode, (b) in AUTO mode if no fixed location has been specified in config + if (chase == SH_LOC_CHASE) { + if (gpsPos.valid && gpsPos.lat != 0 && gpsPos.lon != 0) { sprintf(w, - "\"uploader_position\": [%.6f,%.6f,%s]," - "\"uploader_antenna\": \"%s\"" - "}", - conf->lat, conf->lon, conf->alt, conf->antenna - ); + "\"uploader_position\": [%.6f,%.6f,%d]," + "\"mobile\": true", + gpsPos.lat, gpsPos.lon, gpsPos.alt); } else { - sprintf(w, - "\"uploader_position\": [%.6f,%.6f,null]," - "\"uploader_antenna\": \"%s\"" - "}", - conf->lat, conf->lon, conf->antenna - ); + sprintf(w, "\"uploader_position\": [null,null,null]"); } + w += strlen(w); } - else if (gpsPos.valid && gpsPos.lat != 0 && gpsPos.lon != 0) { - sprintf(w, - "\"uploader_position\": [%.6f,%.6f,%d]," - "\"uploader_antenna\": \"%s\"" - "}", - gpsPos.lat, gpsPos.lon, gpsPos.alt, conf->antenna - ); - } - else { - sprintf(w, - "\"uploader_antenna\": \"%s\"" - "}", - conf->antenna - ); + // Otherweise, in FIXED mode we send the fixed position from config (if specified) + else if (chase == SH_LOC_FIXED) { + if ((!isnan(conf->lat)) && (!isnan(conf->lon))) { + sprintf(w, + "\"uploader_position\": [%.6f,%.6f,%s]", + conf->lat, conf->lon, conf->alt[0] ? conf->alt : "null"); + } else { + sprintf(w, "\"uploader_position\": [null,null,null]"); + } + w += strlen(w); } + + // otherwise (in SH_LOC_NONE mode) we dont include any position info + sprintf(w, "}"); + if (shState != SH_CONN_APPENDING) { sondehub_send_header(client, s, conf); sondehub_send_next(client, s, conf, rs_msg, strlen(rs_msg), 1); diff --git a/RX_FSK/data/config.txt b/RX_FSK/data/config.txt index 08ef101..8a8487e 100644 --- a/RX_FSK/data/config.txt +++ b/RX_FSK/data/config.txt @@ -121,7 +121,7 @@ mqtt.prefix=rdz_sonde_server/ #-------------------------------# # Sondehub v2 DB settings sondehub.active=0 -sondehub.chase=0 +sondehub.chase=2 sondehub.host=api.v2.sondehub.org sondehub.callsign=CHANGEME_RDZTTGO sondehub.lat= diff --git a/RX_FSK/version.h b/RX_FSK/version.h index 2b47269..4e166f8 100644 --- a/RX_FSK/version.h +++ b/RX_FSK/version.h @@ -1,4 +1,4 @@ const char *version_name = "rdzTTGOsonde"; -const char *version_id = "devel20210912"; +const char *version_id = "devel20210913"; const int SPIFFS_MAJOR=2; const int SPIFFS_MINOR=14;