Merge branch 'dl9rdz:devel' into devel

pull/212/head
eben80 2021-09-22 18:59:45 +02:00 zatwierdzone przez GitHub
commit 9e347a48e6
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 83 dodań i 57 usunięć

Wyświetl plik

@ -152,16 +152,22 @@ int readLine(Stream &stream, char *buffer, int maxlen) {
String processor(const String& var) { String processor(const String& var) {
Serial.println(var); Serial.println(var);
if (var == "MAPCENTER") { if (var == "MAPCENTER") {
double lat, lon; double lat, lon;
if(gpsPos.valid) { lat=gpsPos.lat; lon=gpsPos.lon; } if (gpsPos.valid) {
else { lat = sonde.config.rxlat; lon = sonde.config.rxlon; } lat = gpsPos.lat;
if( !isnan(lat) && !isnan(lon) ) { lon = gpsPos.lon;
char p[40]; }
snprintf(p, 40, "%g,%g", lat, lon); else {
return String(p); lat = sonde.config.rxlat;
} else { lon = sonde.config.rxlon;
return String("48,13"); }
} if ( !isnan(lat) && !isnan(lon) ) {
char p[40];
snprintf(p, 40, "%g,%g", lat, lon);
return String(p);
} else {
return String("48,13");
}
} }
if (var == "VERSION_NAME") { if (var == "VERSION_NAME") {
return String(version_name); return String(version_name);
@ -541,8 +547,8 @@ const char *createLiveJson() {
SondeInfo *s = &sonde.sondeList[sonde.currentSonde]; SondeInfo *s = &sonde.sondeList[sonde.currentSonde];
sprintf(ptr + strlen(ptr), "\"sonde\": {\"rssi\": %d, \"vframe\": %d, \"time\": %d,\"id\": \"%s\", \"freq\": %3.3f, \"type\": \"%s\"," sprintf(ptr + strlen(ptr), "\"sonde\": {\"rssi\": %d, \"vframe\": %d, \"time\": %d,\"id\": \"%s\", \"freq\": %3.3f, \"type\": \"%s\","
"\"lat\": %.6f, \"lon\": %.6f, \"alt\": %.0f, \"speed\": %.1f, \"dir\": %.0f, \"climb\": %.1f, \"launchsite\": \"%s\", \"res\": %d }", "\"lat\": %.6f, \"lon\": %.6f, \"alt\": %.0f, \"speed\": %.1f, \"dir\": %.0f, \"climb\": %.1f, \"launchsite\": \"%s\", \"res\": %d }",
s->rssi, s->d.vframe, s->d.time, s->d.id, s->freq, sondeTypeStr[s->type], s->d.lat, s->d.lon, s->d.alt, s->d.hs, s->d.dir, s->d.vs, s->launchsite, s->rxStat[0]); s->rssi, s->d.vframe, s->d.time, s->d.id, s->freq, sondeTypeStr[s->type], s->d.lat, s->d.lon, s->d.alt, s->d.hs, s->d.dir, s->d.vs, s->launchsite, s->rxStat[0]);
if (gpsPos.valid) { if (gpsPos.valid) {
#if 0 #if 0
@ -555,8 +561,8 @@ const char *createLiveJson() {
/*bool b = */nmea.getAltitude(alt); /*bool b = */nmea.getAltitude(alt);
bool valid = nmea.isValid(); bool valid = nmea.isValid();
uint8_t hdop = nmea.getHDOP(); uint8_t hdop = nmea.getHDOP();
if (valid) { //if (valid) {
strcat(ptr, ","); // strcat(ptr, ",");
#endif #endif
sprintf(ptr + strlen(ptr), ", \"gps\": {\"lat\": %g, \"lon\": %g, \"alt\": %d, \"sat\": %d, \"speed\": %g, \"dir\": %d, \"hdop\": %d }", gpsPos.lat, gpsPos.lon, gpsPos.alt, gpsPos.sat, gpsPos.speed, gpsPos.course, gpsPos.hdop); sprintf(ptr + strlen(ptr), ", \"gps\": {\"lat\": %g, \"lon\": %g, \"alt\": %d, \"sat\": %d, \"speed\": %g, \"dir\": %d, \"hdop\": %d }", gpsPos.lat, gpsPos.lon, gpsPos.alt, gpsPos.sat, gpsPos.speed, gpsPos.course, gpsPos.hdop);
//} //}
@ -814,7 +820,7 @@ void addConfigNumEntry(char *ptr, int idx, const char *label, int *value) {
sprintf(ptr + strlen(ptr), "<tr><td>%s</td><td><input name=\"CFG%d\" type=\"text\" value=\"%d\"/></td></tr>\n", sprintf(ptr + strlen(ptr), "<tr><td>%s</td><td><input name=\"CFG%d\" type=\"text\" value=\"%d\"/></td></tr>\n",
label, idx, *value); label, idx, *value);
} }
void addConfigDblEntry(char *ptr, int idx, const char *label, double *value) { void addConfigDblEntry(char *ptr, int idx, const char *label, double * value) {
sprintf(ptr + strlen(ptr), "<tr><td>%s</td><td><input name=\"CFG%d\" type=\"text\" value=\"%f\"/></td></tr>\n", sprintf(ptr + strlen(ptr), "<tr><td>%s</td><td><input name=\"CFG%d\" type=\"text\" value=\"%f\"/></td></tr>\n",
label, idx, *value); label, idx, *value);
} }
@ -955,7 +961,7 @@ const char *createConfigForm() {
} }
const char *handleConfigPost(AsyncWebServerRequest *request) { const char *handleConfigPost(AsyncWebServerRequest * request) {
// parameters: a_i, f_1, t_i (active/frequency/type) // parameters: a_i, f_1, t_i (active/frequency/type)
Serial.println("Handling post request"); Serial.println("Handling post request");
#if 1 #if 1
@ -1049,7 +1055,7 @@ const char *createControlForm() {
} }
const char *handleControlPost(AsyncWebServerRequest *request) { const char *handleControlPost(AsyncWebServerRequest * request) {
Serial.println("Handling post request"); Serial.println("Handling post request");
int params = request->params(); int params = request->params();
for (int i = 0; i < params; i++) { for (int i = 0; i < params; i++) {
@ -1095,7 +1101,7 @@ const char *handleControlPost(AsyncWebServerRequest *request) {
return ""; return "";
} }
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) { void handleUpload(AsyncWebServerRequest * request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
static File file; static File file;
if (!index) { if (!index) {
Serial.printf("UploadStart: %s\n", filename.c_str()); Serial.printf("UploadStart: %s\n", filename.c_str());
@ -1115,7 +1121,7 @@ void handleUpload(AsyncWebServerRequest *request, String filename, size_t index,
} }
int streamEditForm(int &state, File &file, String filename, char *buffer, size_t maxlen, size_t index) { int streamEditForm(int &state, File & file, String filename, char *buffer, size_t maxlen, size_t index) {
Serial.printf("streamEdit: state=%d max:%d idx:%d\n", state, maxlen, index); Serial.printf("streamEdit: state=%d max:%d idx:%d\n", state, maxlen, index);
int i = 0; int i = 0;
switch (state) { switch (state) {
@ -1190,7 +1196,7 @@ const char *createEditForm(String filename) {
} }
const char *handleEditPost(AsyncWebServerRequest *request) { const char *handleEditPost(AsyncWebServerRequest * request) {
Serial.println("Handling post request"); Serial.println("Handling post request");
int params = request->params(); int params = request->params();
Serial.printf("Post:, %d params\n", params); Serial.printf("Post:, %d params\n", params);
@ -1261,7 +1267,7 @@ const char *createUpdateForm(boolean run) {
return message; return message;
} }
const char *handleUpdatePost(AsyncWebServerRequest *request) { const char *handleUpdatePost(AsyncWebServerRequest * request) {
Serial.println("Handling post request"); Serial.println("Handling post request");
int params = request->params(); int params = request->params();
for (int i = 0; i < params; i++) { for (int i = 0; i < params; i++) {
@ -1702,9 +1708,9 @@ void gpsTask(void *parameter) {
} }
} }
} }
gpsPos.hdop = nmea.getHDOP(); gpsPos.hdop = nmea.getHDOP();
gpsPos.sat = nmea.getNumSatellites(); gpsPos.sat = nmea.getNumSatellites();
gpsPos.speed = nmea.getSpeed() / 1000.0 * 0.514444; // speed is in m/s nmea.getSpeed is in 0.001 knots gpsPos.speed = nmea.getSpeed() / 1000.0 * 0.514444; // speed is in m/s nmea.getSpeed is in 0.001 knots
#ifdef DEBUG_GPS #ifdef DEBUG_GPS
uint8_t hdop = nmea.getHDOP(); uint8_t hdop = nmea.getHDOP();
Serial.printf(" =>: valid: %d N %f E %f alt %d course:%d dop:%d\n", gpsPos.valid ? 1 : 0, gpsPos.lat, gpsPos.lon, gpsPos.alt, gpsPos.course, hdop); Serial.printf(" =>: valid: %d N %f E %f alt %d course:%d dop:%d\n", gpsPos.valid ? 1 : 0, gpsPos.lat, gpsPos.lon, gpsPos.alt, gpsPos.course, hdop);
@ -2524,7 +2530,7 @@ void loopDecoder() {
} }
#if FEATURE_CHASEMAPPER #if FEATURE_CHASEMAPPER
if (sonde.config.cm.active) { if (sonde.config.cm.active) {
Chasemapper::send(udp, s); Chasemapper::send(udp, s);
} }
#endif #endif
} }
@ -3379,7 +3385,7 @@ void loop() {
Update station data to the sondehub v2 DB Update station data to the sondehub v2 DB
*/ */
/* which_pos: 0=none, 1=fixed, 2=gps */ /* which_pos: 0=none, 1=fixed, 2=gps */
void sondehub_station_update(WiFiClient *client, struct st_sondehub *conf) { void sondehub_station_update(WiFiClient * client, struct st_sondehub * conf) {
#define STATION_DATA_LEN 300 #define STATION_DATA_LEN 300
char data[STATION_DATA_LEN]; char data[STATION_DATA_LEN];
char *w; char *w;
@ -3507,35 +3513,51 @@ const char *dfmSubtypeStrSH[16] = { NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL NULL, NULL
}; };
void sondehub_reply_handler(WiFiClient *client) { void sondehub_reply_handler(WiFiClient * client) {
// sondehub handler for tasks to be done even if no data is to be sent: // sondehub handler for tasks to be done even if no data is to be sent:
// process response messages from sondehub // process response messages from sondehub
// request frequency list (if active) // request frequency list (if active)
#define MSG_SIZE 1000 #define MSG_SIZE 1000
char rs_msg[MSG_SIZE]; char rs_msg[MSG_SIZE];
if(shImport==1) { // we are waiting for a reply to a sondehub frequency import request if (shImport == 1) { // we are waiting for a reply to a sondehub frequency import request
// while we are waiting, we do nothing else with sondehub... // while we are waiting, we do nothing else with sondehub...
int res = ShFreqImport::shImportHandleReply(&shclient); int res = ShFreqImport::shImportHandleReply(&shclient);
Serial.printf("ret: %d\n", res); Serial.printf("ret: %d\n", res);
// res==0 means more data is expected, res==1 means complete reply received (or error) // res==0 means more data is expected, res==1 means complete reply received (or error)
if (res == 1) { if (res == 1) {
shImport = 2; // finished shImport = 2; // finished
shImportInterval = sonde.config.sondehub.fiinterval * 60; shImportInterval = sonde.config.sondehub.fiinterval * 60;
} }
} }
else { else {
// any reply here belongs to normal telemetry upload, lets just print it. // any reply here belongs to normal telemetry upload, lets just print it.
// and wait for a valid HTTP response // and wait for a valid HTTP response
while(client->available() > 0) { int cnt = 0;
while (client->available() > 0) {
// data is available from remote server, process it... // data is available from remote server, process it...
int cnt = client->readBytesUntil('\n', rs_msg, MSG_SIZE - 1); // readBytesUntil may wait for up to 1 second if enough data is not available...
rs_msg[cnt] = 0; // int cnt = client->readBytesUntil('\n', rs_msg, MSG_SIZE - 1);
Serial.println(rs_msg); int c = client->read();
// If something that looks like a valid HTTP response is received, we are ready to send the next data item if (c < 0) break; // should never happen in available() returned >0 right before....
if (shState == SH_CONN_WAITACK && cnt > 11 && strncmp(rs_msg, "HTTP/1", 6) == 0) { rs_msg[cnt++] = c;
shState = SH_CONN_IDLE; if (c == '\n') {
rs_msg[cnt] = 0;
Serial.println(rs_msg);
// If something that looks like a valid HTTP response is received, we are ready to send the next data item
if (shState == SH_CONN_WAITACK && cnt > 11 && strncmp(rs_msg, "HTTP/1", 6) == 0) {
shState = SH_CONN_IDLE;
}
cnt = 0;
} }
if (cnt >= MSG_SIZE - 1) {
cnt = 0;
Serial.println("(overlong line from network, ignoring)");
}
}
if (cnt > 0) {
rs_msg[cnt + 1] = 0;
Serial.println(rs_msg);
} }
} }
// send import requests if needed // send import requests if needed
@ -3548,7 +3570,7 @@ void sondehub_reply_handler(WiFiClient *client) {
} }
} }
else if (shImport == 0) { else if (shImport == 0) {
if(shState == SH_CONN_APPENDING || shState == SH_CONN_WAITACK) if (shState == SH_CONN_APPENDING || shState == SH_CONN_WAITACK)
Serial.printf("Time to request next sondehub import.... but still busy with upload request"); Serial.printf("Time to request next sondehub import.... but still busy with upload request");
else else
sondehub_send_fimport(&shclient); sondehub_send_fimport(&shclient);
@ -3557,7 +3579,7 @@ void sondehub_reply_handler(WiFiClient *client) {
// also handle periodic station updates here... // also handle periodic station updates here...
// interval check moved to sondehub_station_update to avoid having to calculate distance in auto mode twice // interval check moved to sondehub_station_update to avoid having to calculate distance in auto mode twice
if(shState == SH_CONN_IDLE) { if (shState == SH_CONN_IDLE) {
// (do not set station update while a telemetry report is being sent // (do not set station update while a telemetry report is being sent
sondehub_station_update(&shclient, &sonde.config.sondehub); sondehub_station_update(&shclient, &sonde.config.sondehub);
} }
@ -3710,21 +3732,21 @@ void sondehub_send_data(WiFiClient * client, SondeInfo * s, struct st_sondehub *
w += strlen(w); w += strlen(w);
} else if ( s->type == STYPE_RS41 ) { } else if ( s->type == STYPE_RS41 ) {
char buf[11]; char buf[11];
if(RS41::getSubtype(buf, 11, s)==0) { if (RS41::getSubtype(buf, 11, s) == 0) {
sprintf(w, "\"subtype\": \"%s\",", buf); sprintf(w, "\"subtype\": \"%s\",", buf);
w += strlen(w); w += strlen(w);
} }
} }
// Only send temp if provided // Only send temp if provided
if ((int)s->d.temperature != 0) { if (!isnan(s->d.temperature)) {
sprintf(w, "\"temp\": %.1f,", float(s->d.temperature)); sprintf(w, "\"temp\": %.1f,", s->d.temperature);
w += strlen(w); w += strlen(w);
} }
// Only send humidity if provided // Only send humidity if provided
if ((int)s->d.relativeHumidity != 0) { if (!isnan(s->d.relativeHumidity)) {
sprintf(w, "\"humidity\": %.1f,", float(s->d.relativeHumidity)); sprintf(w, "\"humidity\": %.1f,", s->d.relativeHumidity);
w += strlen(w); w += strlen(w);
} }
@ -3809,7 +3831,7 @@ void sondehub_finish_data(WiFiClient * client, SondeInfo * s, struct st_sondehub
static const char *DAYS[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; static const char *DAYS[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
static const char *MONTHS[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Noc", "Dec"}; static const char *MONTHS[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Noc", "Dec"};
void sondehub_send_header(WiFiClient * client, SondeInfo * s, struct st_sondehub * conf, struct tm *now) { void sondehub_send_header(WiFiClient * client, SondeInfo * s, struct st_sondehub * conf, struct tm * now) {
Serial.print("PUT /sondes/telemetry HTTP/1.1\r\n" Serial.print("PUT /sondes/telemetry HTTP/1.1\r\n"
"Host: "); "Host: ");
Serial.println(conf->host); Serial.println(conf->host);

Wyświetl plik

@ -20,8 +20,7 @@ int Chasemapper::send(WiFiUDP &udp, SondeInfo *si) {
"\"heading\": %d," "\"heading\": %d,"
"\"time\": \"%02d:%02d:%02d\"," "\"time\": \"%02d:%02d:%02d\","
"\"model\": \"%s\"," "\"model\": \"%s\","
"\"freq\": \"%.3f MHz\"," "\"freq\": \"%.3f MHz\"",
"\"temp\": %g }",
si->d.ser, si->d.ser,
si->d.lat, si->d.lat,
si->d.lon, si->d.lon,
@ -30,8 +29,11 @@ int Chasemapper::send(WiFiUDP &udp, SondeInfo *si) {
(int)si->d.dir, (int)si->d.dir,
tim.tm_hour, tim.tm_min, tim.tm_sec, tim.tm_hour, tim.tm_min, tim.tm_sec,
sondeTypeStrSH[realtype], sondeTypeStrSH[realtype],
si->freq, si->freq);
si->d.temperature); if( !isnan(si->d.temperature) ) {
sprintf(buf + strlen(buf), ", \"temp\": %g", si->d.temperature);
}
strcat(buf, "}");
Serial.printf("Sending chasemapper json: %s\n", buf); Serial.printf("Sending chasemapper json: %s\n", buf);
udp.beginPacket(sonde.config.cm.host, sonde.config.cm.port); udp.beginPacket(sonde.config.cm.host, sonde.config.cm.port);
udp.write((const uint8_t *)buf, strlen(buf)); udp.write((const uint8_t *)buf, strlen(buf));

Wyświetl plik

@ -79,10 +79,12 @@ void Sonde::defaultConfig() {
Serial.printf("Board fingerprint is %d\n", fingerprint); Serial.printf("Board fingerprint is %d\n", fingerprint);
sondeList = (SondeInfo *)malloc((MAXSONDE+1)*sizeof(SondeInfo)); sondeList = (SondeInfo *)malloc((MAXSONDE+1)*sizeof(SondeInfo));
// addSonde should initialize everything anyway, so this should not strictly be necessary, but does no harm either
memset(sondeList, 0, (MAXSONDE+1)*sizeof(SondeInfo)); memset(sondeList, 0, (MAXSONDE+1)*sizeof(SondeInfo));
for(int i=0; i<(MAXSONDE+1); i++) { for(int i=0; i<(MAXSONDE+1); i++) {
sondeList[i].freq=400; sondeList[i].freq=400;
sondeList[i].type=STYPE_RS41; sondeList[i].type=STYPE_RS41;
clearAllData(&sondeList[i]);
} }
config.touch_thresh = 70; config.touch_thresh = 70;
config.led_pout = -1; config.led_pout = -1;

Wyświetl plik

@ -1,4 +1,4 @@
const char *version_name = "rdzTTGOsonde"; const char *version_name = "rdzTTGOsonde";
const char *version_id = "devel20210921"; const char *version_id = "devel20210922";
const int SPIFFS_MAJOR=2; const int SPIFFS_MAJOR=2;
const int SPIFFS_MINOR=16; const int SPIFFS_MINOR=16;