Reduced logging messages

This commit is contained in:
Magnus Persson 2022-01-04 21:13:34 +01:00
parent 5a7858ecaf
commit 088a37eaf3
8 changed files with 189 additions and 164 deletions

View File

@ -33,7 +33,7 @@ build_flags =
#-D SKIP_SLEEPMODE #-D SKIP_SLEEPMODE
#-D DOUBLERESETDETECTOR_DEBUG true #-D DOUBLERESETDETECTOR_DEBUG true
-D USE_LITTLEFS=true -D USE_LITTLEFS=true
#-D EMBED_HTML # If this is not used the html files needs to be on the file system (can be uploaded) -D EMBED_HTML # If this is not used the html files needs to be on the file system (can be uploaded)
-D USER_SSID=\""\"" # =\""myssid\"" -D USER_SSID=\""\"" # =\""myssid\""
-D USER_SSID_PWD=\""\"" # =\""mypwd\"" -D USER_SSID_PWD=\""\"" # =\""mypwd\""
-D CFG_APPVER="\"0.4.9\"" -D CFG_APPVER="\"0.4.9\""

View File

@ -25,6 +25,8 @@ SOFTWARE.
#include "helper.h" #include "helper.h"
#include <LittleFS.h> #include <LittleFS.h>
#define CFG_DISABLE_LOGGING
Config myConfig; Config myConfig;
// //
@ -38,9 +40,9 @@ Config::Config() {
sprintf(&buf[0], "" WIFI_MDNS "%s", getID() ); sprintf(&buf[0], "" WIFI_MDNS "%s", getID() );
mDNS = String( &buf[0] ); mDNS = String( &buf[0] );
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( CFG_DISABLE_LOGGING )
Log.verbose(F("CFG : Created config for %s (%s)." CR), id.c_str(), mDNS.c_str() ); Log.verbose(F("CFG : Created config for %s (%s)." CR), id.c_str(), mDNS.c_str() );
#endif #endif
setTempFormat('C'); setTempFormat('C');
setGravityFormat('G'); setGravityFormat('G');
@ -105,15 +107,15 @@ void Config::createJson(DynamicJsonDocument& doc) {
// //
bool Config::saveFile() { bool Config::saveFile() {
if( !saveNeeded ) { if( !saveNeeded ) {
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( CFG_DISABLE_LOGGING )
Log.verbose(F("CFG : Skipping save, not needed." CR)); Log.verbose(F("CFG : Skipping save, not needed." CR));
#endif #endif
return true; return true;
} }
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( CFG_DISABLE_LOGGING )
Log.verbose(F("CFG : Saving configuration to file." CR)); Log.verbose(F("CFG : Saving configuration to file." CR));
#endif #endif
File configFile = LittleFS.open(CFG_FILENAME, "w"); File configFile = LittleFS.open(CFG_FILENAME, "w");
@ -124,10 +126,12 @@ bool Config::saveFile() {
DynamicJsonDocument doc(CFG_JSON_BUFSIZE); DynamicJsonDocument doc(CFG_JSON_BUFSIZE);
createJson( doc ); createJson( doc );
#if LOG_LEVEL==6
#if LOG_LEVEL==6 && !defined( CFG_DISABLE_LOGGING )
serializeJson(doc, Serial); serializeJson(doc, Serial);
Serial.print( CR ); Serial.print( CR );
#endif #endif
serializeJson(doc, configFile); serializeJson(doc, configFile);
configFile.flush(); configFile.flush();
configFile.close(); configFile.close();
@ -142,9 +146,9 @@ bool Config::saveFile() {
// Load config file from disk // Load config file from disk
// //
bool Config::loadFile() { bool Config::loadFile() {
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( CFG_DISABLE_LOGGING )
Log.verbose(F("CFG : Loading configuration from file." CR)); Log.verbose(F("CFG : Loading configuration from file." CR));
#endif #endif
if (!LittleFS.exists(CFG_FILENAME)) { if (!LittleFS.exists(CFG_FILENAME)) {
Log.error(F("CFG : Configuration file does not exist " CFG_FILENAME "." CR)); Log.error(F("CFG : Configuration file does not exist " CFG_FILENAME "." CR));
@ -264,9 +268,7 @@ bool Config::loadFile() {
// Check if file system can be mounted, if not we format it. // Check if file system can be mounted, if not we format it.
// //
void Config::formatFileSystem() { void Config::formatFileSystem() {
#if LOG_LEVEL==6 Log.notice(F("CFG : Formating filesystem." CR));
Log.verbose(F("CFG : Formating filesystem." CR));
#endif
LittleFS.format(); LittleFS.format();
} }
@ -274,9 +276,9 @@ void Config::formatFileSystem() {
// Check if file system can be mounted, if not we format it. // Check if file system can be mounted, if not we format it.
// //
void Config::checkFileSystem() { void Config::checkFileSystem() {
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( CFG_DISABLE_LOGGING )
Log.verbose(F("CFG : Checking if filesystem is valid." CR)); Log.verbose(F("CFG : Checking if filesystem is valid." CR));
#endif #endif
if (LittleFS.begin()) { if (LittleFS.begin()) {
Log.notice(F("CFG : Filesystem mounted." CR)); Log.notice(F("CFG : Filesystem mounted." CR));
@ -290,7 +292,7 @@ void Config::checkFileSystem() {
// Dump the configuration to the serial port // Dump the configuration to the serial port
// //
void Config::debug() { void Config::debug() {
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( CFG_DISABLE_LOGGING )
Log.verbose(F("CFG : Dumping configration " CFG_FILENAME "." CR)); Log.verbose(F("CFG : Dumping configration " CFG_FILENAME "." CR));
Log.verbose(F("CFG : ID; '%s'." CR), getID()); Log.verbose(F("CFG : ID; '%s'." CR), getID());
Log.verbose(F("CFG : WIFI; '%s', '%s'." CR), getWifiSSID(), getWifiPass() ); Log.verbose(F("CFG : WIFI; '%s', '%s'." CR), getWifiSSID(), getWifiPass() );
@ -310,7 +312,7 @@ void Config::debug() {
getInfluxDb2PushBucket(), getInfluxDb2PushToken() ); getInfluxDb2PushBucket(), getInfluxDb2PushToken() );
// Log.verbose(F("CFG : Accel offset\t%d\t%d\t%d" CR), gyroCalibration.ax, gyroCalibration.ay, gyroCalibration.az ); // Log.verbose(F("CFG : Accel offset\t%d\t%d\t%d" CR), gyroCalibration.ax, gyroCalibration.ay, gyroCalibration.az );
// Log.verbose(F("CFG : Gyro offset \t%d\t%d\t%d" CR), gyroCalibration.gx, gyroCalibration.gy, gyroCalibration.gz ); // Log.verbose(F("CFG : Gyro offset \t%d\t%d\t%d" CR), gyroCalibration.gx, gyroCalibration.gy, gyroCalibration.gz );
#endif #endif
} }
// EOF // EOF

View File

@ -24,6 +24,8 @@ SOFTWARE.
#include "gyro.h" #include "gyro.h"
#include "helper.h" #include "helper.h"
#define GYRO_DISABLE_LOGGING
GyroSensor myGyro; GyroSensor myGyro;
#define GYRO_USE_INTERRUPT // Use interrupt to detect when new sample is ready #define GYRO_USE_INTERRUPT // Use interrupt to detect when new sample is ready
@ -38,9 +40,9 @@ GyroSensor myGyro;
// Initialize the sensor chip. // Initialize the sensor chip.
// //
bool GyroSensor::setup() { bool GyroSensor::setup() {
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( GYRO_DISABLE_LOGGING )
Log.verbose(F("GYRO: Setting up hardware." CR)); Log.verbose(F("GYRO: Setting up hardware." CR));
#endif #endif
Wire.begin(D3, D4); Wire.begin(D3, D4);
Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties
accelgyro.initialize(); accelgyro.initialize();
@ -50,7 +52,9 @@ bool GyroSensor::setup() {
sensorConnected = false; sensorConnected = false;
} else { } else {
#if !defined( GYRO_DISABLE_LOGGING )
Log.notice(F("GYRO: Connected to MPU6050 (gyro)." CR)); Log.notice(F("GYRO: Connected to MPU6050 (gyro)." CR));
#endif
sensorConnected = true; sensorConnected = true;
// Configure the sensor // Configure the sensor
@ -76,7 +80,6 @@ bool GyroSensor::setup() {
calibrationOffset = myConfig.getGyroCalibration(); calibrationOffset = myConfig.getGyroCalibration();
applyCalibration(); applyCalibration();
} }
return sensorConnected; return sensorConnected;
} }
@ -84,9 +87,9 @@ bool GyroSensor::setup() {
// Set sensor in sleep mode to conserve battery // Set sensor in sleep mode to conserve battery
// //
void GyroSensor::enterSleep() { void GyroSensor::enterSleep() {
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( GYRO_DISABLE_LOGGING )
Log.verbose(F("GYRO: Setting up hardware." CR)); Log.verbose(F("GYRO: Setting up hardware." CR));
#endif #endif
accelgyro.setSleepEnabled( true ); accelgyro.setSleepEnabled( true );
} }
@ -96,9 +99,9 @@ void GyroSensor::enterSleep() {
void GyroSensor::readSensor(RawGyroData &raw, const int noIterations, const int delayTime) { void GyroSensor::readSensor(RawGyroData &raw, const int noIterations, const int delayTime) {
RawGyroDataL average = { 0, 0, 0, 0, 0, 0 }; RawGyroDataL average = { 0, 0, 0, 0, 0, 0 };
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( GYRO_DISABLE_LOGGING )
Log.verbose(F("GYRO: Reading sensor with %d iterations %d us delay." CR), noIterations, delayTime ); Log.verbose(F("GYRO: Reading sensor with %d iterations %d us delay." CR), noIterations, delayTime );
#endif #endif
// Set some initial values // Set some initial values
#if defined( GYRO_SHOW_MINMAX ) #if defined( GYRO_SHOW_MINMAX )
@ -162,7 +165,7 @@ void GyroSensor::readSensor(RawGyroData &raw, const int noIterations, const int
raw.gz = average.gz/noIterations; raw.gz = average.gz/noIterations;
raw.temp = average.temp/noIterations; raw.temp = average.temp/noIterations;
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( GYRO_DISABLE_LOGGING )
#if defined( GYRO_SHOW_MINMAX ) #if defined( GYRO_SHOW_MINMAX )
Log.verbose(F("GYRO: Min \t%d\t%d\t%d\t%d\t%d\t%d\t%d." CR), min.ax, min.ay, min.az, min.gx, min.gy, min.gz, min.temp ); Log.verbose(F("GYRO: Min \t%d\t%d\t%d\t%d\t%d\t%d\t%d." CR), min.ax, min.ay, min.az, min.gx, min.gy, min.gz, min.temp );
Log.verbose(F("GYRO: Max \t%d\t%d\t%d\t%d\t%d\t%d\t%d." CR), max.ax, max.ay, max.az, max.gx, max.gy, max.gz, max.temp ); Log.verbose(F("GYRO: Max \t%d\t%d\t%d\t%d\t%d\t%d\t%d." CR), max.ax, max.ay, max.az, max.gx, max.gy, max.gz, max.temp );
@ -177,9 +180,9 @@ void GyroSensor::readSensor(RawGyroData &raw, const int noIterations, const int
// Calcuate the angles (tilt) // Calcuate the angles (tilt)
// //
float GyroSensor::calculateAngle(RawGyroData &raw) { float GyroSensor::calculateAngle(RawGyroData &raw) {
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( GYRO_DISABLE_LOGGING )
Log.verbose(F("GYRO: Calculating the angle." CR) ); Log.verbose(F("GYRO: Calculating the angle." CR) );
#endif #endif
// Smooth out the readings to we can have a more stable angle/tilt. // Smooth out the readings to we can have a more stable angle/tilt.
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
@ -195,9 +198,9 @@ float GyroSensor::calculateAngle(RawGyroData &raw) {
//double v = (acos( raw.az / sqrt( raw.ax*raw.ax + raw.ay*raw.ay + raw.az*raw.az ) ) *180.0 / PI); //double v = (acos( raw.az / sqrt( raw.ax*raw.ax + raw.ay*raw.ay + raw.az*raw.az ) ) *180.0 / PI);
//Log.notice(F("GYRO: angle = %F." CR), v ); //Log.notice(F("GYRO: angle = %F." CR), v );
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( GYRO_DISABLE_LOGGING )
Log.verbose(F("GYRO: angle = %F." CR), v ); Log.verbose(F("GYRO: angle = %F." CR), v );
#endif #endif
return v; return v;
} }
@ -205,9 +208,9 @@ float GyroSensor::calculateAngle(RawGyroData &raw) {
// Check if the values are high that indicate that the sensor is moving. // Check if the values are high that indicate that the sensor is moving.
// //
bool GyroSensor::isSensorMoving(RawGyroData &raw) { bool GyroSensor::isSensorMoving(RawGyroData &raw) {
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( GYRO_DISABLE_LOGGING )
Log.verbose(F("GYRO: Checking for sensor movement." CR) ); Log.verbose(F("GYRO: Checking for sensor movement." CR) );
#endif #endif
int x = abs(raw.gx), y = abs(raw.gy), z = abs(raw.gz); int x = abs(raw.gx), y = abs(raw.gy), z = abs(raw.gz);
@ -223,9 +226,10 @@ bool GyroSensor::isSensorMoving(RawGyroData &raw) {
// Read the tilt angle from the gyro. // Read the tilt angle from the gyro.
// //
bool GyroSensor::read() { bool GyroSensor::read() {
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( GYRO_DISABLE_LOGGING )
Log.verbose(F("GYRO: Getting new gyro position." CR) ); Log.verbose(F("GYRO: Getting new gyro position." CR) );
#endif #endif
if( !sensorConnected ) if( !sensorConnected )
return false; return false;
@ -233,12 +237,16 @@ bool GyroSensor::read() {
// If the sensor is unstable we return false to signal we dont have valid value // If the sensor is unstable we return false to signal we dont have valid value
if( isSensorMoving(lastGyroData) ) { if( isSensorMoving(lastGyroData) ) {
#if !defined( GYRO_DISABLE_LOGGING )
Log.notice(F("GYRO: Sensor is moving." CR) ); Log.notice(F("GYRO: Sensor is moving." CR) );
#endif
validValue = false; validValue = false;
} else { } else {
validValue = true; validValue = true;
angle = calculateAngle( lastGyroData ); angle = calculateAngle( lastGyroData );
//Log.notice(F("GYRO: Sensor values %d,%d,%d\t%F" CR), raw.ax, raw.ay, raw.az, angle ); #if !defined( GYRO_DISABLE_LOGGING )
Log.notice(F("GYRO: Sensor values %d,%d,%d\t%F" CR), raw.ax, raw.ay, raw.az, angle );
#endif
} }
sensorTemp = ((float) lastGyroData.temp) / 340 + 36.53; sensorTemp = ((float) lastGyroData.temp) / 340 + 36.53;
@ -255,19 +263,20 @@ bool GyroSensor::read() {
// Dump the stored calibration values. // Dump the stored calibration values.
// //
void GyroSensor::dumpCalibration() { void GyroSensor::dumpCalibration() {
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( GYRO_DISABLE_LOGGING )
Log.verbose(F("GYRO: Accel offset\t%d\t%d\t%d" CR), calibrationOffset.ax, calibrationOffset.ay, calibrationOffset.az ); Log.verbose(F("GYRO: Accel offset\t%d\t%d\t%d" CR), calibrationOffset.ax, calibrationOffset.ay, calibrationOffset.az );
Log.verbose(F("GYRO: Gyro offset \t%d\t%d\t%d" CR), calibrationOffset.gx, calibrationOffset.gy, calibrationOffset.gz ); Log.verbose(F("GYRO: Gyro offset \t%d\t%d\t%d" CR), calibrationOffset.gx, calibrationOffset.gy, calibrationOffset.gz );
#endif #endif
} }
// //
// Update the sensor with out calculated offsets. // Update the sensor with out calculated offsets.
// //
void GyroSensor::applyCalibration() { void GyroSensor::applyCalibration() {
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( GYRO_DISABLE_LOGGING )
Log.verbose(F("GYRO: Applying calibration offsets to sensor." CR) ); Log.verbose(F("GYRO: Applying calibration offsets to sensor." CR) );
#endif #endif
if( ( calibrationOffset.ax + calibrationOffset.ay + calibrationOffset.az + calibrationOffset.gx + calibrationOffset.gy + calibrationOffset.gz ) == 0 ) { if( ( calibrationOffset.ax + calibrationOffset.ay + calibrationOffset.az + calibrationOffset.gx + calibrationOffset.gy + calibrationOffset.gz ) == 0 ) {
Log.error(F("GYRO: No valid calibraion values exist, aborting." CR) ); Log.error(F("GYRO: No valid calibraion values exist, aborting." CR) );
return; return;
@ -285,9 +294,9 @@ void GyroSensor::applyCalibration() {
// Calculate the offsets for calibration. // Calculate the offsets for calibration.
// //
void GyroSensor::calibrateSensor() { void GyroSensor::calibrateSensor() {
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( GYRO_DISABLE_LOGGING )
Log.verbose(F("GYRO: Calibrating sensor" CR) ); Log.verbose(F("GYRO: Calibrating sensor" CR) );
#endif #endif
//accelgyro.PrintActiveOffsets(); //accelgyro.PrintActiveOffsets();
//Serial.print( CR ); //Serial.print( CR );
@ -314,7 +323,7 @@ void GyroSensor::calibrateSensor() {
// Calibrate the device. // Calibrate the device.
// //
void GyroSensor::debug() { void GyroSensor::debug() {
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( GYRO_DISABLE_LOGGING )
Log.verbose(F("GYRO: Debug - Clock src %d." CR), accelgyro.getClockSource() ); Log.verbose(F("GYRO: Debug - Clock src %d." CR), accelgyro.getClockSource() );
Log.verbose(F("GYRO: Debug - Device ID %d." CR), accelgyro.getDeviceID() ); Log.verbose(F("GYRO: Debug - Device ID %d." CR), accelgyro.getDeviceID() );
Log.verbose(F("GYRO: Debug - DHPF Mode %d." CR), accelgyro.getDHPFMode() ); Log.verbose(F("GYRO: Debug - DHPF Mode %d." CR), accelgyro.getDHPFMode() );
@ -355,7 +364,7 @@ void GyroSensor::debug() {
Log.verbose(F("GYRO: Debug - Gyr OffX %d\t%d." CR), accelgyro.getXGyroOffset(), calibrationOffset.gx ); Log.verbose(F("GYRO: Debug - Gyr OffX %d\t%d." CR), accelgyro.getXGyroOffset(), calibrationOffset.gx );
Log.verbose(F("GYRO: Debug - Gyr OffY %d\t%d." CR), accelgyro.getYGyroOffset(), calibrationOffset.gy ); Log.verbose(F("GYRO: Debug - Gyr OffY %d\t%d." CR), accelgyro.getYGyroOffset(), calibrationOffset.gy );
Log.verbose(F("GYRO: Debug - Gyr OffZ %d\t%d." CR), accelgyro.getZGyroOffset(), calibrationOffset.gz ); Log.verbose(F("GYRO: Debug - Gyr OffZ %d\t%d." CR), accelgyro.getZGyroOffset(), calibrationOffset.gz );
#endif #endif
} }
// EOF // EOF

View File

@ -31,6 +31,8 @@ SOFTWARE.
#include "pushtarget.h" #include "pushtarget.h"
#include <LittleFS.h> #include <LittleFS.h>
#define MAIN_DISABLE_LOGGING
// Settings for double reset detector. // Settings for double reset detector.
#define ESP8266_DRD_USE_RTC true #define ESP8266_DRD_USE_RTC true
#define DRD_TIMEOUT 2 #define DRD_TIMEOUT 2
@ -83,9 +85,9 @@ void checkSleepMode( float angle, float volt ) {
// sleep mode active when flat // sleep mode active when flat
//sleepModeActive = ( angle<85 && angle>5 ) ? true : false; //sleepModeActive = ( angle<85 && angle>5 ) ? true : false;
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( MAIN_DISABLE_LOGGING )
Log.verbose(F("MAIN: Deep sleep mode %s (angle=%F volt=%F)." CR), sleepModeActive ? "true":"false", angle, volt ); Log.verbose(F("MAIN: Deep sleep mode %s (angle=%F volt=%F)." CR), sleepModeActive ? "true":"false", angle, volt );
#endif #endif
} }
// //
@ -98,9 +100,9 @@ void setup() {
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS); drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
bool dt = drd->detectDoubleReset(); bool dt = drd->detectDoubleReset();
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( MAIN_DISABLE_LOGGING )
Log.verbose(F("Main: Reset reason %s." CR), ESP.getResetInfo().c_str() ); Log.verbose(F("Main: Reset reason %s." CR), ESP.getResetInfo().c_str() );
#endif #endif
// Main startup // Main startup
Log.notice(F("Main: Started setup for %s." CR), String( ESP.getChipId(), HEX).c_str() ); Log.notice(F("Main: Started setup for %s." CR), String( ESP.getChipId(), HEX).c_str() );
printBuildOptions(); printBuildOptions();
@ -176,9 +178,11 @@ void loop() {
float volt = myBatteryVoltage.getVoltage(); float volt = myBatteryVoltage.getVoltage();
//float sensorTemp = 0; //float sensorTemp = 0;
loopCounter++; loopCounter++;
#if LOG_LEVEL==6
#if LOG_LEVEL==6 && !defined( MAIN_DISABLE_LOGGING )
Log.verbose(F("Main: Entering main loop." CR) ); Log.verbose(F("Main: Entering main loop." CR) );
#endif #endif
// Process the sensor values and push data to targets. // Process the sensor values and push data to targets.
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// If we dont get any readings we just skip this and try again the next interval. // If we dont get any readings we just skip this and try again the next interval.
@ -201,9 +205,10 @@ void loop() {
float corrGravity = gravityTemperatureCorrection( gravity, temp, myConfig.getTempFormat() ); float corrGravity = gravityTemperatureCorrection( gravity, temp, myConfig.getTempFormat() );
//LOG_PERF_STOP("loop-gravity-corr"); //LOG_PERF_STOP("loop-gravity-corr");
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( MAIN_DISABLE_LOGGING )
Log.verbose(F("Main: Sensor values gyro angle=%F, temp=%F, gravity=%F, corr=%F." CR), angle, temp, gravity, corrGravity ); Log.verbose(F("Main: Sensor values gyro angle=%F, temp=%F, gravity=%F, corr=%F." CR), angle, temp, gravity, corrGravity );
#endif #endif
// Limit the printout when sleep mode is not active. // Limit the printout when sleep mode is not active.
if( loopCounter%10 == 0 || sleepModeActive ) { if( loopCounter%10 == 0 || sleepModeActive ) {
Log.notice(F("Main: angle=%F, temp=%F, gravity=%F, corrGravity=%F, batt=%F." CR), angle, temp, gravity, corrGravity ,volt ); Log.notice(F("Main: angle=%F, temp=%F, gravity=%F, corrGravity=%F, batt=%F." CR), angle, temp, gravity, corrGravity ,volt );
@ -220,9 +225,10 @@ void loop() {
Log.error(F("Main: No gyro value." CR) ); Log.error(F("Main: No gyro value." CR) );
} }
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( MAIN_DISABLE_LOGGING )
Log.verbose(F("Main: Sleep mode not active." CR) ); Log.verbose(F("Main: Sleep mode not active." CR) );
#endif #endif
int sleepInterval = myConfig.getSleepInterval(); int sleepInterval = myConfig.getSleepInterval();
// If we didnt get a wifi connection, we enter sleep for a short time to conserve battery. // If we didnt get a wifi connection, we enter sleep for a short time to conserve battery.
@ -272,13 +278,11 @@ void loop() {
//LOG_PERF_STOP("loop-batt-read"); //LOG_PERF_STOP("loop-batt-read");
loopMillis = millis(); loopMillis = millis();
//#if LOG_LEVEL==6 //#if LOG_LEVEL==6 && !defined( MAIN_DISABLE_LOGGING )
Log.verbose(F("Main: Heap %d kb FreeSketch %d kb." CR), ESP.getFreeHeap()/1024, ESP.getFreeSketchSpace()/1024 ); Log.verbose(F("Main: Heap %d kb FreeSketch %d kb HeapFrag %d %%." CR), ESP.getFreeHeap()/1024, ESP.getFreeSketchSpace()/1024, ESP.getHeapFragmentation() );
Log.verbose(F("Main: HeapFrag %d %%." CR), ESP.getHeapFragmentation() ); //#endif
//#endif
} }
//if( myWifi.isConnected() )
myWebServer.loop(); myWebServer.loop();
} }

View File

@ -25,6 +25,8 @@ SOFTWARE.
#include "config.h" #include "config.h"
#include "gyro.h" // For testing the tempsensor in the gyro #include "gyro.h" // For testing the tempsensor in the gyro
#define PUSH_DISABLE_LOGGING
PushTarget myPushTarget; PushTarget myPushTarget;
// //
@ -35,15 +37,16 @@ void PushTarget::send(float angle, float gravity, float corrGravity, float temp,
unsigned long interval = myConfig.getSleepInterval()*1000; unsigned long interval = myConfig.getSleepInterval()*1000;
if( ( timePassed < interval ) && !force) { if( ( timePassed < interval ) && !force) {
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( PUSH_DISABLE_LOGGING )
Log.verbose(F("PUSH: Timer has not expired %l vs %l." CR), timePassed, interval ); Log.verbose(F("PUSH: Timer has not expired %l vs %l." CR), timePassed, interval );
#endif #endif
return; return;
} }
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( PUSH_DISABLE_LOGGING )
Log.verbose(F("PUSH: Sending data." CR) ); Log.verbose(F("PUSH: Sending data." CR) );
#endif #endif
ms = millis(); ms = millis();
if( myConfig.isBrewfatherActive() ) { if( myConfig.isBrewfatherActive() ) {
@ -75,7 +78,9 @@ void PushTarget::send(float angle, float gravity, float corrGravity, float temp,
// Send to influx db v2 // Send to influx db v2
// //
void PushTarget::sendInfluxDb2(float angle, float gravity, float corrGravity, float temp, float runTime) { void PushTarget::sendInfluxDb2(float angle, float gravity, float corrGravity, float temp, float runTime) {
#if !defined( PUSH_DISABLE_LOGGING )
Log.notice(F("PUSH: Sending values to influxdb2 angle=%F, gravity=%F, temp=%F." CR), angle, gravity, temp ); Log.notice(F("PUSH: Sending values to influxdb2 angle=%F, gravity=%F, temp=%F." CR), angle, gravity, temp );
#endif
WiFiClient client; WiFiClient client;
HTTPClient http; HTTPClient http;
@ -94,10 +99,10 @@ void PushTarget::sendInfluxDb2(float angle, float gravity, float corrGravity, fl
myConfig.isGravityTempAdj() ? corrGravity : gravity, myConfig.isGravityTempAdj() ? corrGravity : gravity,
corrGravity, angle, temp, myBatteryVoltage.getVoltage(), WiFi.RSSI(), myGyro.getSensorTempC() ); // For comparing gyro tempsensor vs DSB1820 corrGravity, angle, temp, myBatteryVoltage.getVoltage(), WiFi.RSSI(), myGyro.getSensorTempC() ); // For comparing gyro tempsensor vs DSB1820
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( PUSH_DISABLE_LOGGING )
Log.verbose(F("PUSH: url %s." CR), serverPath.c_str()); Log.verbose(F("PUSH: url %s." CR), serverPath.c_str());
Log.verbose(F("PUSH: data %s." CR), &buf[0] ); Log.verbose(F("PUSH: data %s." CR), &buf[0] );
#endif #endif
// Send HTTP POST request // Send HTTP POST request
String auth = "Token " + String( myConfig.getInfluxDb2PushToken() ); String auth = "Token " + String( myConfig.getInfluxDb2PushToken() );
@ -117,7 +122,9 @@ void PushTarget::sendInfluxDb2(float angle, float gravity, float corrGravity, fl
// Send data to brewfather // Send data to brewfather
// //
void PushTarget::sendBrewfather(float angle, float gravity, float corrGravity, float temp ) { void PushTarget::sendBrewfather(float angle, float gravity, float corrGravity, float temp ) {
#if !defined( PUSH_DISABLE_LOGGING )
Log.notice(F("PUSH: Sending values to brewfather angle=%F, gravity=%F, temp=%F." CR), angle, gravity, temp ); Log.notice(F("PUSH: Sending values to brewfather angle=%F, gravity=%F, temp=%F." CR), angle, gravity, temp );
#endif
DynamicJsonDocument doc(300); DynamicJsonDocument doc(300);
// //
@ -154,10 +161,10 @@ void PushTarget::sendBrewfather(float angle, float gravity, float corrGravity, f
http.begin( client, serverPath); http.begin( client, serverPath);
String json; String json;
serializeJson(doc, json); serializeJson(doc, json);
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( PUSH_DISABLE_LOGGING )
Log.verbose(F("PUSH: url %s." CR), serverPath.c_str()); Log.verbose(F("PUSH: url %s." CR), serverPath.c_str());
Log.verbose(F("PUSH: json %s." CR), json.c_str()); Log.verbose(F("PUSH: json %s." CR), json.c_str());
#endif #endif
// Send HTTP POST request // Send HTTP POST request
http.addHeader(F("Content-Type"), F("application/json") ); http.addHeader(F("Content-Type"), F("application/json") );
@ -176,7 +183,9 @@ void PushTarget::sendBrewfather(float angle, float gravity, float corrGravity, f
// Send data to http target // Send data to http target
// //
void PushTarget::sendHttp( String serverPath, float angle, float gravity, float corrGravity, float temp, float runTime ) { void PushTarget::sendHttp( String serverPath, float angle, float gravity, float corrGravity, float temp, float runTime ) {
#if !defined( PUSH_DISABLE_LOGGING )
Log.notice(F("PUSH: Sending values to http angle=%F, gravity=%F, temp=%F." CR), angle, gravity, temp ); Log.notice(F("PUSH: Sending values to http angle=%F, gravity=%F, temp=%F." CR), angle, gravity, temp );
#endif
DynamicJsonDocument doc(256); DynamicJsonDocument doc(256);
@ -205,10 +214,10 @@ void PushTarget::sendHttp( String serverPath, float angle, float gravity, float
http.begin( client, serverPath); http.begin( client, serverPath);
String json; String json;
serializeJson(doc, json); serializeJson(doc, json);
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( PUSH_DISABLE_LOGGING )
Log.verbose(F("PUSH: url %s." CR), serverPath.c_str()); Log.verbose(F("PUSH: url %s." CR), serverPath.c_str());
Log.verbose(F("PUSH: json %s." CR), json.c_str()); Log.verbose(F("PUSH: json %s." CR), json.c_str());
#endif #endif
// Send HTTP POST request // Send HTTP POST request
http.addHeader(F("Content-Type"), F("application/json") ); http.addHeader(F("Content-Type"), F("application/json") );

View File

@ -29,6 +29,8 @@ SOFTWARE.
#include <DallasTemperature.h> #include <DallasTemperature.h>
#include <Wire.h> #include <Wire.h>
#define TSEN_DISABLE_LOGGING
// //
// Conversion between C and F // Conversion between C and F
// //
@ -57,19 +59,15 @@ void TempSensor::setup() {
#if defined( USE_GYRO_TEMP ) #if defined( USE_GYRO_TEMP )
Log.notice(F("TSEN: Using temperature from gyro." CR)); Log.notice(F("TSEN: Using temperature from gyro." CR));
#else #else
// This code is used to read the DS18 temp sensor #if LOG_LEVEL==6 && !defined( TSEN_DISABLE_LOGGING )
/*if( !mySensors.getDS18Count() ) {
Log.error(F("TSEN: No temperature sensors found." CR));
return;
}*/
#if LOG_LEVEL==6
Log.verbose(F("TSEN: Looking for temp sensors." CR)); Log.verbose(F("TSEN: Looking for temp sensors." CR));
#endif #endif
mySensors.begin(); mySensors.begin();
if( mySensors.getDS18Count() ) { if( mySensors.getDS18Count() ) {
#if !defined( TSEN_DISABLE_LOGGING )
Log.notice(F("TSEN: Found %d temperature sensor(s)." CR), mySensors.getDS18Count()); Log.notice(F("TSEN: Found %d temperature sensor(s)." CR), mySensors.getDS18Count());
#endif
mySensors.setResolution(TEMPERATURE_PRECISION); mySensors.setResolution(TEMPERATURE_PRECISION);
} }
#endif #endif
@ -85,9 +83,9 @@ void TempSensor::setup() {
tempSensorAdjC = t * 0.556; // Convert the adjustent value to F tempSensorAdjC = t * 0.556; // Convert the adjustent value to F
} }
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( TSEN_DISABLE_LOGGING )
Log.verbose(F("TSEN: Adjustment values for temp sensor %F C, %F F." CR), tempSensorAdjC, tempSensorAdjF ); Log.verbose(F("TSEN: Adjustment values for temp sensor %F C, %F F." CR), tempSensorAdjC, tempSensorAdjF );
#endif #endif
} }
// //
@ -105,9 +103,9 @@ float TempSensor::getValue() {
//LOG_PERF_STOP("temp-get"); //LOG_PERF_STOP("temp-get");
hasSensor = true; hasSensor = true;
return c; return c;
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( TSEN_DISABLE_LOGGING )
Log.verbose(F("TSEN: Reciving temp value for gyro sensor %F C." CR), c); Log.verbose(F("TSEN: Reciving temp value for gyro sensor %F C." CR), c);
#endif #endif
#else #else
// If we dont have sensors just return 0 // If we dont have sensors just return 0
if( !mySensors.getDS18Count() ) { if( !mySensors.getDS18Count() ) {
@ -127,12 +125,11 @@ float TempSensor::getValue() {
c = mySensors.getTempCByIndex(0); c = mySensors.getTempCByIndex(0);
//LOG_PERF_STOP("temp-get"); //LOG_PERF_STOP("temp-get");
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( TSEN_DISABLE_LOGGING )
Log.verbose(F("TSEN: Reciving temp value for sensor %F C." CR), c); Log.verbose(F("TSEN: Reciving temp value for sensor %F C." CR), c);
#endif #endif
hasSensor = true; hasSensor = true;
} }
return c; return c;
#endif #endif
} }

View File

@ -30,6 +30,8 @@ SOFTWARE.
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <LittleFS.h> #include <LittleFS.h>
#define WEB_DISABLE_LOGGING
WebServer myWebServer; // My wrapper class fr webserver functions WebServer myWebServer; // My wrapper class fr webserver functions
extern bool sleepModeActive; extern bool sleepModeActive;
extern bool sleepModeAlwaysSkip; extern bool sleepModeAlwaysSkip;
@ -39,9 +41,10 @@ extern bool sleepModeAlwaysSkip;
// //
void WebServer::webHandleDevice() { void WebServer::webHandleDevice() {
LOG_PERF_START("webserver-api-device"); LOG_PERF_START("webserver-api-device");
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( WEB_DISABLE_LOGGING )
Log.verbose(F("WEB : webServer callback for /api/config." CR)); Log.verbose(F("WEB : webServer callback for /api/config." CR));
#endif #endif
DynamicJsonDocument doc(100); DynamicJsonDocument doc(100);
doc[ CFG_PARAM_ID ] = myConfig.getID(); doc[ CFG_PARAM_ID ] = myConfig.getID();
doc[ CFG_PARAM_APP_NAME ] = CFG_APPNAME; doc[ CFG_PARAM_APP_NAME ] = CFG_APPNAME;
@ -62,9 +65,8 @@ void WebServer::webHandleDevice() {
// //
void WebServer::webHandleConfig() { void WebServer::webHandleConfig() {
LOG_PERF_START("webserver-api-config"); LOG_PERF_START("webserver-api-config");
#if LOG_LEVEL==6 Log.notice(F("WEB : webServer callback for /api/config." CR));
Log.verbose(F("WEB : webServer callback for /api/config." CR));
#endif
DynamicJsonDocument doc(CFG_JSON_BUFSIZE); DynamicJsonDocument doc(CFG_JSON_BUFSIZE);
myConfig.createJson( doc ); myConfig.createJson( doc );
@ -79,10 +81,11 @@ void WebServer::webHandleConfig() {
doc[ CFG_PARAM_GRAVITY ] = reduceFloatPrecision( gravity, 4); doc[ CFG_PARAM_GRAVITY ] = reduceFloatPrecision( gravity, 4);
doc[ CFG_PARAM_BATTERY ] = reduceFloatPrecision( myBatteryVoltage.getVoltage()); doc[ CFG_PARAM_BATTERY ] = reduceFloatPrecision( myBatteryVoltage.getVoltage());
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( WEB_DISABLE_LOGGING )
serializeJson(doc, Serial); serializeJson(doc, Serial);
Serial.print( CR ); Serial.print( CR );
#endif #endif
String out; String out;
serializeJson(doc, out); serializeJson(doc, out);
server->send(200, "application/json", out.c_str() ); server->send(200, "application/json", out.c_str() );
@ -94,9 +97,6 @@ void WebServer::webHandleConfig() {
// //
void WebServer::webHandleUpload() { void WebServer::webHandleUpload() {
LOG_PERF_START("webserver-api-upload"); LOG_PERF_START("webserver-api-upload");
#if LOG_LEVEL==6
Log.verbose(F("WEB : webServer callback for /api/upload." CR));
#endif
Log.notice(F("WEB : webServer callback for /api/upload." CR)); Log.notice(F("WEB : webServer callback for /api/upload." CR));
DynamicJsonDocument doc(100); DynamicJsonDocument doc(100);
@ -106,10 +106,11 @@ void WebServer::webHandleUpload() {
doc[ "calibration" ] = myWebServer.checkHtmlFile( WebServer::HTML_CALIBRATION ); doc[ "calibration" ] = myWebServer.checkHtmlFile( WebServer::HTML_CALIBRATION );
doc[ "about" ] = myWebServer.checkHtmlFile( WebServer::HTML_ABOUT ); doc[ "about" ] = myWebServer.checkHtmlFile( WebServer::HTML_ABOUT );
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( WEB_DISABLE_LOGGING )
serializeJson(doc, Serial); serializeJson(doc, Serial);
Serial.print( CR ); Serial.print( CR );
#endif #endif
String out; String out;
serializeJson(doc, out); serializeJson(doc, out);
server->send(200, "application/json", out.c_str() ); server->send(200, "application/json", out.c_str() );
@ -121,9 +122,7 @@ void WebServer::webHandleUpload() {
// //
void WebServer::webHandleUploadFile() { void WebServer::webHandleUploadFile() {
LOG_PERF_START("webserver-api-upload-file"); LOG_PERF_START("webserver-api-upload-file");
#if LOG_LEVEL==6 Log.notice(F("WEB : webServer callback for /api/upload/file." CR));
Log.verbose(F("WEB : webServer callback for /api/upload/file." CR));
#endif
HTTPUpload& upload = server->upload(); HTTPUpload& upload = server->upload();
String f = upload.filename; String f = upload.filename;
bool validFilename = false; bool validFilename = false;
@ -133,7 +132,9 @@ void WebServer::webHandleUploadFile() {
validFilename = true; validFilename = true;
} }
Log.notice(F("WEB : webServer callback for /api/upload, receiving file %s, valid=%s." CR), f.c_str(), validFilename?"yes":"no"); #if LOG_LEVEL==6 && !defined( WEB_DISABLE_LOGGING )
Log.debug(F("WEB : webServer callback for /api/upload, receiving file %s, valid=%s." CR), f.c_str(), validFilename?"yes":"no");
#endif
if(upload.status == UPLOAD_FILE_START) { if(upload.status == UPLOAD_FILE_START) {
Log.notice(F("WEB : Start upload." CR) ); Log.notice(F("WEB : Start upload." CR) );
@ -163,9 +164,8 @@ void WebServer::webHandleUploadFile() {
void WebServer::webHandleCalibrate() { void WebServer::webHandleCalibrate() {
LOG_PERF_START("webserver-api-calibrate"); LOG_PERF_START("webserver-api-calibrate");
String id = server->arg( CFG_PARAM_ID ); String id = server->arg( CFG_PARAM_ID );
#if LOG_LEVEL==6 Log.notice(F("WEB : webServer callback for /api/calibrate." CR));
Log.verbose(F("WEB : webServer callback for /api/calibrate." CR));
#endif
if( !id.equalsIgnoreCase( myConfig.getID() ) ) { if( !id.equalsIgnoreCase( myConfig.getID() ) ) {
Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), myConfig.getID()); Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), myConfig.getID());
server->send(400, "text/plain", "Invalid ID."); server->send(400, "text/plain", "Invalid ID.");
@ -182,9 +182,8 @@ void WebServer::webHandleCalibrate() {
// //
void WebServer::webHandleFactoryReset() { void WebServer::webHandleFactoryReset() {
String id = server->arg( CFG_PARAM_ID ); String id = server->arg( CFG_PARAM_ID );
#if LOG_LEVEL==6 Log.notice(F("WEB : webServer callback for /api/factory." CR));
Log.verbose(F("WEB : webServer callback for /api/factory." CR));
#endif
if( !id.compareTo( myConfig.getID() ) ) { if( !id.compareTo( myConfig.getID() ) ) {
server->send(200, "text/plain", "Doing reset..."); server->send(200, "text/plain", "Doing reset...");
LittleFS.remove(CFG_FILENAME); LittleFS.remove(CFG_FILENAME);
@ -201,9 +200,8 @@ void WebServer::webHandleFactoryReset() {
// //
void WebServer::webHandleStatus() { void WebServer::webHandleStatus() {
LOG_PERF_START("webserver-api-status"); LOG_PERF_START("webserver-api-status");
#if LOG_LEVEL==6 Log.notice(F("WEB : webServer callback for /api/status." CR));
Log.verbose(F("WEB : webServer callback for /api/status." CR));
#endif
DynamicJsonDocument doc(256); DynamicJsonDocument doc(256);
double angle = myGyro.getAngle(); double angle = myGyro.getAngle();
@ -222,10 +220,12 @@ void WebServer::webHandleStatus() {
doc[ CFG_PARAM_TEMPFORMAT ] = String( myConfig.getTempFormat() ); doc[ CFG_PARAM_TEMPFORMAT ] = String( myConfig.getTempFormat() );
doc[ CFG_PARAM_SLEEP_MODE ] = sleepModeAlwaysSkip; doc[ CFG_PARAM_SLEEP_MODE ] = sleepModeAlwaysSkip;
doc[ CFG_PARAM_RSSI ] = WiFi.RSSI(); doc[ CFG_PARAM_RSSI ] = WiFi.RSSI();
#if LOG_LEVEL==6
#if LOG_LEVEL==6 && !defined( WEB_DISABLE_LOGGING )
serializeJson(doc, Serial); serializeJson(doc, Serial);
Serial.print( CR ); Serial.print( CR );
#endif #endif
String out; String out;
serializeJson(doc, out); serializeJson(doc, out);
server->send(200, "application/json", out.c_str() ); server->send(200, "application/json", out.c_str() );
@ -237,9 +237,8 @@ void WebServer::webHandleStatus() {
// //
void WebServer::webHandleClearWIFI() { void WebServer::webHandleClearWIFI() {
String id = server->arg( CFG_PARAM_ID ); String id = server->arg( CFG_PARAM_ID );
#if LOG_LEVEL==6 Log.notice(F("WEB : webServer callback for /api/clearwifi." CR));
Log.verbose(F("WEB : webServer callback for /api/clearwifi." CR));
#endif
if( !id.compareTo( myConfig.getID() ) ) { if( !id.compareTo( myConfig.getID() ) ) {
server->send(200, "text/plain", "Clearing WIFI credentials and doing reset..."); server->send(200, "text/plain", "Clearing WIFI credentials and doing reset...");
delay(1000); delay(1000);
@ -256,18 +255,19 @@ void WebServer::webHandleClearWIFI() {
void WebServer::webHandleStatusSleepmode() { void WebServer::webHandleStatusSleepmode() {
LOG_PERF_START("webserver-api-sleepmode"); LOG_PERF_START("webserver-api-sleepmode");
String id = server->arg( CFG_PARAM_ID ); String id = server->arg( CFG_PARAM_ID );
#if LOG_LEVEL==6 Log.notice(F("WEB : webServer callback for /api/status/sleepmode." CR) );
Log.verbose(F("WEB : webServer callback for /api/status/sleepmode." CR) );
#endif
if( !id.equalsIgnoreCase( myConfig.getID() ) ) { if( !id.equalsIgnoreCase( myConfig.getID() ) ) {
Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), myConfig.getID()); Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), myConfig.getID());
server->send(400, "text/plain", "Invalid ID."); server->send(400, "text/plain", "Invalid ID.");
LOG_PERF_STOP("webserver-api-sleepmode"); LOG_PERF_STOP("webserver-api-sleepmode");
return; return;
} }
#if LOG_LEVEL==6
#if LOG_LEVEL==6 && !defined( WEB_DISABLE_LOGGING )
Log.verbose(F("WEB : sleep-mode=%s." CR), server->arg( CFG_PARAM_SLEEP_MODE ).c_str() ); Log.verbose(F("WEB : sleep-mode=%s." CR), server->arg( CFG_PARAM_SLEEP_MODE ).c_str() );
#endif #endif
if( server->arg( CFG_PARAM_SLEEP_MODE ).equalsIgnoreCase( "true" ) ) if( server->arg( CFG_PARAM_SLEEP_MODE ).equalsIgnoreCase( "true" ) )
sleepModeAlwaysSkip = true; sleepModeAlwaysSkip = true;
else else
@ -282,18 +282,19 @@ void WebServer::webHandleStatusSleepmode() {
void WebServer::webHandleConfigDevice() { void WebServer::webHandleConfigDevice() {
LOG_PERF_START("webserver-api-config-device"); LOG_PERF_START("webserver-api-config-device");
String id = server->arg( CFG_PARAM_ID ); String id = server->arg( CFG_PARAM_ID );
#if LOG_LEVEL==6 Log.notice(F("WEB : webServer callback for /api/config/device." CR) );
Log.verbose(F("WEB : webServer callback for /api/config/device." CR) );
#endif
if( !id.equalsIgnoreCase( myConfig.getID() ) ) { if( !id.equalsIgnoreCase( myConfig.getID() ) ) {
Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), myConfig.getID()); Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), myConfig.getID());
server->send(400, "text/plain", "Invalid ID."); server->send(400, "text/plain", "Invalid ID.");
LOG_PERF_STOP("webserver-api-config-device"); LOG_PERF_STOP("webserver-api-config-device");
return; return;
} }
#if LOG_LEVEL==6
#if LOG_LEVEL==6 && !defined( WEB_DISABLE_LOGGING )
Log.verbose(F("WEB : mdns=%s, temp-format=%s." CR), server->arg( CFG_PARAM_MDNS ).c_str(), server->arg( CFG_PARAM_TEMPFORMAT ).c_str() ); Log.verbose(F("WEB : mdns=%s, temp-format=%s." CR), server->arg( CFG_PARAM_MDNS ).c_str(), server->arg( CFG_PARAM_TEMPFORMAT ).c_str() );
#endif #endif
myConfig.setMDNS( server->arg( CFG_PARAM_MDNS ).c_str() ); myConfig.setMDNS( server->arg( CFG_PARAM_MDNS ).c_str() );
myConfig.setTempFormat( server->arg( CFG_PARAM_TEMPFORMAT ).charAt(0) ); myConfig.setTempFormat( server->arg( CFG_PARAM_TEMPFORMAT ).charAt(0) );
myConfig.setSleepInterval( server->arg( CFG_PARAM_SLEEP_INTERVAL ).c_str() ); myConfig.setSleepInterval( server->arg( CFG_PARAM_SLEEP_INTERVAL ).c_str() );
@ -309,22 +310,22 @@ void WebServer::webHandleConfigDevice() {
void WebServer::webHandleConfigPush() { void WebServer::webHandleConfigPush() {
LOG_PERF_START("webserver-api-config-push"); LOG_PERF_START("webserver-api-config-push");
String id = server->arg( CFG_PARAM_ID ); String id = server->arg( CFG_PARAM_ID );
#if LOG_LEVEL==6 Log.notice(F("WEB : webServer callback for /api/config/push." CR) );
Log.verbose(F("WEB : webServer callback for /api/config/push." CR) );
#endif
if( !id.equalsIgnoreCase( myConfig.getID() ) ) { if( !id.equalsIgnoreCase( myConfig.getID() ) ) {
Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), myConfig.getID()); Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), myConfig.getID());
server->send(400, "text/plain", "Invalid ID."); server->send(400, "text/plain", "Invalid ID.");
LOG_PERF_STOP("webserver-api-config-push"); LOG_PERF_STOP("webserver-api-config-push");
return; return;
} }
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( WEB_DISABLE_LOGGING )
Log.verbose(F("WEB : http=%s,%s, bf=%s influx2=%s, %s, %s, %s." CR), server->arg( CFG_PARAM_PUSH_HTTP ).c_str(), Log.verbose(F("WEB : http=%s,%s, bf=%s influx2=%s, %s, %s, %s." CR), server->arg( CFG_PARAM_PUSH_HTTP ).c_str(),
server->arg( CFG_PARAM_PUSH_HTTP2 ).c_str(), server->arg( CFG_PARAM_PUSH_BREWFATHER ).c_str(), server->arg( CFG_PARAM_PUSH_HTTP2 ).c_str(), server->arg( CFG_PARAM_PUSH_BREWFATHER ).c_str(),
server->arg( CFG_PARAM_PUSH_INFLUXDB2 ).c_str(), server->arg( CFG_PARAM_PUSH_INFLUXDB2_ORG ).c_str(), server->arg( CFG_PARAM_PUSH_INFLUXDB2 ).c_str(), server->arg( CFG_PARAM_PUSH_INFLUXDB2_ORG ).c_str(),
server->arg( CFG_PARAM_PUSH_INFLUXDB2_BUCKET ).c_str(), server->arg( CFG_PARAM_PUSH_INFLUXDB2_AUTH ).c_str() server->arg( CFG_PARAM_PUSH_INFLUXDB2_BUCKET ).c_str(), server->arg( CFG_PARAM_PUSH_INFLUXDB2_AUTH ).c_str()
); );
#endif #endif
myConfig.setHttpPushUrl( server->arg( CFG_PARAM_PUSH_HTTP ).c_str() ); myConfig.setHttpPushUrl( server->arg( CFG_PARAM_PUSH_HTTP ).c_str() );
myConfig.setHttpPushUrl2( server->arg( CFG_PARAM_PUSH_HTTP2 ).c_str() ); myConfig.setHttpPushUrl2( server->arg( CFG_PARAM_PUSH_HTTP2 ).c_str() );
myConfig.setBrewfatherPushUrl( server->arg( CFG_PARAM_PUSH_BREWFATHER ).c_str() ); myConfig.setBrewfatherPushUrl( server->arg( CFG_PARAM_PUSH_BREWFATHER ).c_str() );
@ -344,18 +345,19 @@ void WebServer::webHandleConfigPush() {
void WebServer::webHandleConfigGravity() { void WebServer::webHandleConfigGravity() {
LOG_PERF_START("webserver-api-config-gravity"); LOG_PERF_START("webserver-api-config-gravity");
String id = server->arg( CFG_PARAM_ID ); String id = server->arg( CFG_PARAM_ID );
#if LOG_LEVEL==6 Log.notice(F("WEB : webServer callback for /api/config/gravity." CR) );
Log.verbose(F("WEB : webServer callback for /api/config/gravity." CR) );
#endif
if( !id.equalsIgnoreCase( myConfig.getID() ) ) { if( !id.equalsIgnoreCase( myConfig.getID() ) ) {
Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), myConfig.getID()); Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), myConfig.getID());
server->send(400, "text/plain", "Invalid ID."); server->send(400, "text/plain", "Invalid ID.");
LOG_PERF_STOP("webserver-api-config-gravity"); LOG_PERF_STOP("webserver-api-config-gravity");
return; return;
} }
#if LOG_LEVEL==6
#if LOG_LEVEL==6 && !defined( WEB_DISABLE_LOGGING )
Log.verbose(F("WEB : formula=%s, temp-corr=%s." CR), server->arg( CFG_PARAM_GRAVITY_FORMULA ).c_str(), server->arg( CFG_PARAM_GRAVITY_TEMP_ADJ ).c_str() ); Log.verbose(F("WEB : formula=%s, temp-corr=%s." CR), server->arg( CFG_PARAM_GRAVITY_FORMULA ).c_str(), server->arg( CFG_PARAM_GRAVITY_TEMP_ADJ ).c_str() );
#endif #endif
myConfig.setGravityFormula( server->arg( CFG_PARAM_GRAVITY_FORMULA ).c_str() ); myConfig.setGravityFormula( server->arg( CFG_PARAM_GRAVITY_FORMULA ).c_str() );
myConfig.setGravityTempAdj( server->arg( CFG_PARAM_GRAVITY_TEMP_ADJ ).equalsIgnoreCase( "on" ) ? true:false); myConfig.setGravityTempAdj( server->arg( CFG_PARAM_GRAVITY_TEMP_ADJ ).equalsIgnoreCase( "on" ) ? true:false);
myConfig.saveFile(); myConfig.saveFile();
@ -370,18 +372,19 @@ void WebServer::webHandleConfigGravity() {
void WebServer::webHandleConfigHardware() { void WebServer::webHandleConfigHardware() {
LOG_PERF_START("webserver-api-config-hardware"); LOG_PERF_START("webserver-api-config-hardware");
String id = server->arg( CFG_PARAM_ID ); String id = server->arg( CFG_PARAM_ID );
#if LOG_LEVEL==6 Log.notice(F("WEB : webServer callback for /api/config/hardware." CR) );
Log.verbose(F("WEB : webServer callback for /api/config/hardware." CR) );
#endif
if( !id.equalsIgnoreCase( myConfig.getID() ) ) { if( !id.equalsIgnoreCase( myConfig.getID() ) ) {
Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), myConfig.getID()); Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), myConfig.getID());
server->send(400, "text/plain", "Invalid ID."); server->send(400, "text/plain", "Invalid ID.");
LOG_PERF_STOP("webserver-api-config-hardware"); LOG_PERF_STOP("webserver-api-config-hardware");
return; return;
} }
#if LOG_LEVEL==6
#if LOG_LEVEL==6 && !defined( WEB_DISABLE_LOGGING )
Log.verbose(F("WEB : vf=%s, tempadj=%s, ota=%s." CR), server->arg( CFG_PARAM_VOLTAGEFACTOR ).c_str(), server->arg( CFG_PARAM_TEMP_ADJ ).c_str(), server->arg( CFG_PARAM_OTA ).c_str() ); Log.verbose(F("WEB : vf=%s, tempadj=%s, ota=%s." CR), server->arg( CFG_PARAM_VOLTAGEFACTOR ).c_str(), server->arg( CFG_PARAM_TEMP_ADJ ).c_str(), server->arg( CFG_PARAM_OTA ).c_str() );
#endif #endif
myConfig.setVoltageFactor( server->arg( CFG_PARAM_VOLTAGEFACTOR ).toFloat() ); myConfig.setVoltageFactor( server->arg( CFG_PARAM_VOLTAGEFACTOR ).toFloat() );
myConfig.setTempSensorAdj( server->arg( CFG_PARAM_TEMP_ADJ ).toFloat() ); myConfig.setTempSensorAdj( server->arg( CFG_PARAM_TEMP_ADJ ).toFloat() );
myConfig.setOtaURL( server->arg( CFG_PARAM_OTA ).c_str() ); myConfig.setOtaURL( server->arg( CFG_PARAM_OTA ).c_str() );
@ -396,16 +399,15 @@ void WebServer::webHandleConfigHardware() {
// //
void WebServer::webHandleFormulaRead() { void WebServer::webHandleFormulaRead() {
LOG_PERF_START("webserver-api-formula-read"); LOG_PERF_START("webserver-api-formula-read");
#if LOG_LEVEL==6 Log.notice(F("WEB : webServer callback for /api/formula/get." CR));
Log.verbose(F("WEB : webServer callback for /api/formula/get." CR));
#endif
DynamicJsonDocument doc(250); DynamicJsonDocument doc(250);
const RawFormulaData& fd = myConfig.getFormulaData(); const RawFormulaData& fd = myConfig.getFormulaData();
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( WEB_DISABLE_LOGGING )
Log.verbose(F("WEB : %F %F %F %F %F." CR), fd.a[0], fd.a[1], fd.a[2], fd.a[3], fd.a[4] ); Log.verbose(F("WEB : %F %F %F %F %F." CR), fd.a[0], fd.a[1], fd.a[2], fd.a[3], fd.a[4] );
Log.verbose(F("WEB : %F %F %F %F %F." CR), fd.g[0], fd.g[1], fd.g[2], fd.g[3], fd.g[4] ); Log.verbose(F("WEB : %F %F %F %F %F." CR), fd.g[0], fd.g[1], fd.g[2], fd.g[3], fd.g[4] );
#endif #endif
doc[ CFG_PARAM_ID ] = myConfig.getID(); doc[ CFG_PARAM_ID ] = myConfig.getID();
doc[ CFG_PARAM_ANGLE ] = reduceFloatPrecision( myGyro.getAngle() ); doc[ CFG_PARAM_ANGLE ] = reduceFloatPrecision( myGyro.getAngle() );
@ -437,10 +439,11 @@ void WebServer::webHandleFormulaRead() {
doc[ "g4" ] = reduceFloatPrecision( fd.g[3], 4); doc[ "g4" ] = reduceFloatPrecision( fd.g[3], 4);
doc[ "g5" ] = reduceFloatPrecision( fd.g[4], 4); doc[ "g5" ] = reduceFloatPrecision( fd.g[4], 4);
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( WEB_DISABLE_LOGGING )
serializeJson(doc, Serial); serializeJson(doc, Serial);
Serial.print( CR ); Serial.print( CR );
#endif #endif
String out; String out;
serializeJson(doc, out); serializeJson(doc, out);
server->send(200, "application/json", out.c_str() ); server->send(200, "application/json", out.c_str() );
@ -453,19 +456,20 @@ void WebServer::webHandleFormulaRead() {
void WebServer::webHandleFormulaWrite() { void WebServer::webHandleFormulaWrite() {
LOG_PERF_START("webserver-api-formula-write"); LOG_PERF_START("webserver-api-formula-write");
String id = server->arg( CFG_PARAM_ID ); String id = server->arg( CFG_PARAM_ID );
#if LOG_LEVEL==6 Log.notice(F("WEB : webServer callback for /api/formula/post." CR) );
Log.verbose(F("WEB : webServer callback for /api/formula/post." CR) );
#endif
if( !id.equalsIgnoreCase( myConfig.getID() ) ) { if( !id.equalsIgnoreCase( myConfig.getID() ) ) {
Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), myConfig.getID()); Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), myConfig.getID());
server->send(400, "text/plain", "Invalid ID."); server->send(400, "text/plain", "Invalid ID.");
LOG_PERF_STOP("webserver-api-formula-write"); LOG_PERF_STOP("webserver-api-formula-write");
return; return;
} }
#if LOG_LEVEL==6
#if LOG_LEVEL==6 && !defined( WEB_DISABLE_LOGGING )
Log.verbose(F("WEB : angles=%F,%F,%F,%F,%F." CR), server->arg( "a1" ).toFloat(), server->arg( "a2" ).toFloat(), server->arg( "a3" ).toFloat(), server->arg( "a4" ).toFloat(), server->arg( "a5" ).toFloat() ); Log.verbose(F("WEB : angles=%F,%F,%F,%F,%F." CR), server->arg( "a1" ).toFloat(), server->arg( "a2" ).toFloat(), server->arg( "a3" ).toFloat(), server->arg( "a4" ).toFloat(), server->arg( "a5" ).toFloat() );
Log.verbose(F("WEB : gravity=%F,%F,%F,%F,%F." CR), server->arg( "g1" ).toFloat(), server->arg( "g2" ).toFloat(), server->arg( "g3" ).toFloat(), server->arg( "g4" ).toFloat(), server->arg( "g5" ).toFloat() ); Log.verbose(F("WEB : gravity=%F,%F,%F,%F,%F." CR), server->arg( "g1" ).toFloat(), server->arg( "g2" ).toFloat(), server->arg( "g3" ).toFloat(), server->arg( "g4" ).toFloat(), server->arg( "g5" ).toFloat() );
#endif #endif
RawFormulaData fd; RawFormulaData fd;
fd.a[0] = server->arg( "a1" ).toDouble(); fd.a[0] = server->arg( "a1" ).toDouble();
fd.a[1] = server->arg( "a2" ).toDouble(); fd.a[1] = server->arg( "a2" ).toDouble();
@ -516,9 +520,8 @@ void WebServer::webHandleFormulaWrite() {
// Helper function to check if files exist on file system. // Helper function to check if files exist on file system.
// //
const char* WebServer::getHtmlFileName( HtmlFile item ) { const char* WebServer::getHtmlFileName( HtmlFile item ) {
#if LOG_LEVEL==6 Log.notice(F("WEB : Looking up filename for %d." CR), item);
Log.verbose(F("WEB : Looking up filename for %d." CR), item);
#endif
switch( item ) { switch( item ) {
case HTML_INDEX: case HTML_INDEX:
return "index.min.htm"; return "index.min.htm";
@ -541,9 +544,9 @@ const char* WebServer::getHtmlFileName( HtmlFile item ) {
bool WebServer::checkHtmlFile( HtmlFile item ) { bool WebServer::checkHtmlFile( HtmlFile item ) {
const char *fn = getHtmlFileName( item ); const char *fn = getHtmlFileName( item );
#if LOG_LEVEL==6 #if LOG_LEVEL==6 && !defined( WEB_DISABLE_LOGGING )
Log.verbose(F("WEB : Checking for file %s." CR), fn ); Log.verbose(F("WEB : Checking for file %s." CR), fn );
#endif #endif
// TODO: We might need to add more checks here like zero file size etc. But for now we only check if the file exist. // TODO: We might need to add more checks here like zero file size etc. But for now we only check if the file exist.

View File

@ -52,7 +52,8 @@ bool Wifi::connect( bool showPortal ) {
Log.info(F("WIFI: No SSID seams to be stored, forcing portal to start." CR)); Log.info(F("WIFI: No SSID seams to be stored, forcing portal to start." CR));
showPortal = true; showPortal = true;
} else { } else {
Log.info(F("WIFI: Using SSID=%s and %s." CR), myConfig.getWifiSSID(), myConfig.getWifiPass() ); //Log.info(F("WIFI: Using SSID=%s and %s." CR), myConfig.getWifiSSID(), myConfig.getWifiPass() );
Log.info(F("WIFI: Using SSID=%s and %s." CR), myConfig.getWifiSSID(), "*****" );
} }
if( strlen(userSSID)==0 && showPortal ) { if( strlen(userSSID)==0 && showPortal ) {
@ -66,7 +67,8 @@ bool Wifi::connect( bool showPortal ) {
myWifiManager.setConfigPortalTimeout( 120 ); // Keep it open for 120 seconds myWifiManager.setConfigPortalTimeout( 120 ); // Keep it open for 120 seconds
bool f = myWifiManager.startConfigPortal( WIFI_DEFAULT_SSID, WIFI_DEFAULT_PWD ); bool f = myWifiManager.startConfigPortal( WIFI_DEFAULT_SSID, WIFI_DEFAULT_PWD );
if( f ) { if( f ) {
Log.notice(F("WIFI: Success got values from WIFI portal=%s,%s." CR), myWifiManager.getWiFiSSID(), myWifiManager.getWiFiPass() ); //Log.notice(F("WIFI: Success got values from WIFI portal=%s,%s." CR), myWifiManager.getWiFiSSID(), myWifiManager.getWiFiPass() );
Log.notice(F("WIFI: Success got values from WIFI portal=%s,%s." CR), myWifiManager.getWiFiSSID(), "*****" );
myConfig.setWifiSSID( myWifiManager.getWiFiSSID() ); myConfig.setWifiSSID( myWifiManager.getWiFiSSID() );
myConfig.setWifiPass( myWifiManager.getWiFiPass() ); myConfig.setWifiPass( myWifiManager.getWiFiPass() );
myConfig.saveFile(); myConfig.saveFile();
@ -90,18 +92,17 @@ bool Wifi::connect( bool showPortal ) {
WiFi.begin(myConfig.getWifiSSID(), myConfig.getWifiPass()); WiFi.begin(myConfig.getWifiSSID(), myConfig.getWifiPass());
} }
WiFi.printDiag(Serial); //WiFi.printDiag(Serial);
while( WiFi.status() != WL_CONNECTED ) { while( WiFi.status() != WL_CONNECTED ) {
yield(); delay(200);
delay(100);
Serial.print( "." ); Serial.print( "." );
/*if( i++ > 200 ) { // Try for 20 seconds. if( i++ > 100 ) { // Try for 20 seconds.
Log.error(F("WIFI: Failed to connect to wifi %d, aborting %s." CR), WiFi.status(), getIPAddress().c_str() ); Log.error(F("WIFI: Failed to connect to wifi %d, aborting %s." CR), WiFi.status(), getIPAddress().c_str() );
//WiFi.disconnect(); WiFi.disconnect();
return connectedFlag; // Return to main that we have failed to connect. return connectedFlag; // Return to main that we have failed to connect.
}*/ }
} }
Serial.print( CR ); Serial.print( CR );
connectedFlag = true; connectedFlag = true;