Minor fixes + changed wifi and drd libraries

This commit is contained in:
Magnus
2021-03-28 15:30:43 +02:00
parent f56ef0c56f
commit a0d172540b
16 changed files with 71 additions and 48 deletions

File diff suppressed because one or more lines are too long

View File

@ -14,4 +14,4 @@
<button type="button" class="btn btn-warning" id="wifi-reset-btn">Factory default settings</button>
</div>
</div>
--><hr class="my-4"></div><script type="text/javascript">function getConfig(){var n="/api/device";$("#spinner").show(),$.getJSON(n,function(n){console.log(n),$("#app-ver").text(n["app-ver"]+" (html 0.2.1)"),$("#mdns").text(n.mdns),$("#id").text(n.id)}).fail(function(){showError("Unable to get data from the device.")}).always(function(){$("#spinner").hide()})}window.onload=getConfig</script><!-- START FOOTER --><div class="container-fluid themed-container bg-primary text-light">(C) Copyright 2021 Magnus Persson</div></body></html>
--><hr class="my-4"></div><script type="text/javascript">function getConfig(){var n="/api/device";$("#spinner").show(),$.getJSON(n,function(n){console.log(n),$("#app-ver").text(n["app-ver"]+" (html 0.2.2)"),$("#mdns").text(n.mdns),$("#id").text(n.id)}).fail(function(){showError("Unable to get data from the device.")}).always(function(){$("#spinner").hide()})}window.onload=getConfig</script><!-- START FOOTER --><div class="container-fluid themed-container bg-primary text-light">(C) Copyright 2021 Magnus Persson</div></body></html>

Binary file not shown.

Binary file not shown.

View File

@ -1 +1 @@
{ "project":"gravmon", "version":"0.2.1", "html": [ "index.min.htm", "device.min.htm", "config.min.htm", "about.min.htm" ] }
{ "project":"gravmon", "version":"0.2.2", "html": [ "index.min.htm", "device.min.htm", "config.min.htm", "about.min.htm" ] }

View File

@ -138,19 +138,19 @@
<form action="/api/config/push" method="post">
<input type="text" name="id" id="id2" hidden>
<div class="form-group row">
<label for="http-push" class="col-sm-4 col-form-label">Http 1:</label>
<label for="http-push" class="col-sm-4 col-form-label">Http URL 1:</label>
<div class="col-sm-8">
<input type="url" maxlength="90" class="form-control" name="http-push" id="http-push">
</div>
</div>
<div class="form-group row">
<label for="http-push2" class="col-sm-4 col-form-label">Http 2:</label>
<label for="http-push2" class="col-sm-4 col-form-label">Http URL 2:</label>
<div class="col-sm-8">
<input type="url" maxlength="90" class="form-control" name="http-push2" id="http-push2">
</div>
</div>
<div class="form-group row">
<label for="inputBrewfatherPush" class="col-sm-4 col-form-label">Brewfather:</label>
<label for="inputBrewfatherPush" class="col-sm-4 col-form-label">Brewfather URL:</label>
<div class="col-sm-8">
<input type="url" maxlength="90" class="form-control" name="brewfather-push" id="brewfather-push">
</div>
@ -235,7 +235,7 @@
<input type="number" step=".1" class="form-control" name="temp-adjustment-value" id="temp-adjustment-value">
</div>
</div>
<div class="form-group row" hidden>
<div class="form-group row">
<label for="ota-url" class="col-sm-4 col-form-label">OTA base URL:</label>
<div class="col-sm-8">
<input type="url" maxlength="90" class="form-control" name="ota-url" id="ota-url">

File diff suppressed because one or more lines are too long

View File

@ -118,7 +118,7 @@
$('#spinner').show();
$.getJSON(url, function (cfg) {
console.log( cfg );
$("#app-ver").text(cfg["app-ver"] + " (html 0.2.1)");
$("#app-ver").text(cfg["app-ver"] + " (html 0.2.2)");
$("#mdns").text(cfg["mdns"]);
$("#id").text(cfg["id"]);
})

View File

@ -14,4 +14,4 @@
<button type="button" class="btn btn-warning" id="wifi-reset-btn">Factory default settings</button>
</div>
</div>
--><hr class="my-4"></div><script type="text/javascript">function getConfig(){var n="/api/device";$("#spinner").show(),$.getJSON(n,function(n){console.log(n),$("#app-ver").text(n["app-ver"]+" (html 0.2.1)"),$("#mdns").text(n.mdns),$("#id").text(n.id)}).fail(function(){showError("Unable to get data from the device.")}).always(function(){$("#spinner").hide()})}window.onload=getConfig</script><!-- START FOOTER --><div class="container-fluid themed-container bg-primary text-light">(C) Copyright 2021 Magnus Persson</div></body></html>
--><hr class="my-4"></div><script type="text/javascript">function getConfig(){var n="/api/device";$("#spinner").show(),$.getJSON(n,function(n){console.log(n),$("#app-ver").text(n["app-ver"]+" (html 0.2.2)"),$("#mdns").text(n.mdns),$("#id").text(n.id)}).fail(function(){showError("Unable to get data from the device.")}).always(function(){$("#spinner").hide()})}window.onload=getConfig</script><!-- START FOOTER --><div class="container-fluid themed-container bg-primary text-light">(C) Copyright 2021 Magnus Persson</div></body></html>

View File

@ -26,16 +26,16 @@ build_flags = #-O0 -Wl,-Map,output.map
#-D SKIP_SLEEPMODE
-D USE_LITTLEFS=true
#-D EMBED_HTML
-D CFG_APPVER="\"0.2.1\""
-D CFG_APPVER="\"0.2.2\""
lib_deps =
# https://github.com/jrowberg/i2cdevlib.git # Using local copy of this library
https://github.com/codeplea/tinyexpr
https://github.com/graphitemaster/incbin
https://github.com/khoih-prog/ESP_MultiResetDetector
https://github.com/khoih-prog/ESP_DoubleResetDetector
https://github.com/khoih-prog/ESP_WiFiManager
https://github.com/thijse/Arduino-Log
https://github.com/bblanchon/ArduinoJson
https://github.com/PaulStoffregen/OneWire
https://github.com/tzapu/WiFiManager
https://github.com/milesburton/Arduino-Temperature-Control-Library
[env:gravity-debug]

View File

@ -46,5 +46,5 @@ def after_build(source, target, env):
f.close()
print( "Adding custom build step: (create json)")
print( "Adding custom build step (create json):")
env.AddPreAction("buildprog", after_build)

View File

@ -32,27 +32,27 @@ SOFTWARE.
#include <LittleFS.h>
// Settings for double reset detector.
#define ESP_MRD_USE_LITTLEFS true
#define ESP_MRD_USE_SPIFFS false
#define ESP_MRD_USE_EEPROM false
#define MRD_TIMES 3
#define MRD_TIMEOUT 10
#define MRD_ADDRESS 0
//#define MULTIRESETDETECTOR_DEBUG true
#include <ESP_MultiResetDetector.h>
MultiResetDetector *mrd;
//#define USE_LITTLEFS true
//#define ESP_DRD_USE_LITTLEFS true
#define ESP8266_DRD_USE_RTC true
#define DRD_TIMEOUT 1
#define DRD_ADDRESS 0
#define DOUBLERESETDETECTOR_DEBUG true
#include <ESP_DoubleResetDetector.h>
DoubleResetDetector *drd;
// Define constats for this program
#if LOG_LEVEL==6
const int interval = 1000; // ms, time to wait between changes to output
bool sleepModeAlwaysSkip = true; // Web interface can override normal behaviour
#else
const int interval = 100; // ms, time to wait between changes to output
const int interval = 200; // ms, time to wait between changes to output
bool sleepModeAlwaysSkip = false; // Web interface can override normal behaviour
#endif
unsigned long lastMillis = 0;
unsigned long startMillis;
bool sleepModeActive = false;
int loopCounter = 0;
//
// Check if we should be in sleep mode
@ -94,8 +94,6 @@ void checkSleepMode( float angle, float volt ) {
//
void setup() {
startMillis = millis();
mrd = new MultiResetDetector(MRD_TIMEOUT, MRD_ADDRESS);
bool dt = mrd->detectMultiReset();
#if LOG_LEVEL==6
Log.verbose(F("Main: Reset reason %s." CR), ESP.getResetInfo().c_str() );
@ -118,13 +116,14 @@ void setup() {
if( !myGyro.setup() )
Log.error(F("Main: Failed to initialize the gyro." CR));
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
bool dt = drd->detectDoubleReset();
if( dt )
Log.notice(F("Main: Detected doubletap on reset." CR));
Log.notice(F("Main: Connecting to wifi." CR));
myWifi.connect( dt );
Log.notice(F("Main: WIFI connected." CR));
myGyro.read();
myBatteryVoltage.read();
checkSleepMode( myGyro.getAngle(), myBatteryVoltage.getVoltage() );
@ -147,11 +146,12 @@ void setup() {
// Main loops
//
void loop() {
mrd->loop();
drd->loop();
if( sleepModeActive || abs(millis() - lastMillis) > interval ) {
float angle = 90;
float volt = myBatteryVoltage.getVoltage();
loopCounter++;
#if LOG_LEVEL==6
Log.verbose(F("Main: Entering main loop." CR) );
#endif
@ -170,6 +170,8 @@ void loop() {
#endif
}
// Limit the printout when sleep mode is not active.
if( loopCounter%10 == 0 || sleepModeActive )
Log.notice(F("Main: Gyro angle=%F, temp=%F, gravity=%F, batt=%F." CR), angle, temp, gravity, volt );
#if defined( ACTIVATE_PUSH )
@ -185,10 +187,10 @@ void loop() {
unsigned long runTime = millis() - startMillis;
// Enter sleep mode...
Log.notice(F("MAIN: Entering deep sleep, run time %l s." CR), runTime/1000 );
Log.notice(F("MAIN: Entering deep sleep for %d s, run time %l s, battery=%F V." CR), myConfig.getPushInterval(), runTime/1000, volt );
LittleFS.end();
myGyro.enterSleep();
mrd->stop();
drd->stop();
delay(100);
deepSleep( myConfig.getPushInterval() );
}

View File

@ -131,15 +131,19 @@ void PushTarget::sendHttp( String serverPath, float angle, float gravity, float
DynamicJsonDocument doc(256);
// Use iSpindle format for compatibility
doc["name"] = myConfig.getMDNS();
doc["temp"] = reduceFloatPrecision( temp, 1 );
doc["temp-unit"] = String( myConfig.getTempFormat() );
doc["ID"] = myConfig.getMDNS();
doc["token"] = "gravmon";
doc["interval"] = myConfig.getPushInterval();
doc["temperature"] = reduceFloatPrecision( temp, 1 );
doc["temp-units"] = String( myConfig.getTempFormat() );
doc["gravity"] = reduceFloatPrecision( gravity, 4 );
doc["angle"] = reduceFloatPrecision( angle, 2);
doc["battery"] = reduceFloatPrecision( myBatteryVoltage.getVoltage(), 2 );
doc["rssi"] = WiFi.RSSI();
// Some debug information
// Some additional information
doc["run-time"] = reduceFloatPrecision( runTime, 2 );
WiFiClient client;

View File

@ -468,7 +468,7 @@ bool WebServer::setupWebServer() {
// Dynamic content
server.on("/api/config", HTTP_GET, webHandleConfig); // Get config.json
server.on("/api/device", HTTP_GET, webHandleDevice); // Get device.json
server.on("/api/calibrate", HTTP_GET, webHandleCalibrate); // Run calibration routine (param id)
server.on("/api/calibrate", HTTP_POST, webHandleCalibrate); // Run calibration routine (param id)
server.on("/api/factory", HTTP_GET, webHandleFactoryReset); // Reset the device
server.on("/api/status", HTTP_GET, webHandleStatus); // Get the status.json
server.on("/api/clearwifi", HTTP_GET, webHandleClearWIFI); // Clear wifi settings

View File

@ -27,17 +27,24 @@ SOFTWARE.
#include "gyro.h"
#include "calc.h"
#include "tempsensor.h"
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
#include <ESP_WiFiManager.h>
#include <LittleFS.h>
#include <incbin.h>
Wifi myWifi;
WiFiManager myWifiManager;
ESP_WiFiManager myWifiManager;
bool shouldSaveConfig = false;
// TODO: ADD MDNS setting to WIFI portal.....
//
// Callback notifying us of the need to save config
//
void saveConfigCallback () {
shouldSaveConfig = true;
}
//
// Connect to last known access point or create one if connection is not working.
@ -50,7 +57,15 @@ bool Wifi::connect( bool showPortal ) {
myWifiManager.setDebugOutput(false);
#endif
unsigned long startMillis = millis();
myWifiManager.setConfigPortalChannel(0);
myWifiManager.setConfigPortalTimeout( WIFI_PORTAL_TIMEOUT );
ESP_WMParameter mdnsParam("mDNS name", "hostname", myConfig.getMDNS(), 20);
myWifiManager.setSaveConfigCallback(saveConfigCallback);
myWifiManager.addParameter( &mdnsParam );
myWifiManager.setMinimumSignalQuality(-1); // Ignore under 8%
if( showPortal ) {
Log.notice(F("WIFI: Starting wifi portal." CR));
connectedFlag = myWifiManager.startConfigPortal( WIFI_DEFAULT_SSID, WIFI_DEFAULT_PWD );
@ -58,6 +73,10 @@ bool Wifi::connect( bool showPortal ) {
else
connectedFlag = myWifiManager.autoConnect( WIFI_DEFAULT_SSID, WIFI_DEFAULT_PWD );
if( shouldSaveConfig ) {
myConfig.setMDNS( mdnsParam.getValue() );
}
Log.notice( F("WIFI: Connect time %d s" CR), abs(millis() - startMillis)/1000);
#if LOG_LEVEL==6
@ -193,7 +212,7 @@ 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));
htmlFiles = ver["html"].as<JsonArray>();
JsonArray htmlFiles = ver["html"].as<JsonArray>();
for(JsonVariant v : htmlFiles) {
String s = v;
#if LOG_LEVEL==6

View File

@ -25,15 +25,13 @@ SOFTWARE.
#define _WIFI_H
// Include
#include <WiFiManager.h>
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
// classes
class Wifi {
private:
// WIFI
bool connectedFlag = false;
JsonArray htmlFiles;
// OTA
bool newFirmware = false;