Skip to content

Commit 4cc2066

Browse files
authored
Merge pull request opendata-stuttgart#548 from dirkmueller/beta
http sending improvements
2 parents e48eae4 + 40f527f commit 4cc2066

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed

airrohr-firmware/Versions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
NRZ-2019-126-B6
22
* Read SDS011 version once on startup
33
* Put software serial edge detection work within loop
4+
* Discard power-on self-test dust sensor measurements
5+
* Do not store WiFi station credentials in SDK protected flash
6+
* Switch to ArduinoJson 6.13
7+
* show SDS011 manufacturing date in values HTML page
48

59
NRZ-2019-126-B5
610
* Rename Luftdaten.info to Sensors.Community everywhere

airrohr-firmware/airrohr-firmware.ino

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ enum class PmSensorCmd {
337337
};
338338

339339
LoggerConfig loggerConfigs[LoggerCount];
340-
BearSSL::X509List x509_dst_root_ca(dst_root_ca_x3);
341340

342341
long int sample_count = 0;
343342
bool htu21d_init_failed = false;
@@ -717,7 +716,8 @@ static bool SDS_cmd(PmSensorCmd cmd) {
717716
0xAA, 0xB4, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x05, 0xAB
718717
};
719718
static constexpr uint8_t continuous_mode_cmd[] PROGMEM = {
720-
0xAA, 0xB4, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x07, 0xAB
719+
0xAA, 0xB4, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x07, 0xAB,
720+
0xAA, 0xB4, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x01, 0xAB
721721
};
722722
static constexpr uint8_t version_cmd[] PROGMEM = {
723723
0xAA, 0xB4, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x05, 0xAB
@@ -739,6 +739,7 @@ static bool SDS_cmd(PmSensorCmd cmd) {
739739
memcpy_P(buf, version_cmd, cmd_len);
740740
break;
741741
}
742+
delay(100);
742743
serialSDS.write(buf, cmd_len);
743744
return cmd != PmSensorCmd::Stop;
744745
}
@@ -827,10 +828,10 @@ static String SDS_version_date() {
827828

828829
debug_outln_verbose(FPSTR(DBG_TXT_END_READING), FPSTR(DBG_TXT_SDS011_VERSION_DATE));
829830

831+
delay(100);
830832
is_SDS_running = SDS_cmd(PmSensorCmd::Start);
831833

832834
delay(100);
833-
834835
is_SDS_running = SDS_cmd(PmSensorCmd::VersionDate);
835836

836837
delay(500);
@@ -1090,30 +1091,35 @@ static void writeConfig() {
10901091
* Prepare information for data Loggers *
10911092
*****************************************************************/
10921093
static void createLoggerConfigs() {
1094+
#if defined(ESP8266)
1095+
auto new_session = []() { return new BearSSL::Session; };
1096+
#else
1097+
auto new_session = []() { return nullptr; };
1098+
#endif
10931099
if (cfg::send2dusti) {
10941100
loggerConfigs[LoggerSensorCommunity].destport = 80;
10951101
if (cfg::ssl_dusti) {
10961102
loggerConfigs[LoggerSensorCommunity].destport = 443;
1097-
loggerConfigs[LoggerSensorCommunity].session = new BearSSL::Session;
1103+
loggerConfigs[LoggerSensorCommunity].session = new_session();
10981104
}
10991105
}
11001106
loggerConfigs[LoggerMadavi].destport = PORT_MADAVI;
11011107
if (cfg::send2madavi && cfg::ssl_madavi) {
11021108
loggerConfigs[LoggerMadavi].destport = 443;
1103-
loggerConfigs[LoggerMadavi].session = new BearSSL::Session;
1109+
loggerConfigs[LoggerMadavi].session = new_session();
11041110
}
11051111
loggerConfigs[LoggerSensemap].destport = PORT_SENSEMAP;
1106-
loggerConfigs[LoggerSensemap].session = new BearSSL::Session;
1112+
loggerConfigs[LoggerSensemap].session = new_session();
11071113
loggerConfigs[LoggerFSapp].destport = PORT_FSAPP;
1108-
loggerConfigs[LoggerFSapp].session = new BearSSL::Session;
1114+
loggerConfigs[LoggerFSapp].session = new_session();
11091115
loggerConfigs[Loggeraircms].destport = PORT_AIRCMS;
11101116
loggerConfigs[LoggerInflux].destport = cfg::port_influx;
11111117
if (cfg::send2influx && cfg::ssl_influx) {
1112-
loggerConfigs[LoggerInflux].session = new BearSSL::Session;
1118+
loggerConfigs[LoggerInflux].session = new_session();
11131119
}
11141120
loggerConfigs[LoggerCustom].destport = cfg::port_custom;
11151121
if (cfg::send2custom && (cfg::ssl_custom || (cfg::port_custom == 443))) {
1116-
loggerConfigs[LoggerCustom].session = new BearSSL::Session;
1122+
loggerConfigs[LoggerCustom].session = new_session();
11171123
}
11181124
}
11191125

@@ -1882,6 +1888,7 @@ static void webserver_values() {
18821888
page_content += FPSTR(EMPTY_ROW);
18831889
add_table_row_from_value(page_content, FPSTR(SENSORS_SDS011), FPSTR(WEB_PM25), check_display_value(last_value_SDS_P2, -1, 1, 0), unit_PM);
18841890
add_table_row_from_value(page_content, FPSTR(SENSORS_SDS011), FPSTR(WEB_PM10), check_display_value(last_value_SDS_P1, -1, 1, 0), unit_PM);
1891+
add_table_row_from_value(page_content, FPSTR(SENSORS_SDS011), F("Version"), SDS_version_date(), emptyString);
18851892
}
18861893
if (cfg::pms_read) {
18871894
page_content += FPSTR(EMPTY_ROW);
@@ -2337,6 +2344,9 @@ static void connectWifi() {
23372344
last_signal_strength = WiFi.RSSI();
23382345
}
23392346

2347+
#if defined(ESP8266)
2348+
BearSSL::X509List x509_dst_root_ca(dst_root_ca_x3);
2349+
23402350
static void configureCACertTrustAnchor(WiFiClientSecure* client) {
23412351
constexpr time_t fw_built_year = (__DATE__[ 7] - '0') * 1000 + \
23422352
(__DATE__[ 8] - '0') * 100 + \
@@ -2350,12 +2360,14 @@ static void configureCACertTrustAnchor(WiFiClientSecure* client) {
23502360
client->setTrustAnchors(&x509_dst_root_ca);
23512361
}
23522362
}
2363+
#endif
23532364

23542365
static WiFiClient* getNewLoggerWiFiClient(const LoggerEntry logger) {
23552366

23562367
WiFiClient* _client;
23572368
if (loggerConfigs[logger].session) {
23582369
_client = new WiFiClientSecure;
2370+
#if defined(ESP8266)
23592371
static_cast<WiFiClientSecure*>(_client)->setSession(loggerConfigs[logger].session);
23602372
static_cast<WiFiClientSecure*>(_client)->setBufferSizes(1024, TCP_MSS > 1024 ? 2048 : 1024);
23612373
switch (logger) {
@@ -2368,6 +2380,7 @@ static WiFiClient* getNewLoggerWiFiClient(const LoggerEntry logger) {
23682380
default:
23692381
configureCACertTrustAnchor(static_cast<WiFiClientSecure*>(_client));
23702382
}
2383+
#endif
23712384
} else {
23722385
_client = new WiFiClient;
23732386
}
@@ -2415,15 +2428,16 @@ static unsigned long sendData(const LoggerEntry logger, const String& data, cons
24152428
if (pin) {
24162429
http.addHeader(F("X-PIN"), String(pin));
24172430
}
2431+
24182432
int result = http.POST(data);
2419-
http.end();
24202433

24212434
if (result >= HTTP_CODE_OK && result <= HTTP_CODE_ALREADY_REPORTED) {
24222435
debug_outln_info(F("Succeeded - "), s_Host);
24232436
} else if (result >= HTTP_CODE_BAD_REQUEST) {
24242437
debug_outln_info(F("Request failed with error: "), String(result));
24252438
debug_outln_info(F("Details:"), http.getString());
24262439
}
2440+
http.end();
24272441
} else {
24282442
debug_outln_info(F("Failed connecting to "), s_Host);
24292443
}
@@ -2775,9 +2789,8 @@ static void fetchSensorSDS(String& s) {
27752789
pm25_serial = 0;
27762790
checksum_is = 0;
27772791
}
2778-
yield();
27792792
}
2780-
2793+
yield();
27812794
}
27822795
if (send_now) {
27832796
last_value_SDS_P1 = -1;
@@ -2937,10 +2950,10 @@ static void fetchSensorPMS(String& s) {
29372950
checksum_is = 0;
29382951
}
29392952
}
2940-
yield();
29412953
}
2942-
2954+
yield();
29432955
}
2956+
29442957
if (send_now) {
29452958
last_value_PMS_P0 = -1;
29462959
last_value_PMS_P1 = -1;
@@ -3076,8 +3089,8 @@ static void fetchSensorHPM(String& s) {
30763089
checksum_is = 0;
30773090
}
30783091
}
3079-
yield();
30803092
}
3093+
yield();
30813094

30823095
}
30833096
if (send_now) {
@@ -3958,6 +3971,8 @@ static void powerOnTestSensors() {
39583971
delay(100);
39593972
debug_outln_info(F("Stopping SDS011..."));
39603973
is_SDS_running = SDS_cmd(PmSensorCmd::Stop);
3974+
delay(100);
3975+
serialSDS.flush();
39613976
}
39623977

39633978
if (cfg::pms_read) {
@@ -3968,6 +3983,8 @@ static void powerOnTestSensors() {
39683983
delay(100);
39693984
debug_outln_info(F("Stopping PMS..."));
39703985
is_PMS_running = PMS_cmd(PmSensorCmd::Stop);
3986+
delay(100);
3987+
serialSDS.flush();
39713988
}
39723989

39733990
if (cfg::hpm_read) {
@@ -3978,6 +3995,8 @@ static void powerOnTestSensors() {
39783995
delay(100);
39793996
debug_outln_info(F("Stopping HPM..."));
39803997
is_HPM_running = HPM_cmd(PmSensorCmd::Stop);
3998+
delay(100);
3999+
serialSDS.flush();
39814000
}
39824001

39834002
if (cfg::sps30_read) {
@@ -4201,6 +4220,8 @@ void setup(void) {
42014220
esp_chipid += String((uint32_t)chipid_num, HEX);
42024221
#endif
42034222
cfg::initNonTrivials(esp_chipid.c_str());
4223+
WiFi.persistent(false);
4224+
42044225
debug_outln_info(F("Airrohr: "), SOFTWARE_VERSION);
42054226

42064227
init_config();

airrohr-firmware/ext_def.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ enum LoggerEntry {
4545
struct LoggerConfig {
4646
uint16_t destport;
4747
uint16_t _unused;
48+
#if defined(ESP8266)
4849
BearSSL::Session* session;
50+
#else
51+
void* session;
52+
#endif
4953
};
5054

5155
// IMPORTANT: NO MORE CHANGES TO VARIABLE NAMES NEEDED FOR EXTERNAL APIS

airrohr-firmware/platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ lib_deps_generic_external =
3838
Adafruit BMP085 [email protected]
3939
Adafruit HTU21DF [email protected]
4040
Adafruit SHT31 [email protected]
41-
ArduinoJson@6.12.0
41+
ArduinoJson@6.13.0
4242
4343
4444
[email protected] ; TinyGPSPlus, formerly this was referenced as mikalhart/TinyGPSPlus#v0.95

0 commit comments

Comments
 (0)