Sondehub position tidy

pull/156/head
Uskompuf 2021-09-13 17:28:24 +10:00
rodzic 7980a9c8ee
commit 3c803f2ed7
2 zmienionych plików z 70 dodań i 59 usunięć

Wyświetl plik

@ -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.
@ -3122,40 +3122,48 @@ 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);
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");
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: ");
@ -3217,6 +3225,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);
@ -3294,27 +3308,24 @@ void sondehub_send_data(WiFiClient * client, SondeInfo * s, struct st_sondehub *
"\"vel_h\": %.3f,"
"\"vel_v\": %.3f,"
"\"heading\": %.3f,"
"\"rssi\": %.1f,",
"\"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];
@ -3324,6 +3335,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,"
@ -3333,38 +3345,37 @@ 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
);
} else {
sprintf(w,
"\"uploader_position\": [%.6f,%.6f,null],"
"\"uploader_antenna\": \"%s\""
"}",
conf->lat, conf->lon, conf->antenna
);
"\"uploader_position\": [%.6f,%.6f,%d],"
"\"mobile\": true",
gpsPos.lat, gpsPos.lon, gpsPos.alt);
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");
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);

Wyświetl plik

@ -1,4 +1,4 @@
const char *version_name = "rdzTTGOsonde";
const char *version_id = "devel20210910test";
const char *version_id = "devel20210913";
const int SPIFFS_MAJOR=2;
const int SPIFFS_MINOR=14;