diff --git a/README.md b/README.md index 94f8784..4529d56 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ I started this project out of curiosity for how a motion sensor is working and s * Add support for Plato in device (today it assumes that formula is in SG). * Add support for converting between SG/Plato in device. -* Add support for InfluxDB as endpoint * Add support for Blynk as endpoint * Add support for https connections (push) * Add support for https web server (will require certificates to be created as part of build process) @@ -54,11 +53,15 @@ The device page shows the device settings and software versions. http://gravmon.local/config.htm -This page is divided into several categories of settings. The first one contains device settings, mDNS name, temperature format, and gyro calibration data. Calibration needs to be done or the device will not work correctly. Place the device flat on a surface with gyro up and press the calibrate button when it's stable. +This page is divided into several categories of settings. The first one contains device settings, mDNS name, temperature format, and gyro calibration data. The interval setting is the amount of time the device will be in sleep mode between readings (interval is in seconds). + +Calibration needs to be done or the device will not work correctly. Place the device flat on a surface with gyro up and press the calibrate button when it's stable. + +__TODO: Update image for config settings.__ ![Config - Device](img/config1.png) -The second section contains the push settings, two URL's for http sending and one for Brewfather. The interval setting is the amount of time the device will be in sleep mode between readings (interval is in seconds). +The second section contains the push settings, two URL's for http posts, Brewfather and settings for InfluxDB v2. ### This is the format used for standard http posts. ``` @@ -73,7 +76,7 @@ The second section contains the push settings, two URL's for http sending and on "angle": 45.34, "battery": 3.67, "rssi": -12, - "run-time": 2.30, // Runtime for this reading, this is an extension + "run-time": 230, // ms, Runtime for this reading, this is an additional field not part of the standard format } ``` @@ -90,6 +93,18 @@ The second section contains the push settings, two URL's for http sending and on } ``` +### This is the format for InfluxDB v2 + +``` +gravity,host=,device=,format=SG value=1.0004 +angle,host=,device= value=45.45 +temp,host=,device=,format= value=20.1 +battery,host=,device= value=3.96 +rssi,host=,device= value=-18 +``` + +__TODO: Update image for push settings.__ + ![Config - Push](img/config2.png) The third section contains the gravity options, formlua and option for temperature correcting gravity. diff --git a/bin/device.min.htm b/bin/device.min.htm index dbff1be..93d8388 100644 --- a/bin/device.min.htm +++ b/bin/device.min.htm @@ -1,17 +1 @@ -Beer Gravity Monitor

Current version:
Loading...
Host name:
Loading...
Device ID:
Loading...

(C) Copyright 2021 Magnus Persson
\ No newline at end of file +Beer Gravity Monitor

Current version:
Loading...
Host name:
Loading...
Device ID:
Loading...

(C) Copyright 2021 Magnus Persson
\ No newline at end of file diff --git a/bin/firmware-debug.bin b/bin/firmware-debug.bin index cb169be..6648e93 100644 Binary files a/bin/firmware-debug.bin and b/bin/firmware-debug.bin differ diff --git a/bin/firmware.bin b/bin/firmware.bin index 9e146b7..832f534 100644 Binary files a/bin/firmware.bin and b/bin/firmware.bin differ diff --git a/bin/version.json b/bin/version.json index 7b61a72..11cabea 100644 --- a/bin/version.json +++ b/bin/version.json @@ -1 +1 @@ -{ "project":"gravmon", "version":"0.3.2", "html": [ "index.min.htm", "device.min.htm", "config.min.htm", "about.min.htm" ] } \ No newline at end of file +{ "project":"gravmon", "version":"0.3.5", "html": [ "index.min.htm", "device.min.htm", "config.min.htm", "about.min.htm" ] } \ No newline at end of file diff --git a/data/device.htm b/data/device.htm index c654e6e..0f6526d 100644 --- a/data/device.htm +++ b/data/device.htm @@ -1,12 +1,6 @@ - - @@ -91,21 +85,6 @@
Device ID:
Loading...
- - -
diff --git a/data/device.min.htm b/data/device.min.htm index 2f5c2c3..93d8388 100644 --- a/data/device.min.htm +++ b/data/device.min.htm @@ -1,17 +1 @@ -Beer Gravity Monitor

Current version:
Loading...
Host name:
Loading...
Device ID:
Loading...

(C) Copyright 2021 Magnus Persson
\ No newline at end of file +Beer Gravity Monitor

Current version:
Loading...
Host name:
Loading...
Device ID:
Loading...

(C) Copyright 2021 Magnus Persson
\ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 6d2626f..9415a7a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -50,7 +50,7 @@ extra_scripts = 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 or influxdb + -D COLLECT_PERFDATA # This option will collect runtime data for a few defined methods to measure time, dumped to serial and/or influxdb -D LOG_LEVEL=6 # Maximum log level for the debug build. lib_deps = ${common_env_data.lib_deps} @@ -69,6 +69,7 @@ extra_scripts = 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 -D LOG_LEVEL=5 lib_deps = ${common_env_data.lib_deps} diff --git a/src/config.cpp b/src/config.cpp index 4848eb1..a0b77e6 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -137,7 +137,7 @@ bool Config::loadFile() { return false; } - Log.notice(F("CFG : Size of configuration %d bytes." CR), configFile.size() ); + Log.notice(F("CFG : Size of configuration file=%d bytes." CR), configFile.size() ); DynamicJsonDocument doc(CFG_JSON_BUFSIZE); DeserializationError err = deserializeJson(doc, configFile); diff --git a/src/helper.cpp b/src/helper.cpp index 5f046cd..9bec992 100644 --- a/src/helper.cpp +++ b/src/helper.cpp @@ -194,9 +194,9 @@ void PerfLogging::pushInflux() { int httpResponseCode = http.POST(body); if (httpResponseCode==204) { - Log.notice(F("PUSH: InfluxDB2 HTTP Response code %d" CR), httpResponseCode); + Log.notice(F("PERF: InfluxDB2 push performance data successful, response=%d" CR), httpResponseCode); } else { - Log.error(F("PUSH: InfluxDB2 HTTP Response code %d" CR), httpResponseCode); + Log.error(F("PERF: InfluxDB2 push performance data failed, response=%d" CR), httpResponseCode); } http.end(); diff --git a/src/helper.h b/src/helper.h index 683f9e0..08cc0b7 100644 --- a/src/helper.h +++ b/src/helper.h @@ -125,13 +125,14 @@ extern PerfLogging myPerfLogging; // Use these to collect performance data from various parts of the code #define LOG_PERF_START(s) myPerfLogging.start(s) #define LOG_PERF_STOP(s) myPerfLogging.stop(s) -#define LOG_PERF_PRINT() myPerfLogging.print() +//#define LOG_PERF_PRINT() myPerfLogging.print() +#define LOG_PERF_PRINT() #define LOG_PERF_CLEAR() myPerfLogging.clear() #define LOG_PERF_PUSH() myPerfLogging.pushInflux() #else -// These will disable the performance collection +// These will disable the performance collection function #define LOG_PERF_START(s) #define LOG_PERF_STOP(s) #define LOG_PERF_PRINT() diff --git a/src/main.cpp b/src/main.cpp index 73c627f..a147c75 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -97,7 +97,6 @@ void setup() { drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS); bool dt = drd->detectDoubleReset(); - #if LOG_LEVEL==6 Log.verbose(F("Main: Reset reason %s." CR), ESP.getResetInfo().c_str() ); #endif @@ -105,7 +104,6 @@ void setup() { Log.notice(F("Main: Started setup for %s." CR), String( ESP.getChipId(), HEX).c_str() ); printBuildOptions(); - Log.notice(F("Main: Loading configuration." CR)); LOG_PERF_START("main-config-load"); myConfig.checkFileSystem(); myConfig.loadFile(); @@ -128,7 +126,6 @@ void setup() { if( dt ) Log.notice(F("Main: Detected doubletap on reset." CR)); - Log.notice(F("Main: Connecting to wifi." CR)); LOG_PERF_START("main-wifi-connect"); myWifi.connect( dt ); LOG_PERF_STOP("main-wifi-connect"); @@ -143,8 +140,6 @@ void setup() { checkSleepMode( myGyro.getAngle(), myBatteryVoltage.getVoltage() ); if( myWifi.isConnected() ) { - Log.notice(F("Main: Connected to wifi ip=%s." CR), myWifi.getIPAddress().c_str() ); - #if defined( ACTIVATE_OTA ) LOG_PERF_START("main-wifi-ota"); if( !sleepModeActive && myWifi.checkFirmwareVersion() ) { @@ -154,8 +149,7 @@ void setup() { #endif if( !sleepModeActive ) { LOG_PERF_START("main-webserver-setup"); - if( myWebServer.setupWebServer() ) - Log.notice(F("Main: Webserver is running." CR) ); + myWebServer.setupWebServer(); LOG_PERF_STOP("main-webserver-setup"); } } @@ -163,6 +157,7 @@ void setup() { LOG_PERF_STOP("main-setup"); LOG_PERF_PRINT(); // Dump data to serial LOG_PERF_PUSH(); // Dump data to influx + Log.notice(F("Main: Setup completed." CR)); } // diff --git a/src/pushtarget.cpp b/src/pushtarget.cpp index 3d2f937..898cf4e 100644 --- a/src/pushtarget.cpp +++ b/src/pushtarget.cpp @@ -87,11 +87,13 @@ void PushTarget::sendInfluxDb2(float angle, float gravity, float temp, float run // Create body for influxdb2 char buf[1024]; sprintf( &buf[0], "gravity,host=%s,device=%s,format=%s value=%.4f\n" + "angle,host=%s,device=%s value=%.2f\n" "temp,host=%s,device=%s,format=%c value=%.1f\n" "battery,host=%s,device=%s value=%.2f\n" "rssi,host=%s,device=%s value=%d\n", // TODO: Add support for plato format myConfig.getMDNS(), myConfig.getID(), "SG", gravity, + myConfig.getMDNS(), myConfig.getID(), angle, myConfig.getMDNS(), myConfig.getID(), myConfig.getTempFormat(), temp, myConfig.getMDNS(), myConfig.getID(), myBatteryVoltage.getVoltage(), myConfig.getMDNS(), myConfig.getID(), WiFi.RSSI() ); @@ -107,9 +109,9 @@ void PushTarget::sendInfluxDb2(float angle, float gravity, float temp, float run int httpResponseCode = http.POST(&buf[0]); if (httpResponseCode==204) { - Log.notice(F("PUSH: InfluxDB2 HTTP Response code %d" CR), httpResponseCode); + Log.notice(F("PUSH: InfluxDB2 push successful, response=%d" CR), httpResponseCode); } else { - Log.error(F("PUSH: InfluxDB2 HTTP Response code %d" CR), httpResponseCode); + Log.error(F("PUSH: InfluxDB2 push failed, response=%d" CR), httpResponseCode); } http.end(); @@ -167,9 +169,9 @@ void PushTarget::sendBrewfather(float angle, float gravity, float temp ) { int httpResponseCode = http.POST(json); if (httpResponseCode==200) { - Log.notice(F("PUSH: Brewfather HTTP Response code %d" CR), httpResponseCode); + Log.notice(F("PUSH: Brewfather push successful, response=%d" CR), httpResponseCode); } else { - Log.error(F("PUSH: Brewfather HTTP Response code %d" CR), httpResponseCode); + Log.error(F("PUSH: Brewfather push failed, response=%d" CR), httpResponseCode); } http.end(); @@ -217,9 +219,9 @@ void PushTarget::sendHttp( String serverPath, float angle, float gravity, float int httpResponseCode = http.POST(json); if (httpResponseCode==200) { - Log.notice(F("PUSH: HTTP Response code %d" CR), httpResponseCode); + Log.notice(F("PUSH: HTTP push successful, response=%d" CR), httpResponseCode); } else { - Log.error(F("PUSH: HTTP Response code %d" CR), httpResponseCode); + Log.error(F("PUSH: HTTP push failed, response=%d" CR), httpResponseCode); } http.end(); diff --git a/src/webserver.cpp b/src/webserver.cpp index 062cde2..09e9cfe 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -444,7 +444,7 @@ bool WebServer::checkHtmlFile( HtmlFile item ) { // Setup the Web Server callbacks and start it // bool WebServer::setupWebServer() { - Log.notice(F("WEB : Web server setup started." CR)); + Log.notice(F("WEB : Configuring web server." CR)); MDNS.begin( myConfig.getMDNS() ); MDNS.addService("http", "tcp", 80); diff --git a/src/wifi.cpp b/src/wifi.cpp index 26bd2b4..00308c6 100644 --- a/src/wifi.cpp +++ b/src/wifi.cpp @@ -57,8 +57,6 @@ bool Wifi::connect( bool showPortal ) { Log.verbose(F("WIFI: Connecting to WIFI via connection manager (portal=%s)." CR), showPortal?"true":"false"); myWifiManager.setDebugOutput(true); #endif - unsigned long startMillis = millis(); - if( strlen(userSSID)==0 && showPortal ) { Log.notice(F("WIFI: Starting wifi portal." CR)); @@ -82,8 +80,9 @@ bool Wifi::connect( bool showPortal ) { // Connect to wifi int i = 0; + Log.notice(F("WIFI: Connecting to WIFI." CR)); if( strlen(userSSID) ) { - Log.notice(F("WIFI: connecting to wifi using predefined settings %s." CR), userSSID); + Log.notice(F("WIFI: Connecting to wifi using predefined settings %s." CR), userSSID); WiFi.begin( userSSID, userPWD ); } else { WiFi.begin(); @@ -100,13 +99,7 @@ bool Wifi::connect( bool showPortal ) { } Serial.print( CR ); connectedFlag = true; - - Log.notice( F("WIFI: IP=%s, Connect time %d s" CR), WiFi.localIP().toString().c_str(), abs(millis() - startMillis)/1000); - -#if LOG_LEVEL==6 - Log.verbose(F("WIFI: Connect returned %s." CR), connectedFlag?"True":"False" ); -#endif - + Log.notice(F("WIFI: Connected to wifi ip=%s." CR), getIPAddress().c_str() ); return connectedFlag; } @@ -116,7 +109,7 @@ bool Wifi::connect( bool showPortal ) { bool Wifi::disconnect() { Log.notice(F("WIFI: Erasing stored WIFI credentials." CR)); // Erase WIFI credentials - return WiFi.disconnect(); + return WiFi.disconnect(true); } #if defined( ACTIVATE_OTA ) @@ -141,12 +134,13 @@ bool Wifi::updateFirmware() { switch(ret) { case HTTP_UPDATE_FAILED: - Log.error(F("WIFI: Updating failed %d, %s." CR), ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); + Log.error(F("WIFI: OTA update failed %d, %s." CR), ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); break; case HTTP_UPDATE_NO_UPDATES: break; case HTTP_UPDATE_OK: - Log.notice("WIFI: Updated succesfull, rebooting." ); + Log.notice("WIFI: OTA Update sucesfull, rebooting." ); + delay(100); ESP.reset(); break; } @@ -175,7 +169,7 @@ void Wifi::downloadFile(const char *fname) { f.close(); Log.notice(F("WIFI: Downloaded file %s." CR), fname); } else { - Log.error(F("WIFI: HTTP Response code %d" CR), httpResponseCode); + Log.error(F("WIFI: Failed to download file, respone=%d" CR), httpResponseCode); } http.end(); } @@ -199,7 +193,7 @@ bool Wifi::checkFirmwareVersion() { int httpResponseCode = http.GET(); if (httpResponseCode==200) { - Log.notice(F("WIFI: HTTP Response code %d" CR), httpResponseCode); + Log.notice(F("WIFI: Found version.json, response=%d" CR), httpResponseCode); String payload = http.getString(); #if LOG_LEVEL==6 @@ -208,7 +202,7 @@ bool Wifi::checkFirmwareVersion() { DynamicJsonDocument ver(300); DeserializationError err = deserializeJson(ver, payload); if( err ) { - Log.error(F("WIFI: Failed to parse json, %s" CR), err); + Log.error(F("WIFI: Failed to parse version.json, %s" CR), err); } else { #if LOG_LEVEL==6 Log.verbose(F("WIFI: Project %s version %s." CR), (const char*) ver["project"], (const char*) ver["version"]); @@ -219,7 +213,7 @@ bool Wifi::checkFirmwareVersion() { if( parseFirmwareVersionString( newVer, (const char*) ver["version"] ) ) { if( parseFirmwareVersionString( curVer, CFG_APPVER) ) { #if LOG_LEVEL==6 - Log.verbose(F("OTA : Checking New=%d.%d.%d Cur=%d.%d.%d" CR), newVer[0], newVer[1], newVer[2], curVer[0], curVer[1], curVer[2] ); + Log.verbose(F("WIFI: OTA checking new=%d.%d.%d cur=%d.%d.%d" CR), newVer[0], newVer[1], newVer[2], curVer[0], curVer[1], curVer[2] ); #endif // Compare major version if( newVer[0] > curVer[0] ) @@ -235,23 +229,23 @@ bool Wifi::checkFirmwareVersion() { // Download new html files to filesystem if they are present. if( !ver["html"].isNull() && newFirmware ) { - Log.notice(F("OTA : Downloading new html files." CR)); + Log.notice(F("WIFI: OTA downloading new html files." CR)); JsonArray htmlFiles = ver["html"].as(); for(JsonVariant v : htmlFiles) { String s = v; #if LOG_LEVEL==6 - Log.verbose(F("OTA : Html file found %s" CR), s.c_str() ); + Log.verbose(F("WIFI: OTA listed html file %s" CR), s.c_str() ); #endif downloadFile( s.c_str() ); } } } } else { - Log.error(F("WIFI: HTTP Response code %d" CR), httpResponseCode); + Log.error(F("WIFI: OTA error checking version.json, response=%d" CR), httpResponseCode); } http.end(); #if LOG_LEVEL==6 - Log.verbose(F("WIFI: Found new version %s." CR), newFirmware?"true":"false"); + Log.verbose(F("WIFI: OTA found new version %s." CR), newFirmware?"true":"false"); #endif return newFirmware; } @@ -261,7 +255,7 @@ bool Wifi::checkFirmwareVersion() { // bool Wifi::parseFirmwareVersionString( int (&num)[3], const char *version ) { #if LOG_LEVEL==6 - Log.verbose(F("WIFI: Parsing version number %s." CR), version); + Log.verbose(F("WIFI: Parsing version number string %s." CR), version); #endif char temp[80]; char *s;