Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta #462

Merged
merged 42 commits into from
Sep 11, 2019
Merged

Beta #462

Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6afb681
fixed prototype of loop() and setup()
nospam2000 Sep 8, 2019
826555e
use existing ESP32 serial port instances
nospam2000 Sep 8, 2019
e9516bc
fixed sntp initialization for ESP32
nospam2000 Sep 8, 2019
1339700
fixed reading/write config.json
nospam2000 Sep 8, 2019
945ce7e
fixed config.json serialization of ints
nospam2000 Sep 8, 2019
bfb2a96
fixed serialization of numeric values inf config,json
nospam2000 Sep 8, 2019
d88f98c
removed unnecessary .as() and typeof() to fix compile error
nospam2000 Sep 9, 2019
9fb6f87
reworked lib dependencies
nospam2000 Sep 9, 2019
7276094
back to esp8266 platform 1.8.0
nospam2000 Sep 9, 2019
87d430e
added comment for build_flags -Wl,T option
nospam2000 Sep 9, 2019
94a20af
exclude ESP32 targets from automatic builds
nospam2000 Sep 9, 2019
97d45ff
removed 'default_envs' because not supported by PIO Core v3.6.7
nospam2000 Sep 9, 2019
063615a
commented esp32 target
nospam2000 Sep 9, 2019
8ecb0af
uncommented esp32 target
nospam2000 Sep 9, 2019
d4d2988
ESP32 IO mapping for Lolin D32 Pro board
nospam2000 Sep 10, 2019
13c14a3
fixed compile error
nospam2000 Sep 10, 2019
ad3031e
restructured pin assignments
nospam2000 Sep 10, 2019
8a4c56d
fixed define for ESP32 boards
nospam2000 Sep 10, 2019
d3a8672
reactivated code for OLED reset
nospam2000 Sep 10, 2019
05f2cc2
excluded .pio dir
nospam2000 Sep 10, 2019
3b9a827
fixed merge errors
nospam2000 Sep 10, 2019
44bedf2
commented out ESP32 targets to make Travis work
nospam2000 Sep 10, 2019
485d6f7
fixed merge problems
nospam2000 Sep 10, 2019
b24bc00
enabled ESP32 again
nospam2000 Sep 10, 2019
2cab340
debugger configuration, adapt to your needs
nospam2000 Sep 10, 2019
2d165c9
refinement of ESP32 board definitions
nospam2000 Sep 11, 2019
6b51740
added comment for SoftwareSerial
nospam2000 Sep 11, 2019
3e3f202
added upload+monitor port to nodemcuv2
nospam2000 Sep 11, 2019
1ec6f80
Revert "removed unnecessary .as() and typeof() to fix compile error"
nospam2000 Sep 11, 2019
131068a
Revert "fixed serialization of numeric values inf config,json"
nospam2000 Sep 11, 2019
ed3b909
Revert "fixed config.json serialization of ints"
nospam2000 Sep 11, 2019
bc03758
Revert "fixed reading/write config.json"
nospam2000 Sep 11, 2019
cfc8b01
Revert "fixed sntp initialization for ESP32"
nospam2000 Sep 11, 2019
e9053db
Merge branch 'beta' of https://github.com/opendata-stuttgart/sensors-…
nospam2000 Sep 11, 2019
e1c680b
moved serialGPS.begin before powerOnTestSensors()
nospam2000 Sep 11, 2019
c6105f0
fixed I2C pin definition
nospam2000 Sep 11, 2019
d6daad7
removed SoftwareSerial from refs
nospam2000 Sep 11, 2019
6a11df8
extracted common includes
nospam2000 Sep 11, 2019
133c0f4
added workaround for ESP32 FPSTR bug
nospam2000 Sep 11, 2019
ba85a83
use explicit version of SoftwareSerial
nospam2000 Sep 11, 2019
9ac3145
removed upload settings
nospam2000 Sep 11, 2019
3d04417
renamed #define from JTAG_DEBUGGER to USING_JTAG_DEBUGGER_PINS
nospam2000 Sep 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 39 additions & 21 deletions airrohr-firmware/airrohr-firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ SoftwareSerial serialSDS(PM_SERIAL_RX, PM_SERIAL_TX, false, 128);
SoftwareSerial serialGPS(GPS_SERIAL_RX, GPS_SERIAL_TX, false, 512);
#endif
#if defined(ESP32)
HardwareSerial serialSDS(2);
HardwareSerial serialGPS(3);
#define serialSDS (Serial1)
#define serialGPS (Serial2)
#endif

/*****************************************************************
Expand Down Expand Up @@ -731,15 +731,25 @@ String Var2Json(const String& name, const String& value) {
/*****************************************************************
* convert boolean value to json string *
*****************************************************************/
String Var2Json(const String& name, const bool value) {
return Var2Json(name, String(value ? "true" : "false"));
String Var2JsonBool(const String& name, const bool value) {
String s = "\"";
s += name;
s += "\":";
s += value ? "true" : "false";
s += ",";
return s;
}

/*****************************************************************
* convert boolean value to json string *
* convert int value to json string *
*****************************************************************/
String Var2Json(const String& name, const int value) {
return Var2Json(name, String(value));
String Var2JsonLong(const String& name, const long value) {
String s = "\"";
s += name;
s += "\":";
s += Float2String(value, 0);
s += ",";
return s;
}

/*****************************************************************
Expand Down Expand Up @@ -995,8 +1005,8 @@ void readConfig() {
strcpy(version_from_local_config, json["SOFTWARE_VERSION"]);
}

#define setFromJSON(key) if (json.containsKey(#key)) key = json[#key];
#define strcpyFromJSON(key) if (json.containsKey(#key)) strcpy(key, json[#key]);
#define setFromJSON(key) if (json.containsKey(#key)) {key = json[#key]; }
#define strcpyFromJSON(key) if (json.containsKey(#key)) {strcpy(key, json[#key]); }
strcpyFromJSON(current_lang);
strcpyFromJSON(wlanssid);
strcpyFromJSON(wlanpwd);
Expand Down Expand Up @@ -1098,8 +1108,8 @@ void writeConfig() {
String json_string = "{";
debug_outln(F("saving config..."), DEBUG_MIN_INFO);

#define copyToJSON_Bool(varname) json_string += Var2Json(#varname, varname);
#define copyToJSON_Int(varname) json_string += Var2Json(#varname, varname);
#define copyToJSON_Bool(varname) json_string += Var2JsonBool(#varname, varname);
#define copyToJSON_Int(varname) json_string += Var2JsonLong(#varname, varname);
#define copyToJSON_String(varname) json_string += Var2Json(#varname, String(varname));
copyToJSON_String(current_lang);
copyToJSON_String(SOFTWARE_VERSION);
Expand Down Expand Up @@ -1143,9 +1153,9 @@ void writeConfig() {
copyToJSON_Bool(has_lcd2004_27);
copyToJSON_Bool(display_wifi_info);
copyToJSON_Bool(display_device_info);
copyToJSON_String(debug);
copyToJSON_String(sending_intervall_ms);
copyToJSON_String(time_for_wifi_config);
copyToJSON_Int(debug);
copyToJSON_Int(sending_intervall_ms);
copyToJSON_Int(time_for_wifi_config);
copyToJSON_String(senseboxid);
copyToJSON_Bool(send2custom);
copyToJSON_String(host_custom);
Expand Down Expand Up @@ -4225,11 +4235,15 @@ static bool acquireNetworkTime() {
#if defined(ESP8266)
settimeofday_cb(time_is_set);
#endif
configTime(8 * 3600, 0, "pool.ntp.org");
configTime(0, 0, "pool.ntp.org"); // using UTC as timezone
while (retryCount++ < 20) {
// later than 2000/01/01:00:00:00
now = time(nullptr);
#if defined(ESP8266)
if (sntp_time_is_set) {
now = time(nullptr);
#endif
#if defined(ESP32)
if (now > 17897*24*60*60) { // later than 2019/01/01:00:00:00
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is sntp_time_is_set now only used for ESP8266?

Copy link
Contributor Author

@nospam2000 nospam2000 Sep 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because settimeofday_cb() is not available for ESP32. The examples are using sntp_set_time_sync_notification_cb() but this is not yet available in the newest esp32platform delivered with platformio.

/edit: see also https://github.com/espressif/esp-idf/tree/master/examples/protocols/sntp

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, thanks

#endif
debug_outln(ctime(&now), DEBUG_MIN_INFO);
return true;
}
Expand All @@ -4240,9 +4254,13 @@ static bool acquireNetworkTime() {
retryCount = 0;
configTime(0, 0, WiFi.gatewayIP().toString().c_str());
while (retryCount++ < 20) {
// later than 2000/01/01:00:00:00
now = time(nullptr);
#if defined(ESP8266)
if (sntp_time_is_set) {
now = time(nullptr);
#endif
#if defined(ESP32)
if (now > 17897*24*60*60) { // later than 2019/01/01:00:00:00
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't that mean that sntp_time_is_set should not be true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I understood your questions correctly.
sntp_time_is_set is initialized with false and only set in the callback time_is_set().
When the callback is called in the first try with "ntp.org", the second part (the change from line 4247 to 4252) will never be reached because the function returns.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I agree with your assessment, sorry, didn't read the code closely. I wonder if we can remove all of the ESP conditionals in the code and use both code paths the same way?

Copy link
Contributor Author

@nospam2000 nospam2000 Sep 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in this specific case the ESP32 path will work for both. The error checking of the ESP8266 is more strict. The fallback in the ESP32 case to use the local router will not be triggered if the RTC has a date after 2019-01-01 and this will happen on a reboot.

That means:

  • when ntp.org cannot be reached on the first boot it will fallback to the local router
  • on the second boot the RTC will already have a valid date and don't do a fallback to the local router. /edit: this means the time will not by synchronized any longer and start to drift

To solve that, I would remove the fallback and replace it by the following solution:
Set multiple servers with one call:

  1. ntp.org
  2. the ntp server(s) announced by dhcp
  3. the local router (actually this shall not be necessary because in many cases this is already covered by 2.)

roughly the code would be the following, but I need to check how to mix dhcp and fixed servers:

sntp_servermode_dhcp(1);
sntp_setservername(0, "pool.ntp.org");
sntp_setserver(1, WiFi.gatewayIP());

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would try local first before going to the internet.. I implemented router/pool in my pr that I just opened.

Searching for ntp information in dhcp does sound like a good idea though.

#endif
debug_outln(ctime(&now), DEBUG_MIN_INFO);
return true;
}
Expand Down Expand Up @@ -4317,7 +4335,7 @@ static unsigned long sendDataToOptionalApis(const String &data) {
/*****************************************************************
* The Setup *
*****************************************************************/
void setup() {
void setup(void) {
Serial.begin(9600); // Output to Serial at 9600 baud

#if defined(ESP32)
Expand Down Expand Up @@ -4390,7 +4408,7 @@ void setup() {
/*****************************************************************
* And action *
*****************************************************************/
void loop() {
void loop(void) {
String result_PPD, result_SDS, result_PMS, result_HPM, result_SPS30;
String result_DHT, result_HTU21D, result_BMP, result_BMP280;
String result_BME280, result_DS18B20, result_GPS, result_DNMS;
Expand Down
117 changes: 90 additions & 27 deletions airrohr-firmware/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,90 @@ src_dir = .

[common]
build_flags =
-DESP8266 ; as hint for ldf
-DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
-DVTABLES_IN_FLASH
-DNDEBUG
-Wl,-Teagle.flash.4m.ld
-Wl,-Teagle.flash.4m.ld ; required for platform == [email protected]
; -Wl,-Teagle.flash.4m3m.ld ; required for platform >= [email protected] to make SPIFFS work

build_flags_esp32 =
-DESP32 ; as hint for ldf
-DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
-DVTABLES_IN_FLASH
build_flags_esp32_release = ${common.build_flags_esp32} -DNDEBUG
build_flags_esp32_debug = ${common.build_flags_esp32} -g -Og -fno-inline -DJTAG_DEBUGGER=1 -DDEBUG_ESP_PORT=Serial

board_build.f_cpu = 160000000L
; Always depend on specific library versions (wherever possible)
; Keep Library names in alphabetical order
; 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
; TinyGPSPlus is not yet in platformio - https://github.com/platformio/platformio-libmirror/issues/99
lib_deps_external =
; Use library ID numbers instead of names for libraries whose names are not unique
; (like OneWire, LiquidCrystal_I2C and TinyGPSPlus)

lib_deps_generic_external =
[email protected] ; OneWire
[email protected] ; LiquidCrystal_I2C
;136 ; LiquidCrystal, alternative to 576 LiquidCrystal_I2C?
Adafruit Unified [email protected]
Adafruit BMP085 [email protected]
Adafruit BMP280 [email protected]
Adafruit BME280 [email protected]
Adafruit HTU21DF [email protected]
ArduinoJson@6.11.5
ArduinoJson@6.12.0
[email protected]
[email protected]
[email protected] ; TinyGPSPlus, formerly this was referenced as mikalhart/TinyGPSPlus#v0.95

lib_deps_esp8266_external =
;[email protected] ; the latest version available in platformio
;plerup/espsoftwareserial#5.2.9 ; this version needs unpublished 8266 plaform, see https://github.com/plerup/espsoftwareserial/issues/103
;plerup/espsoftwareserial#5.0.3 ; this version compiles with esp8266 platform version 2.2.3
plerup/espsoftwareserial#4.0.0 ; this version compiles with esp8266 platform version 1.8.0

lib_deps_esp32_external =

; system libraries from platform -> no version number
lib_deps_esp8266_platform =
Hash
Wire
SPI
ESP8266WiFi
DNSServer
ESP8266HTTPClient
ESP8266WebServer
ESP8266WiFi
[email protected]
ESP8266httpUpdate
ESP8266mDNS
[email protected]
SPI
mikalhart/TinyGPSPlus#v0.95

; system libraries from platform -> no version number
lib_deps_esp32_platform =
Wire
[email protected]
[email protected]
SPI
WiFi
DNSServer
WiFiClientSecure
HTTPClient
FS
SPIFFS
WebServer
Update
HTTPUpdate
ESPmDNS

lib_deps_esp8266 = ${common.lib_deps_esp8266_platform} ${common.lib_deps_esp8266_external} ${common.lib_deps_generic_external}
lib_deps_esp32 = ${common.lib_deps_esp32_platform} ${common.lib_deps_esp32_external} ${common.lib_deps_generic_external}

extra_scripts = platformio_script.py
# This release is reflecting the Arduino Core 2.4.2 release
# When the requirement for Arduino Core is raised, this
# needs to be adjusted to the matching version from
# https://github.com/platformio/platform-espressif8266/releases
platform_version = [email protected]
;platform_version = [email protected] ; using Arduino core 2.5.2
[env]
;lib_ldf_mode = chain+
lib_ldf_mode = off
;lib_compat_mode = strict

[env:nodemcuv2]
lang = DE
Expand All @@ -57,7 +105,7 @@ framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
build_flags = ${common.build_flags} '-DINTL_DE'
lib_deps = ${common.lib_deps_external}
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}

[env:nodemcuv2_bg]
Expand All @@ -67,7 +115,7 @@ framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
build_flags = ${common.build_flags} '-DINTL_BG'
lib_deps = ${common.lib_deps_external}
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}

[env:nodemcuv2_cz]
Expand All @@ -77,7 +125,7 @@ platform = ${common.platform_version}
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
build_flags = ${common.build_flags} '-DINTL_CZ'
lib_deps = ${common.lib_deps_external}
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}

[env:nodemcuv2_dk]
Expand All @@ -87,7 +135,7 @@ framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
build_flags = ${common.build_flags} '-DINTL_DK'
lib_deps = ${common.lib_deps_external}
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}

[env:nodemcuv2_en]
Expand All @@ -97,7 +145,7 @@ framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
build_flags = ${common.build_flags} '-DINTL_EN'
lib_deps = ${common.lib_deps_external}
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}

[env:nodemcuv2_es]
Expand All @@ -107,7 +155,7 @@ framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
build_flags = ${common.build_flags} '-DINTL_ES'
lib_deps = ${common.lib_deps_external}
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}

[env:nodemcuv2_fr]
Expand All @@ -117,7 +165,7 @@ framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
build_flags = ${common.build_flags} '-DINTL_FR'
lib_deps = ${common.lib_deps_external}
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}

[env:nodemcuv2_it]
Expand All @@ -127,7 +175,7 @@ framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
build_flags = ${common.build_flags} '-DINTL_IT'
lib_deps = ${common.lib_deps_external}
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}

[env:nodemcuv2_lu]
Expand All @@ -137,7 +185,7 @@ framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
build_flags = ${common.build_flags} '-DINTL_LU'
lib_deps = ${common.lib_deps_external}
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}

[env:nodemcuv2_nl]
Expand All @@ -147,7 +195,7 @@ framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
build_flags = ${common.build_flags} '-DINTL_NL'
lib_deps = ${common.lib_deps_external}
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}

[env:nodemcuv2_pl]
Expand All @@ -157,7 +205,7 @@ framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
build_flags = ${common.build_flags} '-DINTL_PL'
lib_deps = ${common.lib_deps_external}
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}

[env:nodemcuv2_pt]
Expand All @@ -167,7 +215,7 @@ framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
build_flags = ${common.build_flags} '-DINTL_PT'
lib_deps = ${common.lib_deps_external}
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}

[env:nodemcuv2_ru]
Expand All @@ -177,7 +225,7 @@ framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
build_flags = ${common.build_flags} '-DINTL_RU'
lib_deps = ${common.lib_deps_external}
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}

[env:nodemcuv2_se]
Expand All @@ -187,5 +235,20 @@ framework = arduino
board = nodemcuv2
board_build.f_cpu = ${common.board_build.f_cpu}
build_flags = ${common.build_flags} '-DINTL_SE'
lib_deps = ${common.lib_deps_external}
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}

[env:lolin_d32_pro_debug]
lang = DE
platform = espressif32
framework = arduino
board = lolin_d32_pro
build_flags = ${common.build_flags_esp32_debug} '-DINTL_DE'
lib_deps = ${common.lib_deps_esp32}
extra_scripts = ${common.extra_scripts}
debug_tool = custom
monitor_speed = 9600
upload_port = /dev/cu.wchusbserial40
monitor_port = /dev/cu.wchusbserial40
targets = debug