From 940520006a52128304078b84871d5f1d0c479460 Mon Sep 17 00:00:00 2001 From: Magnus Date: Thu, 27 May 2021 08:26:56 +0200 Subject: [PATCH] Update to wifi connection sequence + new perf target --- README.md | 6 ++++-- platformio.ini | 18 ++++++++++++++++++ script/copy_firmware.py | 2 ++ src/config.cpp | 7 +++++-- src/helper.cpp | 12 +++++++++--- src/helper.h | 1 + src/wifi.cpp | 8 +++++++- 7 files changed, 46 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e155e92..8a53569 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,8 @@ http://gravmon.local/config.htm "interval": 900, "temperature": 20.5, // C or F based on setting, adjusted value. "temp-units": "C", // C or F based on setting - "gravity": 1.0050, // + "gravity": 1.0050, // Raw or temperature corrected gravity (based on setting) + "corr-gravity": 1.0050, // Temperature corrected gravity "angle": 45.34, "battery": 3.67, "rssi": -12, @@ -100,8 +101,9 @@ http://gravmon.local/config.htm ### This is the format for InfluxDB v2 ``` -measurement,host=,device=,temp-format=,gravity-format=SG gravity=1.0004,angle=45.45,temp=20.1,battery=3.96,rssi=-18 +measurement,host=,device=,temp-format=,gravity-format=SG,gravity=1.0004,corr-gravity=1.0004,angle=45.45,temp=20.1,battery=3.96,rssi=-18 ``` + ![Config - Push](img/config2.png) * The third section contains the gravity formula and also option for doing temperature compensation. The calibration formula uses two keywords, temp and tilt. Temperature is in the selected device format. diff --git a/platformio.ini b/platformio.ini index cbfdda6..c432585 100644 --- a/platformio.ini +++ b/platformio.ini @@ -72,6 +72,24 @@ extra_scripts = script/copy_firmware.py script/create_versionjson.py build_unflags = ${common_env_data.build_unflags} +build_flags = + ${common_env_data.build_flags} + -D LOG_LEVEL=4 +lib_deps = + ${common_env_data.lib_deps} +board = ${common_env_data.board} +build_type = release +board_build.filesystem = littlefs + +[env:gravity-perf] +upload_speed = ${common_env_data.upload_speed} +monitor_speed = ${common_env_data.monitor_speed} +framework = ${common_env_data.framework} +platform = ${common_env_data.platform} +extra_scripts = + script/copy_firmware.py + script/create_versionjson.py +build_unflags = ${common_env_data.build_unflags} build_flags = ${common_env_data.build_flags} -D COLLECT_PERFDATA # This option will collect runtime data for a few defined methods to measure time, dumped to serial and/or influxdb diff --git a/script/copy_firmware.py b/script/copy_firmware.py index e49fc99..0b2cbb6 100644 --- a/script/copy_firmware.py +++ b/script/copy_firmware.py @@ -16,6 +16,8 @@ def after_build(source, target, env): target = dir + "\\bin\\firmware-debug.bin" if name == "gravity-release" : target = dir + "\\bin\\firmware.bin" + if name == "gravity-perf" : + target = dir + "\\bin\\firmware-perf.bin" print( "Copy file : " + source + " -> " + target ) shutil.copyfile( source, target ) diff --git a/src/config.cpp b/src/config.cpp index a0b77e6..ba66fc1 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -40,7 +40,7 @@ Config::Config() { setTempFormat('C'); setGravityFormat('G'); setSleepInterval(900); // 15 minutes - setVoltageFactor(1.59); // Conversion factor for battery + setVoltageFactor(1.59); // Conversion factor for battery setTempSensorAdj(0.0); setGravityTempAdj(false); gyroCalibration = { 0, 0, 0, 0, 0 ,0 }; @@ -185,6 +185,8 @@ bool Config::loadFile() { setVoltageFactor( doc[ CFG_PARAM_VOLTAGEFACTOR ].as() ); if( !doc[ CFG_PARAM_GRAVITY_FORMULA ].isNull() ) setGravityFormula( doc[ CFG_PARAM_GRAVITY_FORMULA ] ); + if( !doc[ CFG_PARAM_GRAVITY_TEMP_ADJ ].isNull() ) + setGravityTempAdj( doc[ CFG_PARAM_GRAVITY_TEMP_ADJ ].as() ); if( !doc[ CFG_PARAM_GRAVITY_FORMAT ].isNull() ) { String s = doc[ CFG_PARAM_GRAVITY_FORMAT ]; setGravityFormat( s.charAt(0) ); @@ -247,11 +249,12 @@ void Config::debug() { Log.verbose(F("CFG : mDNS; '%s'." CR), getMDNS() ); Log.verbose(F("CFG : Sleep interval; %d." CR), getSleepInterval() ); Log.verbose(F("CFG : OTA; '%s'." CR), getOtaURL() ); - Log.verbose(F("CFG : Temp; %c." CR), getTempFormat() ); + Log.verbose(F("CFG : Temp Format; %c." CR), getTempFormat() ); Log.verbose(F("CFG : Temp Adj; %F." CR), getTempSensorAdj() ); Log.verbose(F("CFG : VoltageFactor; %F." CR), getVoltageFactor() ); Log.verbose(F("CFG : Gravity formula; '%s'." CR), getGravityFormula() ); Log.verbose(F("CFG : Gravity format; '%c'." CR), getGravityFormat() ); + Log.verbose(F("CFG : Gravity temp adj; %s." CR), isGravityTempAdj()?"true":"false" ); Log.verbose(F("CFG : Push brewfather; '%s'." CR), getBrewfatherPushUrl() ); Log.verbose(F("CFG : Push http; '%s'." CR), getHttpPushUrl() ); Log.verbose(F("CFG : Push http2; '%s'." CR), getHttpPushUrl2() ); diff --git a/src/helper.cpp b/src/helper.cpp index f469179..5cee407 100644 --- a/src/helper.cpp +++ b/src/helper.cpp @@ -31,6 +31,15 @@ SOFTWARE. SerialDebug mySerial; BatteryVoltage myBatteryVoltage; +// +// Print the heap information. +// +void printHeap() { +#if LOG_LEVEL==6 + Log.verbose(F("HELP: Heap %d kb, HeapFrag %d %%, FreeSketch %d kb." CR), ESP.getFreeHeap()/1024, ESP.getHeapFragmentation(), ESP.getFreeSketchSpace()/1024 ); +#endif +} + // // Enter deep sleep for the defined duration (Argument is seconds) // @@ -50,9 +59,6 @@ void printBuildOptions() { #ifdef SKIP_SLEEPMODE "SKIP_SLEEP " #endif -#ifdef USE_GYRO_TEMP - "GYRO_TEMP " -#endif #ifdef EMBED_HTML "EMBED_HTML " #endif diff --git a/src/helper.h b/src/helper.h index 9abf35a..f06b9f3 100644 --- a/src/helper.h +++ b/src/helper.h @@ -40,6 +40,7 @@ float reduceFloatPrecision( float f, int dec = 2 ); // Logging via serial void printTimestamp(Print* _logOutput); void printNewline(Print* _logOutput); +void printHeap(); // Classes class SerialDebug { diff --git a/src/wifi.cpp b/src/wifi.cpp index 30ed0f2..3ea2c70 100644 --- a/src/wifi.cpp +++ b/src/wifi.cpp @@ -82,18 +82,24 @@ bool Wifi::connect( bool showPortal ) { int i = 0; Log.notice(F("WIFI: Connecting to WIFI." CR)); + WiFi.mode(WIFI_STA); if( strlen(userSSID) ) { Log.notice(F("WIFI: Connecting to wifi using predefined settings %s." CR), userSSID); WiFi.begin( userSSID, userPWD ); } else { WiFi.begin(); +#if LOG_LEVEL==6 + Log.debug(F("WIFI: Using SSID=%s, KEY=%s." CR), WiFi.SSID().c_str(), WiFi.psk().c_str() ); +#endif } while( WiFi.status() != WL_CONNECTED ) { delay(100); Serial.print( "." ); - if( i++ > 60 ) { // Try for 6 seconds. +// if( i++ > 60 ) { // Try for 6 seconds. + if( i++ > 200 ) { // Try for 20 seconds. + Log.error(F("WIFI: Failed to connect to wifi, aborting." CR)); return connectedFlag; // Return to main that we have failed to connect. } }