From b9482906466523774fe4f31e11fb933846cd273e Mon Sep 17 00:00:00 2001 From: Luke Prior <22492406+LukePrior@users.noreply.github.com> Date: Fri, 14 May 2021 14:56:27 +1000 Subject: [PATCH 1/6] Add Sondehub tracker link in web interface --- RX_FSK/RX_FSK.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino index f9669ab..6fcba98 100644 --- a/RX_FSK/RX_FSK.ino +++ b/RX_FSK/RX_FSK.ino @@ -460,6 +460,7 @@ void addSondeStatus(char *ptr, int i) sprintf(ptr + strlen(ptr), "GEO-App - ", s->lat, s->lon); sprintf(ptr + strlen(ptr), "wetterson.de - ", s->id); sprintf(ptr + strlen(ptr), "radiosondy.info - ", s->id); + sprintf(ptr + strlen(ptr), "SondeHub Tracker - ", s->id); sprintf(ptr + strlen(ptr), "OSM - ", s->lat, s->lon); sprintf(ptr + strlen(ptr), "Google", s->lat, s->lon); @@ -3015,4 +3016,4 @@ void sondehub_send_data(WiFiClient *client, SondeInfo *s, struct st_sondehub *co //Serial.println(response); //client->stop(); } -// End of sondehub v2 related codes \ No newline at end of file +// End of sondehub v2 related codes From 30483560ba8308c5188aabb9997a5a199910e449 Mon Sep 17 00:00:00 2001 From: Uskompuf <22492406+Uskompuf@users.noreply.github.com> Date: Fri, 14 May 2021 15:02:30 +1000 Subject: [PATCH 2/6] unnecessary cast--; precision++; --- libraries/SondeLib/MP3H.cpp | 2 +- libraries/SondeLib/RS41.cpp | 38 ++++++++++++++----------------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/libraries/SondeLib/MP3H.cpp b/libraries/SondeLib/MP3H.cpp index a516d50..29bdad7 100644 --- a/libraries/SondeLib/MP3H.cpp +++ b/libraries/SondeLib/MP3H.cpp @@ -261,7 +261,7 @@ void calcgps(uint8_t *buf) { if(dir<0.0) dir+=360.0; si->dir = dir; si->vs = clb; - si->hs = sqrt((float)(vn*vn + ve*ve)); + si->hs = sqrt(vn*vn + ve*ve); Serial.printf("Pos: %f %f alt %f dir %f vs %f hs %f\n", si->lat, si->lon, si->alt, si->dir, si->vs, si->hs); si->validPos = 0x3f; // maybe do some checks first... diff --git a/libraries/SondeLib/RS41.cpp b/libraries/SondeLib/RS41.cpp index 68f1c94..4f5894c 100644 --- a/libraries/SondeLib/RS41.cpp +++ b/libraries/SondeLib/RS41.cpp @@ -173,15 +173,14 @@ double atang2(double x, double y) { double w; if (fabs(x)>fabs(y)) { - w = (double)atan((float)(X2C_DIVL(y,x))); + w = (double)atan(X2C_DIVL(y,x)); if (x<0.0) { if (y>0.0) w = 3.1415926535898+w; else w = w-3.1415926535898; } } else if (y!=0.0) { - w = (double)(1.5707963267949f-atan((float)(X2C_DIVL(x, - y)))); + w = (double)(1.5707963267949f-atan(X2C_DIVL(x, y))); if (y<0.0) w = w-3.1415926535898; } else w = 0.0; @@ -422,20 +421,18 @@ void wgs84r(double x, double y, double z, double h; h = x*x+y*y; if (h>0.0) { - rh = (double)sqrt((float)h); + rh = sqrt(h); xh = x+rh; *long0 = atang2(xh, y)*2.0; if (*long0>3.1415926535898) *long0 = *long0-6.2831853071796; - t = (double)atan((float)(X2C_DIVL(z*1.003364089821, - rh))); - st = (double)sin((float)t); - ct = (double)cos((float)t); - *lat = (double)atan((float) - (X2C_DIVL(z+4.2841311513312E+4*st*st*st, + t = atan(X2C_DIVL(z*1.003364089821, rh)); + st = sin(t); + ct = cos(t); + *lat = atan((X2C_DIVL(z+4.2841311513312E+4*st*st*st, rh-4.269767270718E+4*ct*ct*ct))); - sl = (double)sin((float)*lat); - *heig = X2C_DIVL(rh,(double)cos((float)*lat))-(double)(X2C_DIVR(6.378137E+6f, - sqrt((float)(1.0-6.6943799901413E-3*sl*sl)))); + sl = sin(*lat); + *heig = X2C_DIVL(rh,cos(*lat))-(X2C_DIVR(6.378137E+6f, + sqrt((1.0-6.6943799901413E-3*sl*sl)))); } else { *lat = 0.0; @@ -481,21 +478,14 @@ static void posrs41(const byte b[], uint32_t b_len, uint32_t p) vx = (double)getint16(b, b_len, p+12UL)*0.01; vy = (double)getint16(b, b_len, p+14UL)*0.01; vz = (double)getint16(b, b_len, p+16UL)*0.01; - vn = (-(vx*(double)sin((float)lat)*(double) - cos((float)long0))-vy*(double) - sin((float)lat)*(double)sin((float) - long0))+vz*(double)cos((float)lat); - ve = -(vx*(double)sin((float)long0))+vy*(double) - cos((float)long0); - vu = vx*(double)cos((float)lat)*(double) - cos((float)long0)+vy*(double) - cos((float)lat)*(double)sin((float) - long0)+vz*(double)sin((float)lat); + vn = (-(vx*sin(lat)*cos(long0))-vy*sin(lat)*sin(long0))+vz*cos(lat); + ve = -(vx*sin(long0))+vy*cos(long0); + vu = vx*cos(lat)*cos(long0)+vy*cos(lat)*sin(long0)+vz*sin(lat); dir = X2C_DIVL(atang2(vn, ve),1.7453292519943E-2); if (dir<0.0) dir = 360.0+dir; sonde.si()->dir = dir; Serial.print(" "); - sonde.si()->hs = sqrt((float)(vn*vn+ve*ve)); + sonde.si()->hs = sqrt(vn*vn+ve*ve); Serial.print(sonde.si()->hs*3.6); Serial.print("km/h "); Serial.print(dir); From b56842c9dc5920cd169bbca3ccacadc0eefc801a Mon Sep 17 00:00:00 2001 From: Uskompuf <22492406+Uskompuf@users.noreply.github.com> Date: Fri, 14 May 2021 15:42:56 +1000 Subject: [PATCH 3/6] send more values to SondeHub --- RX_FSK/RX_FSK.ino | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino index 6fcba98..f6b9b18 100644 --- a/RX_FSK/RX_FSK.ino +++ b/RX_FSK/RX_FSK.ino @@ -2928,6 +2928,7 @@ void sondehub_station_update(WiFiClient *client, struct st_sondehub *conf) { "\"software_name\": \"%s\"," "\"software_version\": \"%s\"," "\"uploader_callsign\": \"%s\"," + //TODO only send position + antenna if set "\"uploader_position\": [%s,%s,%s]," "\"uploader_antenna\": \"%s\"" "}", version_name, version_id, conf->callsign, conf->lat, conf->lon, conf->alt, conf->antenna); @@ -2953,6 +2954,7 @@ void sondehub_send_data(WiFiClient *client, SondeInfo *s, struct st_sondehub *co time_t t = s->time; ts = *gmtime(&t); + //TODO convert back to GPS time from UTC time +18s memset(rs_msg, 0, 450); w=rs_msg; @@ -2970,19 +2972,13 @@ void sondehub_send_data(WiFiClient *client, SondeInfo *s, struct st_sondehub *co "\"lat\": %02d.%06d," "\"lon\": %d.%06d," "\"alt\": %d.%02d," -// "\"subtype\": \"RS41-SG\"," -// "\"frequency\": 0," -// "\"temp\": 0," -// "\"humidity\": 0," -// "\"vel_h\": 0," -// "\"vel_v\": 0," -// "\"pressure\": 0," -// "\"heading\": 0," -// "\"batt\": 0," -// "\"sats\": 0," -// "\"xdata\": \"string\"," -// "\"snr\": 0," -// "\"rssi\": %d" + "\"frequency\": %.2f," + "\"vel_h\": %.1f," + "\"vel_v\": %.1f," + "\"heading\": %.1f," + "\"sats\": %d," + "\"rssi\": %.1f," + //TODO only send position + antenna if set "\"uploader_position\": [ %s, %s, %s ]," "\"uploader_antenna\": \"%s\"" "}]", @@ -2992,7 +2988,7 @@ void sondehub_send_data(WiFiClient *client, SondeInfo *s, struct st_sondehub *co ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec + s->sec, (int)s->lat, (int)((s->lat - (int)s->lat)*1000000), (int)s->lon, (int)((s->lon - (int)s->lon)*1000000), (int)s->alt, (int)((s->alt - (int)s->alt)*100), - conf->lat, conf->lon, conf->alt, conf->antenna + (float)s->freq, (float)s->hs, (float)s->vs, (float)s->dir, (int)s->sats, (float)s->rssi, conf->lat, conf->lon, conf->alt, conf->antenna ); if (!client->connected()) { From 14dbbfc8bb62ee72354b119eaaf74992a7f31279 Mon Sep 17 00:00:00 2001 From: Uskompuf <22492406+Uskompuf@users.noreply.github.com> Date: Fri, 14 May 2021 18:57:43 +1000 Subject: [PATCH 4/6] add email field support, null position default --- RX_FSK/RX_FSK.ino | 6 +++--- RX_FSK/data/config.txt | 11 ++++++----- libraries/SondeLib/Sonde.cpp | 2 ++ libraries/SondeLib/Sonde.h | 1 + 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino index f6b9b18..286826e 100644 --- a/RX_FSK/RX_FSK.ino +++ b/RX_FSK/RX_FSK.ino @@ -594,7 +594,7 @@ struct st_configitems config_list[] = { {"sondehub.lon", "Longitude", 19, &sonde.config.sondehub.lon}, {"sondehub.alt", "Altitude", 19, &sonde.config.sondehub.alt}, {"sondehub.antenna", "Antenna", 63, &sonde.config.sondehub.antenna}, - + {"sondehub.email", "Sondehub email", 63, &sonde.config.sondehub.email}, }; const static int N_CONFIG = (sizeof(config_list) / sizeof(struct st_configitems)); @@ -2928,10 +2928,10 @@ void sondehub_station_update(WiFiClient *client, struct st_sondehub *conf) { "\"software_name\": \"%s\"," "\"software_version\": \"%s\"," "\"uploader_callsign\": \"%s\"," - //TODO only send position + antenna if set + "\"uploader_contact_email\": \"%s\"," "\"uploader_position\": [%s,%s,%s]," "\"uploader_antenna\": \"%s\"" - "}", version_name, version_id, conf->callsign, conf->lat, conf->lon, conf->alt, conf->antenna); + "}", version_name, version_id, conf->callsign, conf->email, conf->lat, conf->lon, conf->alt, conf->antenna); client->println(strlen(data)); client->println(); client->println(data); diff --git a/RX_FSK/data/config.txt b/RX_FSK/data/config.txt index 3147aa1..c50d637 100644 --- a/RX_FSK/data/config.txt +++ b/RX_FSK/data/config.txt @@ -124,11 +124,12 @@ mqtt.prefix=rdz_sonde_server/ # Sondehub v2 DB settings sondehub.active=1 sondehub.host=api.v2.sondehub.org -sondehub.callsign=OH3BSG -sondehub.lat=61.570242 -sondehub.lon=23.518801 -sondehub.alt=160.0 -sondehub.antenna=Discone + LNA +sondehub.callsign=CHANGEME_BSG_TTGO +sondehub.lat=null +sondehub.lon=null +sondehub.alt=null +sondehub.antenna= +sondehub.email= #-------------------------------# # EOF #-------------------------------# diff --git a/libraries/SondeLib/Sonde.cpp b/libraries/SondeLib/Sonde.cpp index 05bcde7..aba6785 100644 --- a/libraries/SondeLib/Sonde.cpp +++ b/libraries/SondeLib/Sonde.cpp @@ -388,6 +388,8 @@ void Sonde::setConfig(const char *cfg) { strncpy(config.sondehub.alt, val, 19); } else if(strcmp(cfg, "sondehub.antenna")==0) { strncpy(config.sondehub.antenna, val, 63); + } else if(strcmp(cfg, "sondehub.email")==0) { + strncpy(config.sondehub.email, val, 63); } else { Serial.printf("Invalid config option '%s'=%s \n", cfg, val); } diff --git a/libraries/SondeLib/Sonde.h b/libraries/SondeLib/Sonde.h index 93bd0b2..e20e4df 100644 --- a/libraries/SondeLib/Sonde.h +++ b/libraries/SondeLib/Sonde.h @@ -189,6 +189,7 @@ struct st_sondehub { char lon[20]; char alt[20]; char antenna[64]; + char email[64]; }; typedef struct st_rdzconfig { From 87be88c19a88be2478ee7a42ac56bc2de9583ea1 Mon Sep 17 00:00:00 2001 From: Uskompuf <22492406+Uskompuf@users.noreply.github.com> Date: Fri, 14 May 2021 19:38:31 +1000 Subject: [PATCH 5/6] increase data size to 300 --- RX_FSK/RX_FSK.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino index 286826e..5e7a849 100644 --- a/RX_FSK/RX_FSK.ino +++ b/RX_FSK/RX_FSK.ino @@ -2908,7 +2908,7 @@ void loop() { * Update station data to the sondehub v2 DB */ void sondehub_station_update(WiFiClient *client, struct st_sondehub *conf) { - char data[200]; + char data[300]; Serial.println("sondehub_station_update()"); @@ -2955,6 +2955,7 @@ void sondehub_send_data(WiFiClient *client, SondeInfo *s, struct st_sondehub *co ts = *gmtime(&t); //TODO convert back to GPS time from UTC time +18s + Serial.println(sondeTypeStr[s->type]); memset(rs_msg, 0, 450); w=rs_msg; @@ -2978,7 +2979,6 @@ void sondehub_send_data(WiFiClient *client, SondeInfo *s, struct st_sondehub *co "\"heading\": %.1f," "\"sats\": %d," "\"rssi\": %.1f," - //TODO only send position + antenna if set "\"uploader_position\": [ %s, %s, %s ]," "\"uploader_antenna\": \"%s\"" "}]", From 7f436d54dbb106d0e913a4808636371fb87a196f Mon Sep 17 00:00:00 2001 From: Uskompuf <22492406+Uskompuf@users.noreply.github.com> Date: Fri, 14 May 2021 19:59:40 +1000 Subject: [PATCH 6/6] Stop crash if not enabled or in AP mode --- RX_FSK/RX_FSK.ino | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino index 5e7a849..4cf7688 100644 --- a/RX_FSK/RX_FSK.ino +++ b/RX_FSK/RX_FSK.ino @@ -2130,7 +2130,9 @@ void loopDecoder() { tncclient.write(raw, rawlen); } } - sondehub_send_data(&shclient, s, &sonde.config.sondehub); + if (sonde.config.sondehub.active) { + sondehub_send_data(&shclient, s, &sonde.config.sondehub); + } } // send to MQTT if enabled @@ -2315,6 +2317,9 @@ String translateEncryptionType(wifi_auth_mode_t encryptionType) { } } +enum t_wifi_state { WIFI_DISABLED, WIFI_SCAN, WIFI_CONNECT, WIFI_CONNECTED, WIFI_APMODE }; + +static t_wifi_state wifi_state = WIFI_DISABLED; void enableNetwork(bool enable) { if (enable) { @@ -2334,8 +2339,10 @@ void enableNetwork(bool enable) { mqttclient.init(sonde.config.mqtt.host, sonde.config.mqtt.port, sonde.config.mqtt.id, sonde.config.mqtt.username, sonde.config.mqtt.password, sonde.config.mqtt.prefix); } - //shclient.setInsecure(); // Skip verification - sondehub_station_update(&shclient, &sonde.config.sondehub); + if (sonde.config.sondehub.active && wifi_state != WIFI_APMODE) { + sondehub_station_update(&shclient, &sonde.config.sondehub); + } + connected = true; } else { MDNS.end(); @@ -2343,11 +2350,6 @@ void enableNetwork(bool enable) { } } - -enum t_wifi_state { WIFI_DISABLED, WIFI_SCAN, WIFI_CONNECT, WIFI_CONNECTED, WIFI_APMODE }; - -static t_wifi_state wifi_state = WIFI_DISABLED; - // Events used only for debug output right now void WiFiEvent(WiFiEvent_t event) {