Skip to content

Commit

Permalink
Update to Arduino Core 2.7.4 (Fixes #753)
Browse files Browse the repository at this point in the history
This is a huge update, covering a much newer SoftwareSerial and
includes many fixes and optimisations. Unfortunately it deprecates
SPIFFS so we now have to live with compiler warnings until
we managed to find an upgrade path to littlefs.

Includes a fix for a WPA plain-text attack security issue so
we need to update, even though it increases FW quite a bit.
  • Loading branch information
dirkmueller committed Sep 2, 2020
1 parent 5da35f9 commit 2073565
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 164 deletions.
1 change: 1 addition & 0 deletions airrohr-firmware/Versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ NRZ-2020-130-B6
* Disabled IPv6 for stable release
* Force I2C clock to 100k for better compatibility with sensors (Fixes #735)
* Update ArduinoJson to 6.16.1
* Update ArduinoCore to 2.7.4 to fix WPA downgrade issue (CVE-2020-12638)

NRZ-2020-130-B5
* Slovak translations added
Expand Down
251 changes: 126 additions & 125 deletions airrohr-firmware/airrohr-cfg.h

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions airrohr-firmware/airrohr-cfg.h.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@
struct ConfigShapeEntry {
enum ConfigEntryType cfg_type;
unsigned short cfg_len;
const __FlashStringHelper* cfg_key;
const char* _cfg_key;
union {
void* as_void;
bool* as_bool;
unsigned int* as_uint;
char* as_str;
} cfg_val;
const __FlashStringHelper* cfg_key() const { return FPSTR(_cfg_key); }
};
enum ConfigShapeId {""", file=h)
Expand All @@ -99,7 +100,7 @@

for cfgentry in configshape_in.strip().split('\n'):
_, cfgkey = cfgentry.split()
print("const char CFG_KEY_", cfgkey.upper(),
print("static constexpr char CFG_KEY_", cfgkey.upper(),
"[] PROGMEM = \"", cfgkey, "\";", sep='', file=h)

print("static constexpr ConfigShapeEntry configShape[] PROGMEM = {",
Expand All @@ -108,7 +109,7 @@
cfgtype, cfgkey = cfgentry.split()
print("\t{ Config_Type_", cfgtype,
", sizeof(cfg::" + cfgkey + ")-1" if cfgtype in ('String', 'Password') else ", 0",
", FPSTR(CFG_KEY_", cfgkey.upper(),
"), ", "" if cfgtype in ('String', 'Password') else "&",
", CFG_KEY_", cfgkey.upper(),
", ", "" if cfgtype in ('String', 'Password') else "&",
"cfg::", cfgkey, " },", sep='', file=h)
print("};", file=h)
28 changes: 12 additions & 16 deletions airrohr-firmware/airrohr-firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,6 @@ static String SDS_version_date() {
const constexpr uint8_t header_cmd_response[2] = { 0xAA, 0xC5 };
while (serialSDS.find(header_cmd_response, sizeof(header_cmd_response))) {
uint8_t data[8];
yield_for_serial_buffer(sizeof(data));
unsigned r = serialSDS.readBytes(data, sizeof(data));
if (r == sizeof(data) && data[0] == 0x07 && SDS_checksum_valid(data)) {
char tmp[20];
Expand Down Expand Up @@ -629,20 +628,20 @@ static void readConfig(bool oldconfig = false) {
for (unsigned e = 0; e < sizeof(configShape)/sizeof(configShape[0]); ++e) {
ConfigShapeEntry c;
memcpy_P(&c, &configShape[e], sizeof(ConfigShapeEntry));
if (json[c.cfg_key].isNull()) {
if (json[c.cfg_key()].isNull()) {
continue;
}
switch (c.cfg_type) {
case Config_Type_Bool:
*(c.cfg_val.as_bool) = boolFromJSON(json, c.cfg_key);
*(c.cfg_val.as_bool) = boolFromJSON(json, c.cfg_key());
break;
case Config_Type_UInt:
case Config_Type_Time:
*(c.cfg_val.as_uint) = json[c.cfg_key].as<unsigned int>();
*(c.cfg_val.as_uint) = json[c.cfg_key()].as<unsigned int>();
break;
case Config_Type_String:
case Config_Type_Password:
strncpy(c.cfg_val.as_str, json[c.cfg_key].as<char*>(), c.cfg_len);
strncpy(c.cfg_val.as_str, json[c.cfg_key()].as<char*>(), c.cfg_len);
c.cfg_val.as_str[c.cfg_len] = '\0';
break;
};
Expand Down Expand Up @@ -722,15 +721,15 @@ static bool writeConfig() {
memcpy_P(&c, &configShape[e], sizeof(ConfigShapeEntry));
switch (c.cfg_type) {
case Config_Type_Bool:
json[c.cfg_key].set(*c.cfg_val.as_bool);
json[c.cfg_key()].set(*c.cfg_val.as_bool);
break;
case Config_Type_UInt:
case Config_Type_Time:
json[c.cfg_key].set(*c.cfg_val.as_uint);
json[c.cfg_key()].set(*c.cfg_val.as_uint);
break;
case Config_Type_Password:
case Config_Type_String:
json[c.cfg_key].set(c.cfg_val.as_str);
json[c.cfg_key()].set(c.cfg_val.as_str);
break;
};
}
Expand Down Expand Up @@ -851,7 +850,7 @@ static void add_form_input(String& page_content, const ConfigShapeId cfgid, cons
}
}
s.replace("{i}", info);
s.replace("{n}", String(c.cfg_key));
s.replace("{n}", String(c.cfg_key()));
s.replace("{v}", t_value);
s.replace("{l}", String(length));
page_content += s;
Expand All @@ -869,7 +868,7 @@ static String form_checkbox(const ConfigShapeId cfgid, const String& info, const
s.replace("{c}", emptyString);
};
s.replace("{i}", info);
s.replace("{n}", String(configShape[cfgid].cfg_key));
s.replace("{n}", String(configShape[cfgid].cfg_key()));
if (! linebreak) {
s.replace("<br/>", emptyString);
}
Expand Down Expand Up @@ -1205,7 +1204,7 @@ static void webserver_config_send_body_post(String& page_content) {
for (unsigned e = 0; e < sizeof(configShape)/sizeof(configShape[0]); ++e) {
ConfigShapeEntry c;
memcpy_P(&c, &configShape[e], sizeof(ConfigShapeEntry));
const String s_param(c.cfg_key);
const String s_param(c.cfg_key());
if (!server.hasArg(s_param)) {
continue;
}
Expand Down Expand Up @@ -2440,7 +2439,6 @@ static void fetchSensorSDS(String& s) {
while (serialSDS.available() >= 10 &&
serialSDS.find(header_measurement, sizeof(header_measurement))) {
uint8_t data[8];
yield_for_serial_buffer(sizeof(data));
unsigned r = serialSDS.readBytes(data, sizeof(data));
if (r == sizeof(data) && SDS_checksum_valid(data)) {
uint32_t pm25_serial = data[0] | (data[1] << 8);
Expand Down Expand Up @@ -2868,7 +2866,6 @@ static void fetchSensorNPM(String& s) {


while (serialSDS.available() > 0) {
// yield_for_serial_buffer(sizeof(data));
unsigned r = serialSDS.readBytes(data, sizeof(data));

if (r == sizeof(data) && NPM_checksum_valid_16(data)) {
Expand Down Expand Up @@ -3934,8 +3931,6 @@ static void powerOnTestSensors() {
while (!serialSDS.available()) {debug_outln_info(F("Wait for Serial..."));}

while (serialSDS.available() > 0) {

//yield_for_serial_buffer(sizeof(data));
unsigned r = serialSDS.readBytes(data, sizeof(data));

if (r == sizeof(data) && NPM_checksum_valid_4(data)) {
Expand Down Expand Up @@ -4222,8 +4217,8 @@ void setup(void) {
#endif
init_config();
init_display();
connectWifi();
setupNetworkTime();
connectWifi();
setup_webserver();
createLoggerConfigs();
debug_outln_info(F("\nChipId: "), esp_chipid);
Expand Down Expand Up @@ -4259,6 +4254,7 @@ void loop(void) {
String result_PPD, result_SDS, result_PMS, result_HPM;
String result_GPS, result_DNMS;


unsigned sum_send_time = 0;

act_micro = micros();
Expand Down
47 changes: 43 additions & 4 deletions airrohr-firmware/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,23 @@ build_flags =
-D PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH
-D HTTPCLIENT_1_1_COMPATIBLE=0 -D NO_GLOBAL_SERIAL=0
-DNDEBUG
-Wl,-Teagle.flash.4m3m.ld

build_flags_esp32 =
-DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
-DVTABLES_IN_FLASH -DBEARSSL_SSL_BASIC
build_flags_esp32_release = ${common.build_flags_esp32} -DNDEBUG
build_flags_esp32_debug = ${common.build_flags_esp32} -g -Og -fno-inline -DUSING_JTAG_DEBUGGER_PINS=1 -DDEBUG_ESP_PORT=Serial

board_build.ldscript = eagle.flash.4m3m.ld
board_build.filesystem = spiffs
board_build.f_cpu = 160000000L
; Always depend on specific library versions (wherever possible and only for external libraries)
; Keep Library names in the order of their dependencies (leaves at the top)
; ESP8266WiFi in both cases is necessary to solve a case sensitivity issue with WiFiUdp.h
; Use library ID numbers instead of names for libraries whose names are not unique
; (like OneWire, LiquidCrystal_I2C and TinyGPSPlus)

lib_deps_generic_external =
lib_deps_external =
1@2.3.5 ; OneWire
576@1.1.4 ; LiquidCrystal_I2C
Adafruit BMP085 Library@1.0.1
Expand Down Expand Up @@ -75,8 +76,8 @@ lib_deps_esp32_platform =
Update
ESPmDNS

lib_deps_esp8266 = ${common.lib_deps_esp8266_platform} ${common.lib_deps_generic_external}
lib_deps_esp32 = ${common.lib_deps_esp32_platform} ${common.lib_deps_generic_external}
lib_deps_esp8266 = ${common.lib_deps_esp8266_platform} ${common.lib_deps_external}
lib_deps_esp32 = ${common.lib_deps_esp32_platform} ${common.lib_deps_external}

extra_scripts = platformio_script.py
# This release is reflecting the Arduino Core 2.6.2 release
Expand Down Expand Up @@ -119,6 +120,8 @@ check_tool = clangtidy
check_flags =
clangtidy: --checks=-*,cert-*,bugprone-*,clang-analyzer-*,hicpp-*,modernize-*,performance-*,portability-*,-readability-*
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_DE
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -129,6 +132,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_BG
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -139,6 +144,8 @@ framework = arduino
platform = ${common.platform_version}
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_CZ
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -149,6 +156,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_DK
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -159,6 +168,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_EN
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -169,6 +180,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_ES
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -179,6 +192,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_FR
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -189,6 +204,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_HU
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -199,6 +216,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_IT
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -209,6 +228,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_LU
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -219,6 +240,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_NL
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -229,6 +252,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_PL
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -239,6 +264,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_PT
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -249,6 +276,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_RS
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -259,6 +288,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_RU
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -269,6 +300,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_SE
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -279,6 +312,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_SK
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -289,6 +324,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_TR
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
Expand All @@ -299,6 +336,8 @@ platform = ${common.platform_version}
framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_UA
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}
14 changes: 0 additions & 14 deletions airrohr-firmware/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,20 +534,6 @@ void NPM_cmd(PmSensorCmd2 cmd) {
serialSDS.write(buf, cmd_len);
}

// workaround for https://github.com/plerup/espsoftwareserial/issues/127
void yield_for_serial_buffer(size_t length) {
unsigned long startMillis = millis();
unsigned long yield_timeout = length * 9 * 1000 / 9600;

while (serialSDS.available() < (int) length &&
millis() - startMillis < yield_timeout) {
yield();
#if defined(ESP8266)
serialSDS.perform_work();
#endif
}
}

const __FlashStringHelper* loggerDescription(unsigned i) {
const __FlashStringHelper* logger = nullptr;
switch (i) {
Expand Down
Loading

0 comments on commit 2073565

Please sign in to comment.