less code duplication, saving some 800 bytes in flash
This commit is contained in:
parent
6222cc2d5b
commit
5fdb008a11
|
|
@ -2985,72 +2985,50 @@ void sondehub_send_data(WiFiClient *client, SondeInfo *s, struct st_sondehub *co
|
||||||
memset(rs_msg, 0, MSG_SIZE);
|
memset(rs_msg, 0, MSG_SIZE);
|
||||||
w = rs_msg;
|
w = rs_msg;
|
||||||
|
|
||||||
|
sprintf(w,
|
||||||
|
"[ {"
|
||||||
|
"\"software_name\": \"%s\","
|
||||||
|
"\"software_version\": \"%s\","
|
||||||
|
"\"uploader_callsign\": \"%s\","
|
||||||
|
"\"time_received\": \"%04d-%02d-%02dT%02d:%02d:%02d.000Z\","
|
||||||
|
"\"manufacturer\": \"%s\","
|
||||||
|
"\"type\": \"%s\","
|
||||||
|
"\"serial\": \"%s\","
|
||||||
|
"\"frame\": %d,"
|
||||||
|
"\"datetime\": \"%04d-%02d-%02dT%02d:%02d:%02d.000Z\","
|
||||||
|
"\"lat\": %.6f,"
|
||||||
|
"\"lon\": %.6f,"
|
||||||
|
"\"alt\": %.2f,"
|
||||||
|
"\"frequency\": %.3f,"
|
||||||
|
"\"vel_h\": %.1f,"
|
||||||
|
"\"vel_v\": %.1f,"
|
||||||
|
"\"heading\": %.1f,"
|
||||||
|
"\"sats\": %d,"
|
||||||
|
"\"rssi\": %.1f,",
|
||||||
|
version_name, version_id, conf->callsign,
|
||||||
|
ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec + s->sec,
|
||||||
|
manufacturer_string[s->type], sondeTypeStr[s->type], s->ser, s->frame,
|
||||||
|
ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec + s->sec,
|
||||||
|
(float)s->lat, (float)s->lon, (float)s->alt, (float)s->freq, (float)s->hs, (float)s->vs,
|
||||||
|
(float)s->dir, (int)s->sats, -((float)s->rssi / 2)
|
||||||
|
);
|
||||||
|
|
||||||
|
w += strlen(w);
|
||||||
if (((int)s->temperature != 0) && ((int)s->relativeHumidity != 0)) {
|
if (((int)s->temperature != 0) && ((int)s->relativeHumidity != 0)) {
|
||||||
sprintf(w,
|
sprintf(w,
|
||||||
"[ {"
|
|
||||||
"\"software_name\": \"%s\","
|
|
||||||
"\"software_version\": \"%s\","
|
|
||||||
"\"uploader_callsign\": \"%s\","
|
|
||||||
"\"time_received\": \"%04d-%02d-%02dT%02d:%02d:%02d.000Z\","
|
|
||||||
"\"manufacturer\": \"%s\","
|
|
||||||
"\"type\": \"%s\","
|
|
||||||
"\"serial\": \"%s\","
|
|
||||||
"\"frame\": %d,"
|
|
||||||
"\"datetime\": \"%04d-%02d-%02dT%02d:%02d:%02d.000Z\","
|
|
||||||
"\"lat\": %.6f,"
|
|
||||||
"\"lon\": %.6f,"
|
|
||||||
"\"alt\": %.2f,"
|
|
||||||
"\"frequency\": %.3f,"
|
|
||||||
"\"vel_h\": %.1f,"
|
|
||||||
"\"vel_v\": %.1f,"
|
|
||||||
"\"heading\": %.1f,"
|
|
||||||
"\"sats\": %d,"
|
|
||||||
"\"rssi\": %.1f,"
|
|
||||||
"\"temp\": %.2f,"
|
"\"temp\": %.2f,"
|
||||||
"\"humidity\": %.2f,"
|
"\"humidity\": %.2f,",
|
||||||
"\"uploader_position\": [ %s, %s, %s ],"
|
float(s->temperature), float(s->relativeHumidity)
|
||||||
"\"uploader_antenna\": \"%s\""
|
|
||||||
"}]",
|
|
||||||
version_name, version_id, conf->callsign,
|
|
||||||
ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec + s->sec,
|
|
||||||
manufacturer_string[s->type], sondeTypeStr[s->type], s->ser, s->frame,
|
|
||||||
ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec + s->sec,
|
|
||||||
(float)s->lat, (float)s->lon, (float)s->alt, (float)s->freq, (float)s->hs, (float)s->vs,
|
|
||||||
(float)s->dir, (int)s->sats, -((float)s->rssi / 2), float(s->temperature), float(s->relativeHumidity), conf->lat, conf->lon, conf->alt, conf->antenna
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sprintf(w,
|
|
||||||
"[ {"
|
|
||||||
"\"software_name\": \"%s\","
|
|
||||||
"\"software_version\": \"%s\","
|
|
||||||
"\"uploader_callsign\": \"%s\","
|
|
||||||
"\"time_received\": \"%04d-%02d-%02dT%02d:%02d:%02d.000Z\","
|
|
||||||
"\"manufacturer\": \"%s\","
|
|
||||||
"\"type\": \"%s\","
|
|
||||||
"\"serial\": \"%s\","
|
|
||||||
"\"frame\": %d,"
|
|
||||||
"\"datetime\": \"%04d-%02d-%02dT%02d:%02d:%02d.000Z\","
|
|
||||||
"\"lat\": %.6f,"
|
|
||||||
"\"lon\": %.6f,"
|
|
||||||
"\"alt\": %.2f,"
|
|
||||||
"\"frequency\": %.3f,"
|
|
||||||
"\"vel_h\": %.1f,"
|
|
||||||
"\"vel_v\": %.1f,"
|
|
||||||
"\"heading\": %.1f,"
|
|
||||||
"\"sats\": %d,"
|
|
||||||
"\"rssi\": %.1f,"
|
|
||||||
"\"uploader_position\": [ %s, %s, %s ],"
|
|
||||||
"\"uploader_antenna\": \"%s\""
|
|
||||||
"}]",
|
|
||||||
version_name, version_id, conf->callsign,
|
|
||||||
ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec + s->sec,
|
|
||||||
manufacturer_string[s->type], sondeTypeStr[s->type], s->ser, s->frame,
|
|
||||||
ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec + s->sec,
|
|
||||||
(float)s->lat, (float)s->lon, (float)s->alt, (float)s->freq, (float)s->hs, (float)s->vs,
|
|
||||||
(float)s->dir, (int)s->sats, -((float)s->rssi / 2), conf->lat, conf->lon, conf->alt, conf->antenna
|
|
||||||
);
|
);
|
||||||
|
w += strlen(w);
|
||||||
}
|
}
|
||||||
|
sprintf(w,
|
||||||
|
"\"uploader_position\": [ %s, %s, %s ],"
|
||||||
|
"\"uploader_antenna\": \"%s\""
|
||||||
|
"}]",
|
||||||
|
conf->lat, conf->lon, conf->alt, conf->antenna
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
if (!client->connected()) {
|
if (!client->connected()) {
|
||||||
Serial.println("NO CONNECTION");
|
Serial.println("NO CONNECTION");
|
||||||
|
|
@ -3066,10 +3044,10 @@ void sondehub_send_data(WiFiClient *client, SondeInfo *s, struct st_sondehub *co
|
||||||
client->println("accept: text/plain");
|
client->println("accept: text/plain");
|
||||||
client->println("Content-Type: application/json");
|
client->println("Content-Type: application/json");
|
||||||
client->print("Content-Length: ");
|
client->print("Content-Length: ");
|
||||||
client->println(strlen(w));
|
client->println(strlen(rs_msg));
|
||||||
client->println();
|
client->println();
|
||||||
client->println(w);
|
client->println(rs_msg);
|
||||||
Serial.println(w);
|
Serial.println(rs_msg);
|
||||||
String response = client->readString();
|
String response = client->readString();
|
||||||
Serial.println(response);
|
Serial.println(response);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue