Updated code to 0.6 test

This commit is contained in:
Magnus Persson
2022-01-10 20:14:58 +01:00
parent ea62d9e752
commit 2f391c95c7
5 changed files with 46 additions and 19 deletions

View File

@ -210,11 +210,9 @@ bool loopReadGravity() {
float temp = myTempSensor.getTempC(); float temp = myTempSensor.getTempC();
LOG_PERF_STOP("loop-temp-read"); LOG_PERF_STOP("loop-temp-read");
float gravity = calculateGravity( float gravity = calculateGravity(angle, temp);
angle, temp); // Takes less than 2ms , so skip this measurment
float corrGravity = gravityTemperatureCorrection( float corrGravity = gravityTemperatureCorrection(
gravity, temp, myConfig.getTempFormat()); // Takes less than 2ms , so gravity, temp, myConfig.getTempFormat());
// skip this measurment
#if LOG_LEVEL == 6 && !defined(MAIN_DISABLE_LOGGING) #if LOG_LEVEL == 6 && !defined(MAIN_DISABLE_LOGGING)
Log.verbose(F("Main: Sensor values gyro angle=%F, temp=%F, gravity=%F, " Log.verbose(F("Main: Sensor values gyro angle=%F, temp=%F, gravity=%F, "
@ -261,10 +259,11 @@ void loopGravityOnInterval() {
// //
void goToSleep(int sleepInterval) { void goToSleep(int sleepInterval) {
float volt = myBatteryVoltage.getVoltage(); float volt = myBatteryVoltage.getVoltage();
float runtime = (millis() - runtimeMillis);
Log.notice(F("MAIN: Entering deep sleep for %d s, run time %l s, " Log.notice(F("MAIN: Entering deep sleep for %ds, run time %Fs, "
"battery=%F V." CR), "battery=%FV." CR),
sleepInterval, (millis() - runtimeMillis) / 1000, volt); sleepInterval, reduceFloatPrecision(runtime/1000, 2), volt);
LittleFS.end(); LittleFS.end();
myGyro.enterSleep(); myGyro.enterSleep();
LOG_PERF_STOP("run-time"); LOG_PERF_STOP("run-time");
@ -282,6 +281,7 @@ void loop() {
myWebServer.loop(); myWebServer.loop();
myWifi.loop(); myWifi.loop();
loopGravityOnInterval(); loopGravityOnInterval();
myBatteryVoltage.read();
break; break;
case RunMode::gravityMode: case RunMode::gravityMode:

View File

@ -141,13 +141,10 @@ void WifiConnection::startPortal() {
void WifiConnection::loop() { myDRD->loop(); } void WifiConnection::loop() { myDRD->loop(); }
// //
// Connect to last known access point or create one if connection is not // Connect to last known access point, non blocking mode.
// working.
// //
bool WifiConnection::connect() { void WifiConnection::connectAsync() {
// Connect to wifi WiFi.persistent(true);
int i = 0;
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
if (strlen(userSSID)) { if (strlen(userSSID)) {
Log.notice(F("WIFI: Connecting to wifi using hardcoded settings %s." CR), Log.notice(F("WIFI: Connecting to wifi using hardcoded settings %s." CR),
@ -158,14 +155,22 @@ bool WifiConnection::connect() {
myConfig.getWifiSSID()); myConfig.getWifiSSID());
WiFi.begin(myConfig.getWifiSSID(), myConfig.getWifiPass()); WiFi.begin(myConfig.getWifiSSID(), myConfig.getWifiPass());
} }
}
// WiFi.printDiag(Serial); //
// Blocks until wifi connection has been found
//
bool WifiConnection::waitForConnection(int maxTime) {
#if DEBUG_LEVEL == 6
WiFi.printDiag(Serial);
#endif
int i = 0;
while (WiFi.status() != WL_CONNECTED) { while (WiFi.status() != WL_CONNECTED) {
delay(200); delay(100);
Serial.print(".");
if (i++ > 100) { // Try for 20 seconds. if ( i % 10 ) Serial.print(".");
if (i++ > (maxTime*10)) { // Try for maxTime seconds. Since delay is 100ms.
Log.error(F("WIFI: Failed to connect to wifi %d, aborting %s." CR), Log.error(F("WIFI: Failed to connect to wifi %d, aborting %s." CR),
WiFi.status(), getIPAddress().c_str()); WiFi.status(), getIPAddress().c_str());
WiFi.disconnect(); WiFi.disconnect();
@ -180,6 +185,14 @@ bool WifiConnection::connect() {
return true; return true;
} }
//
// Connect to last known access point, blocking mode.
//
bool WifiConnection::connect() {
connectAsync();
return waitForConnection(20); // 20 seconds.
}
// //
// This will erase the stored credentials and forcing the WIFI manager to AP // This will erase the stored credentials and forcing the WIFI manager to AP
// mode. // mode.

View File

@ -36,6 +36,8 @@ class WifiConnection {
bool newFirmware = false; bool newFirmware = false;
bool parseFirmwareVersionString(int (&num)[3], const char *version); bool parseFirmwareVersionString(int (&num)[3], const char *version);
void downloadFile(const char *fname); void downloadFile(const char *fname);
void connectAsync();
bool waitForConnection(int maxTime = 20);
public: public:
// WIFI // WIFI

View File

@ -30,6 +30,7 @@ be found here; `GravityMon on Github <https://github.com/mp-se/gravitymon>`_
I dont take responsibility for any errors that can cause problems with the use. I have tested v0.4 on 5+ brews I dont take responsibility for any errors that can cause problems with the use. I have tested v0.4 on 5+ brews
over the last 6 months without any issues. over the last 6 months without any issues.
The main differences: The main differences:
--------------------- ---------------------
@ -67,7 +68,7 @@ the following libraries and without these this would have been much more difficu
Can detect if the reset button is pressed twice, is used to enter WIFI config mode. Can detect if the reset button is pressed twice, is used to enter WIFI config mode.
* https://github.com/tzapu/WiFiManager * https://github.com/khoih-prog/ESP_WiFiManager
Configure wifi settings. Configure wifi settings.

View File

@ -3,6 +3,17 @@
Releases Releases
######## ########
v0.6.0 (work in progress)
-------------------------
This is features for the next release.
* Changed the wifi manager and refactored wifi.cpp
* LED is now turned on when Wifi Portal is open
* Refactored main.cpp to make it easier to read
* Tested runtime performance
* Improved documentation
v0.5.0 v0.5.0
------ ------