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

View File

@ -141,13 +141,10 @@ void WifiConnection::startPortal() {
void WifiConnection::loop() { myDRD->loop(); }
//
// Connect to last known access point or create one if connection is not
// working.
// Connect to last known access point, non blocking mode.
//
bool WifiConnection::connect() {
// Connect to wifi
int i = 0;
void WifiConnection::connectAsync() {
WiFi.persistent(true);
WiFi.mode(WIFI_STA);
if (strlen(userSSID)) {
Log.notice(F("WIFI: Connecting to wifi using hardcoded settings %s." CR),
@ -158,14 +155,22 @@ bool WifiConnection::connect() {
myConfig.getWifiSSID());
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) {
delay(200);
Serial.print(".");
delay(100);
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),
WiFi.status(), getIPAddress().c_str());
WiFi.disconnect();
@ -180,6 +185,14 @@ bool WifiConnection::connect() {
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
// mode.

View File

@ -36,6 +36,8 @@ class WifiConnection {
bool newFirmware = false;
bool parseFirmwareVersionString(int (&num)[3], const char *version);
void downloadFile(const char *fname);
void connectAsync();
bool waitForConnection(int maxTime = 20);
public:
// 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
over the last 6 months without any issues.
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.
* https://github.com/tzapu/WiFiManager
* https://github.com/khoih-prog/ESP_WiFiManager
Configure wifi settings.

View File

@ -3,6 +3,17 @@
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
------