diff --git a/README.md b/README.md index 220c3a4..94f8784 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ I started this project out of curiosity for how a motion sensor is working and s * 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) -* Add option to enter SSID/Password as part of build proccess (since WifiManager does not support secure connections) * Add iSpindle 3D print cradle + small PCB (what I use for my builds) # Functionallity @@ -124,3 +123,9 @@ Not yet complete. I recommend that VSCODE with PlatformIO and Minfy extensions are used. Minify is used to reduce the size of the HTML files which are embedded into the firmware or uploaded to the file system. When using minify on a file, for example index.htm the output will be called index.min.htm. This is the file that will be used when buildning the image. By default the html files are embedded but there are options to upload them to the file system to reduce the size of the image if the size becomes to large for OTA. + +You can set the SSID and PWD as presets through platformio.ini by adding the settings to the following definitions: +``` +-D USER_SSID=\""\"" // =\""myssid\"" +-D USER_SSID_PWD=\""\"" // =\""mypwd\"" +``` diff --git a/bin/config.min.htm b/bin/config.min.htm index 9aa207f..99fd1df 100644 --- a/bin/config.min.htm +++ b/bin/config.min.htm @@ -1 +1 @@ -Beer Gravity Monitor

Temperature Format:


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

Temperature Format:


(C) Copyright 2021 Magnus Persson
\ No newline at end of file diff --git a/bin/device.min.htm b/bin/device.min.htm index 0a6cba7..dbff1be 100644 --- a/bin/device.min.htm +++ b/bin/device.min.htm @@ -14,4 +14,4 @@ - -->
(C) Copyright 2021 Magnus Persson
\ No newline at end of file + -->
(C) Copyright 2021 Magnus Persson
\ No newline at end of file diff --git a/bin/firmware-debug.bin b/bin/firmware-debug.bin index 7708b4d..dede29f 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 c8ca323..c04bfbf 100644 Binary files a/bin/firmware.bin and b/bin/firmware.bin differ diff --git a/bin/version.json b/bin/version.json index 10edd45..7b61a72 100644 --- a/bin/version.json +++ b/bin/version.json @@ -1 +1 @@ -{ "project":"gravmon", "version":"0.3.1", "html": [ "index.min.htm", "device.min.htm", "config.min.htm", "about.min.htm" ] } \ No newline at end of file +{ "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 diff --git a/data/config.htm b/data/config.htm index d9ed86f..acfd5af 100644 --- a/data/config.htm +++ b/data/config.htm @@ -105,6 +105,13 @@ +
+ +
+ +
+ +
@@ -155,13 +162,6 @@
-
- -
- -
- -
@@ -281,13 +281,13 @@ } ); }); - function updatePushInfo() { - var i = $("#push-interval").val() - $("#push-interval-info").text( Math.floor(i/60) + " m " + (i%60) + " s" ) + function updateSleepInfo() { + var i = $("#sleep-interval").val() + $("#sleep-interval-info").text( Math.floor(i/60) + " m " + (i%60) + " s" ) } // Trigger the calibration - $("#push-interval").keyup(updatePushInfo); + $("#sleep-interval").keyup(updateSleepInfo); function setButtonDisabled( b ) { $("#device-btn").prop("disabled", b); @@ -302,7 +302,7 @@ setButtonDisabled( true ); var url = "/api/config"; - var url = "/test/config.json"; + //var url = "/test/config.json"; $('#spinner').show(); $.getJSON(url, function (cfg) { console.log( cfg ); @@ -319,7 +319,7 @@ $("#http-push").val(cfg["http-push"]); $("#http-push2").val(cfg["http-push2"]); $("#brewfather-push").val(cfg["brewfather-push"]); - $("#push-interval").val(cfg["push-interval"]); + $("#sleep-interval").val(cfg["sleep-interval"]); $("#voltage-factor").val(cfg["voltage-factor"]); $("#gravity-formula").val(cfg["gravity-formula"]); $("#temp-adjustment-value").val(cfg["temp-adjustment-value"]); @@ -335,7 +335,7 @@ .always(function() { $('#spinner').hide(); setButtonDisabled( false ); - updatePushInfo(); + updateSleepInfo(); }); } diff --git a/data/config.min.htm b/data/config.min.htm index 26011af..99fd1df 100644 --- a/data/config.min.htm +++ b/data/config.min.htm @@ -1 +1 @@ -Beer Gravity Monitor

Temperature Format:


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

Temperature Format:


(C) Copyright 2021 Magnus Persson
\ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 7977840..efbcde0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -25,6 +25,8 @@ build_flags = #-O0 -Wl,-Map,output.map #-D SKIP_SLEEPMODE -D USE_LITTLEFS=true -D EMBED_HTML + -D USER_SSID=\""\"" # =\""myssid\"" + -D USER_SSID_PWD=\""\"" # =\""mypwd\"" -D CFG_APPVER="\"0.3.2\"" lib_deps = # https://github.com/jrowberg/i2cdevlib.git # Using local copy of this library diff --git a/src/config.cpp b/src/config.cpp index 54566fa..affe5dc 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -38,7 +38,7 @@ Config::Config() { sprintf(&buf[0], "" WIFI_MDNS "%s", getID() ); mDNS = &buf[0]; setTempFormat('C'); - setPushInterval(900); // 15 minutes + setSleepInterval(900); // 15 minutes setVoltageFactor(1.59); // Conversion factor for battery setTempSensorAdj(0.0); setGravityTempAdj(false); @@ -57,7 +57,8 @@ void Config::createJson(DynamicJsonDocument& doc) { doc[ CFG_PARAM_PUSH_BREWFATHER ] = getBrewfatherPushTarget(); doc[ CFG_PARAM_PUSH_HTTP ] = getHttpPushTarget(); doc[ CFG_PARAM_PUSH_HTTP2 ] = getHttpPushTarget2(); - doc[ CFG_PARAM_PUSH_INTERVAL ] = getPushInterval(); + doc[ CFG_PARAM_SLEEP_INTERVAL ] = getSleepInterval(); + doc[ CFG_PARAM_PUSH_INTERVAL ] = getSleepInterval(); // TODO: @deprecated doc[ CFG_PARAM_VOLTAGEFACTOR ] = getVoltageFactor(); doc[ CFG_PARAM_GRAVITY_FORMULA ] = getGravityFormula(); doc[ CFG_PARAM_TEMP_ADJ ] = getTempSensorAdj(); @@ -160,8 +161,10 @@ bool Config::loadFile() { setHttpPushTarget( doc[ CFG_PARAM_PUSH_HTTP ] ); if( !doc[ CFG_PARAM_PUSH_HTTP2 ].isNull() ) setHttpPushTarget2( doc[ CFG_PARAM_PUSH_HTTP2 ] ); - if( !doc[ CFG_PARAM_PUSH_INTERVAL ].isNull() ) - setPushInterval( doc[ CFG_PARAM_PUSH_INTERVAL ].as() ); + if( !doc[ CFG_PARAM_SLEEP_INTERVAL ].isNull() ) + setSleepInterval( doc[ CFG_PARAM_SLEEP_INTERVAL ].as() ); + if( !doc[ CFG_PARAM_PUSH_INTERVAL ].isNull() ) // TODO: @deprecated + setSleepInterval( doc[ CFG_PARAM_PUSH_INTERVAL ].as() ); // TODO: @deprecated if( !doc[ CFG_PARAM_VOLTAGEFACTOR ].isNull() ) setVoltageFactor( doc[ CFG_PARAM_VOLTAGEFACTOR ].as() ); if( !doc[ CFG_PARAM_GRAVITY_FORMULA ].isNull() ) @@ -230,7 +233,7 @@ void Config::debug() { Log.verbose(F("CFG : Push brewfather; '%s'." CR), getBrewfatherPushTarget() ); Log.verbose(F("CFG : Push http; '%s'." CR), getHttpPushTarget() ); Log.verbose(F("CFG : Push http2; '%s'." CR), getHttpPushTarget2() ); - Log.verbose(F("CFG : Push interval; %d." CR), getPushInterval() ); + Log.verbose(F("CFG : Sleep interval; %d." CR), getSleepInterval() ); // 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 ); #endif diff --git a/src/config.h b/src/config.h index 8923061..6eb48da 100644 --- a/src/config.h +++ b/src/config.h @@ -48,6 +48,8 @@ SOFTWARE. #define CFG_PARAM_PUSH_BREWFATHER "brewfather-push" // URL (brewfather format) #define CFG_PARAM_PUSH_HTTP "http-push" // URL (iSpindle format) #define CFG_PARAM_PUSH_HTTP2 "http-push2" // URL (iSpindle format) +#define CFG_PARAM_SLEEP_INTERVAL "sleep-interval" // Sleep interval +// TODO: @deprecated setting #define CFG_PARAM_PUSH_INTERVAL "push-interval" // Time between push #define CFG_PARAM_TEMPFORMAT "temp-format" // C or F #define CFG_PARAM_VOLTAGEFACTOR "voltage-factor" // Factor to calculate the battery voltage @@ -92,12 +94,12 @@ class Config { char tempFormat; // C, F float voltageFactor; float tempSensorAdj; // This value will be added to the read sensor value + int sleepInterval; // Push target settings String brewfatherPushTarget; String httpPushTarget; String httpPushTarget2; - int pushInterval; // Gravity and temperature calculations String gravityFormula; @@ -133,9 +135,9 @@ class Config { void setHttpPushTarget2( String s ) { httpPushTarget2 = s; saveNeeded = true; } bool isHttpActive2() { return httpPushTarget2.length()>0?true:false; } - int getPushInterval() { return pushInterval; } - void setPushInterval( int v ) { pushInterval = v; saveNeeded = true; } - void setPushInterval( String s ) { pushInterval = s.toInt(); saveNeeded = true; } + int getSleepInterval() { return sleepInterval; } + void setSleepInterval( int v ) { sleepInterval = v; saveNeeded = true; } + void setSleepInterval( String s ) { sleepInterval = s.toInt(); saveNeeded = true; } char getTempFormat() { return tempFormat; } void setTempFormat( char c ) { tempFormat = c; saveNeeded = true; } diff --git a/src/main.cpp b/src/main.cpp index a7b3936..c4bad85 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -187,12 +187,12 @@ void loop() { unsigned long runTime = millis() - startMillis; // Enter sleep mode... - Log.notice(F("MAIN: Entering deep sleep for %d s, run time %l s, battery=%F V." CR), myConfig.getPushInterval(), runTime/1000, volt ); + Log.notice(F("MAIN: Entering deep sleep for %d s, run time %l s, battery=%F V." CR), myConfig.getSleepInterval(), runTime/1000, volt ); LittleFS.end(); myGyro.enterSleep(); drd->stop(); delay(100); - deepSleep( myConfig.getPushInterval() ); + deepSleep( myConfig.getSleepInterval() ); } #if LOG_LEVEL==6 diff --git a/src/pushtarget.cpp b/src/pushtarget.cpp index e64cd5b..c7c3553 100644 --- a/src/pushtarget.cpp +++ b/src/pushtarget.cpp @@ -31,7 +31,7 @@ PushTarget myPushTarget; // void PushTarget::send(float angle, float gravity, float temp, float runTime, bool force ) { unsigned long timePassed = abs( millis() - ms ); - unsigned long interval = myConfig.getPushInterval()*1000; + unsigned long interval = myConfig.getSleepInterval()*1000; if( ( timePassed < interval ) && !force) { #if LOG_LEVEL==6 @@ -133,7 +133,7 @@ void PushTarget::sendHttp( String serverPath, float angle, float gravity, float doc["name"] = myConfig.getMDNS(); doc["ID"] = myConfig.getID(); doc["token"] = "gravmon"; - doc["interval"] = myConfig.getPushInterval(); + doc["interval"] = myConfig.getSleepInterval(); doc["temperature"] = reduceFloatPrecision( temp, 1 ); doc["temp-units"] = String( myConfig.getTempFormat() ); doc["gravity"] = reduceFloatPrecision( gravity, 4 ); diff --git a/src/resources.cpp b/src/resources.cpp index b62e9a3..7fb48d0 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -36,6 +36,7 @@ INCBIN(AboutHtm, "data/about.min.htm" ); // Minium web interface for uploading htm files INCBIN(UploadHtm, "data/upload.min.htm" ); + #endif // EOF \ No newline at end of file diff --git a/src/webserver.cpp b/src/webserver.cpp index adb0c38..6e7f38a 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -292,6 +292,7 @@ void webHandleConfigDevice() { #endif myConfig.setMDNS( server.arg( CFG_PARAM_MDNS ).c_str() ); myConfig.setTempFormat( server.arg( CFG_PARAM_TEMPFORMAT ).charAt(0) ); + myConfig.setSleepInterval( server.arg( CFG_PARAM_SLEEP_INTERVAL ).c_str() ); myConfig.saveFile(); server.sendHeader("Location", "/config.htm#collapseOne", true); server.send(302, "text/plain", "Device config updated" ); @@ -316,7 +317,6 @@ void webHandleConfigPush() { myConfig.setHttpPushTarget( server.arg( CFG_PARAM_PUSH_HTTP ).c_str() ); myConfig.setHttpPushTarget2( server.arg( CFG_PARAM_PUSH_HTTP2 ).c_str() ); myConfig.setBrewfatherPushTarget( server.arg( CFG_PARAM_PUSH_BREWFATHER ).c_str() ); - myConfig.setPushInterval( server.arg( CFG_PARAM_PUSH_INTERVAL ).c_str() ); myConfig.saveFile(); server.sendHeader("Location", "/config.htm#collapseTwo", true); server.send(302, "text/plain", "Push config updated" ); diff --git a/src/wifi.cpp b/src/wifi.cpp index cb66b8a..26bd2b4 100644 --- a/src/wifi.cpp +++ b/src/wifi.cpp @@ -39,6 +39,9 @@ Wifi myWifi; WiFiManager myWifiManager; bool shouldSaveConfig = false; +const char* userSSID= USER_SSID; +const char* userPWD = USER_SSID_PWD; + // // Callback notifying us of the need to save config // @@ -56,7 +59,7 @@ bool Wifi::connect( bool showPortal ) { #endif unsigned long startMillis = millis(); - if( showPortal ) { + if( strlen(userSSID)==0 && showPortal ) { Log.notice(F("WIFI: Starting wifi portal." CR)); myWifiManager.setBreakAfterConfig( true ); @@ -79,7 +82,13 @@ bool Wifi::connect( bool showPortal ) { // Connect to wifi int i = 0; - WiFi.begin(); + if( strlen(userSSID) ) { + Log.notice(F("WIFI: connecting to wifi using predefined settings %s." CR), userSSID); + WiFi.begin( userSSID, userPWD ); + } else { + WiFi.begin(); + } + while( WiFi.status() != WL_CONNECTED ) { delay(100); Serial.print( "." ); diff --git a/test/config.json b/test/config.json index a0391f5..fbeb053 100644 --- a/test/config.json +++ b/test/config.json @@ -1 +1,26 @@ -{"mdns":"gravitymon2","id":"ee1bfc","ota-url":"","temp-format":"C","brewfather-push":"","http-push":"http://192.168.1.16:9090/api/v1/V7s7vRXLqnsW3HdxxRuD/telemetry","http-push2":"http://192.168.1.16:9090/test", "push-interval":30,"voltage-factor":1.59,"gravity-formula":"0.0*tilt^3+0.0*tilt^2+0.0017978*tilt+0.9436","temp-adjustment-value":0,"gravity-temp-adjustment":false,"gyro-calibration-data":{"ax":-4814,"ay":1143,"az":2270,"gx":47,"gy":-25,"gz":47},"angle":90.38,"gravity":1.1106,"battery":4.24} \ No newline at end of file +{ + "mdns": "gravitymon2", + "id": "ee1bfc", + "ota-url": "", + "temp-format": "C", + "brewfather-push": "", + "http-push": "http://192.168.1.16:9090/api/v1/V7s7vRXLqnsW3HdxxRuD/telemetry", + "http-push2": "http://192.168.1.16:9090/test", + "sleep-interval": 30, + "push-interval": 30, + "voltage-factor": 1.59, + "gravity-formula": "0.0*tilt^3+0.0*tilt^2+0.0017978*tilt+0.9436", + "temp-adjustment-value": 0, + "gravity-temp-adjustment": false, + "gyro-calibration-data": { + "ax": -4814, + "ay": 1143, + "az": 2270, + "gx": 47, + "gy": -25, + "gz": 47 + }, + "angle": 90.38, + "gravity": 1.1106, + "battery": 4.24 +} \ No newline at end of file diff --git a/test/device.json b/test/device.json index dff84b7..ea87d67 100644 --- a/test/device.json +++ b/test/device.json @@ -1 +1,6 @@ -{"app-name":"GravityMon ","app-ver":"0.0.0","id":"7376ef","mdns":"gravmon"} \ No newline at end of file +{ + "app-name": "GravityMon ", + "app-ver": "0.0.0", + "id": "7376ef", + "mdns": "gravmon" +} \ No newline at end of file