Refactored class members
This commit is contained in:
parent
ddb34e129d
commit
37a1ca6058
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
BIN
bin/firmware.bin
BIN
bin/firmware.bin
Binary file not shown.
@ -1 +1 @@
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="description" content=""><title>Beer Gravity Monitor</title><link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous"><script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script><script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" crossorigin="anonymous"></script></head><body class="py-4"><!-- START MENU --><nav class="navbar navbar-expand-sm navbar-dark bg-primary"><a class="navbar-brand" href="/index.htm">Beer Gravity Monitor</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button><div class="collapse navbar-collapse" id="navbar"><ul class="navbar-nav mr-auto"><li class="nav-item active"><a class="nav-link" href="/index.htm">Home <span class="sr-only">(current)</span></a></li><li class="nav-item"><a class="nav-link" href="/device.htm">Device</a></li><li class="nav-item"><a class="nav-link" href="/config.htm">Configuration</a></li><li class="nav-item"><a class="nav-link" href="/calibration.htm">Calibration</a></li><li class="nav-item"><a class="nav-link" href="/about.htm">About</a></li></ul><div class="spinner-border text-light" id="spinner" role="status"></div></div></nav><!-- START MAIN INDEX --><div class="container"><hr class="my-4"><div class="alert alert-success alert-dismissible fade hide show d-none" role="alert" id="alert"><div id="alert-msg">...</div><button type="button" id="alert-btn" class="close" aria-label="Close"><span aria-hidden="true">×</span></button></div><script type="text/javascript">function showError(s){$(".alert").removeClass("alert-success").addClass("alert-danger").removeClass("d-none").addClass("show"),$("#alert-msg").text(s)}function showSuccess(s){$(".alert").addClass("alert-success").removeClass("alert-danger").removeClass("d-none").addClass("show"),$("#alert-msg").text(s)}$("#alert-btn").click(function(s){$(".alert").addClass("d-none").removeClass("show")})</script><div class="" id="id" hidden></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Gravity:</div><div class="col-md-4 themed-grid-col bg-light" id="gravity">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Temperature:</div><div class="col-md-4 themed-grid-col bg-light" id="temp">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Angle/Tilt:</div><div class="col-md-4 themed-grid-col bg-light" id="angle">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Battery:</div><div class="col-md-4 themed-grid-col bg-light" id="battery">Loading...</div></div><div class="row mb-3"><div class="col-md-12 px-md-5 themed-grid-col bg-light custom-control custom-checkbox"><input type="checkbox" class="custom-control-input" name="sleep-mode" id="sleep-mode" disabled> <label class="custom-control-label" for="sleep-mode">Do not enter sleep mode when floating (check this if you are collecting angles/tilt for calibration).</label></div></div><hr class="my-4"></div><script type="text/javascript">function getStatus(){var e="/api/status";$("#spinner").show(),$.getJSON(e,function(e){console.log(e),$("#id").text(e.id),$("#angle").text(e.angle),$("#gravity").text(e.gravity+" SG"),$("#battery").text(e.battery+" V"),"C"==e["temp-format"]?$("#temp").text(e["temp-c"]+" C"):$("#temp").text(e["temp-f"]+" F"),e["sleep-mode"]?$("#sleep-mode").attr("checked",!0):$("#sleep-mode").attr("checked",!1),$("#sleep-mode").removeAttr("disabled")}).fail(function(){showError("Unable to get data from the device.")}).always(function(){$("#spinner").hide()})}function start(){setInterval(getStatus,3e3)}window.onload=start,$("#sleep-mode").click(function(e){console.log("Blocking sleep mode = "+$("#sleep-mode").is(":checked")),$.ajax({type:"POST",url:"/api/status/sleepmode",data:{id:$("#id").text(),"sleep-mode":$("#sleep-mode").is(":checked")},success:function(e){},error:function(e){showError("Could not update sleep mode for device.")}})})</script><!-- START FOOTER --><div class="container-fluid themed-container bg-primary text-light">(C) Copyright 2021-22 Magnus Persson</div></body></html>
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="description" content=""><title>Beer Gravity Monitor</title><link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous"><script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script><script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" crossorigin="anonymous"></script></head><body class="py-4"><!-- START MENU --><nav class="navbar navbar-expand-sm navbar-dark bg-primary"><a class="navbar-brand" href="/index.htm">Beer Gravity Monitor</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button><div class="collapse navbar-collapse" id="navbar"><ul class="navbar-nav mr-auto"><li class="nav-item active"><a class="nav-link" href="/index.htm">Home <span class="sr-only">(current)</span></a></li><li class="nav-item"><a class="nav-link" href="/device.htm">Device</a></li><li class="nav-item"><a class="nav-link" href="/config.htm">Configuration</a></li><li class="nav-item"><a class="nav-link" href="/calibration.htm">Calibration</a></li><li class="nav-item"><a class="nav-link" href="/about.htm">About</a></li></ul><div class="spinner-border text-light" id="spinner" role="status"></div></div></nav><!-- START MAIN INDEX --><div class="container"><hr class="my-4"><div class="alert alert-success alert-dismissible fade hide show d-none" role="alert" id="alert"><div id="alert-msg">...</div><button type="button" id="alert-btn" class="close" aria-label="Close"><span aria-hidden="true">×</span></button></div><script type="text/javascript">function showError(s){$(".alert").removeClass("alert-success").addClass("alert-danger").removeClass("d-none").addClass("show"),$("#alert-msg").text(s)}function showSuccess(s){$(".alert").addClass("alert-success").removeClass("alert-danger").removeClass("d-none").addClass("show"),$("#alert-msg").text(s)}$("#alert-btn").click(function(s){$(".alert").addClass("d-none").removeClass("show")})</script><div class="" id="id" hidden></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Gravity:</div><div class="col-md-4 themed-grid-col bg-light" id="gravity">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Temperature:</div><div class="col-md-4 themed-grid-col bg-light" id="temp">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Angle/Tilt:</div><div class="col-md-4 themed-grid-col bg-light" id="angle">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Battery:</div><div class="col-md-4 themed-grid-col bg-light" id="battery">Loading...</div></div><div class="row mb-3"><div class="col-md-12 px-md-5 themed-grid-col bg-light custom-control custom-checkbox"><input type="checkbox" class="custom-control-input" name="sleep-mode" id="sleep-mode" disabled> <label class="custom-control-label" for="sleep-mode">Do not enter sleep mode when floating (check this if you are collecting angles/tilt for calibration).</label></div></div><hr class="my-4"></div><script type="text/javascript">function getStatus(){var e="/api/status";$("#spinner").show(),$.getJSON(e,function(e){console.log(e),$("#id").text(e.id),$("#angle").text(e.angle),"G"==e["gravity-format"]?$("#gravity").text(e.gravity+" SG"):$("#gravity").text(e.gravity+" °P"),$("#battery").text(e.battery+" V"),"C"==e["temp-format"]?$("#temp").text(e["temp-c"]+" C"):$("#temp").text(e["temp-f"]+" F"),e["sleep-mode"]?$("#sleep-mode").attr("checked",!0):$("#sleep-mode").attr("checked",!1),$("#sleep-mode").removeAttr("disabled")}).fail(function(){showError("Unable to get data from the device.")}).always(function(){$("#spinner").hide()})}function start(){setInterval(getStatus,3e3)}window.onload=start,$("#sleep-mode").click(function(e){console.log("Blocking sleep mode = "+$("#sleep-mode").is(":checked")),$.ajax({type:"POST",url:"/api/status/sleepmode",data:{id:$("#id").text(),"sleep-mode":$("#sleep-mode").is(":checked")},success:function(e){},error:function(e){showError("Could not update sleep mode for device.")}})})</script><!-- START FOOTER --><div class="container-fluid themed-container bg-primary text-light">(C) Copyright 2021-22 Magnus Persson</div></body></html>
|
@ -1 +1 @@
|
||||
{ "project":"gravmon", "version":"0.6.0", "html": [ "index.min.htm", "device.min.htm", "config.min.htm", "calibration.min.htm", "about.min.htm" ] }
|
||||
{ "project":"gravmon", "version":"0.6.1", "html": [ "index.min.htm", "device.min.htm", "config.min.htm", "calibration.min.htm", "about.min.htm" ] }
|
@ -98,7 +98,7 @@ int createFormula(RawFormulaData &fd, char *formulaBuffer,
|
||||
// If the deviation is more than 2 degress we mark it as failed.
|
||||
if (dev * 1000 > FORMULA_MAX_DEVIATION) {
|
||||
#if LOG_LEVEL == 6 && !defined(CALC_DISABLE_LOGGING)
|
||||
char s[10];
|
||||
char s[20];
|
||||
snprintf(&s[0], sizeof(s), "%.8f", dev);
|
||||
Log.verbose(F("CALC: Deviation is: %s" CR), &s[0]);
|
||||
#endif
|
||||
@ -154,7 +154,7 @@ double calculateGravity(double angle, double temp, const char *tempFormula) {
|
||||
te_free(expr);
|
||||
|
||||
#if LOG_LEVEL == 6 && !defined(CALC_DISABLE_LOGGING)
|
||||
char s[10];
|
||||
char s[20];
|
||||
snprintf(&s[0], sizeof(s), "%.8f", g);
|
||||
Log.verbose(F("CALC: Calculated gravity is %s." CR), &s[0]);
|
||||
#endif
|
||||
|
@ -35,13 +35,13 @@ Config::Config() {
|
||||
// Assiging default values
|
||||
char buf[30];
|
||||
snprintf(&buf[0], sizeof(buf), "%6x", (unsigned int)ESP.getChipId());
|
||||
id = String(&buf[0]);
|
||||
_id = String(&buf[0]);
|
||||
snprintf(&buf[0], sizeof(buf), "" WIFI_MDNS "%s", getID());
|
||||
mDNS = String(&buf[0]);
|
||||
_mDNS = String(&buf[0]);
|
||||
|
||||
#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
|
||||
|
||||
setTempFormat('C');
|
||||
@ -50,10 +50,10 @@ Config::Config() {
|
||||
setVoltageFactor(1.59); // Conversion factor for battery
|
||||
setTempSensorAdjC(0.0);
|
||||
setGravityTempAdj(false);
|
||||
gyroCalibration = {0, 0, 0, 0, 0, 0};
|
||||
formulaData = {{0, 0, 0, 0, 0}, {1, 1, 1, 1, 1}};
|
||||
gyroTemp = false;
|
||||
saveNeeded = false;
|
||||
_gyroCalibration = {0, 0, 0, 0, 0, 0};
|
||||
_formulaData = {{0, 0, 0, 0, 0}, {1, 1, 1, 1, 1}};
|
||||
_gyroTemp = false;
|
||||
_saveNeeded = false;
|
||||
}
|
||||
|
||||
//
|
||||
@ -87,32 +87,32 @@ void Config::createJson(DynamicJsonDocument& doc) {
|
||||
doc[CFG_PARAM_GYRO_TEMP] = isGyroTemp();
|
||||
|
||||
JsonObject cal = doc.createNestedObject(CFG_PARAM_GYRO_CALIBRATION);
|
||||
cal["ax"] = gyroCalibration.ax;
|
||||
cal["ay"] = gyroCalibration.ay;
|
||||
cal["az"] = gyroCalibration.az;
|
||||
cal["gx"] = gyroCalibration.gx;
|
||||
cal["gy"] = gyroCalibration.gy;
|
||||
cal["gz"] = gyroCalibration.gz;
|
||||
cal["ax"] = _gyroCalibration.ax;
|
||||
cal["ay"] = _gyroCalibration.ay;
|
||||
cal["az"] = _gyroCalibration.az;
|
||||
cal["gx"] = _gyroCalibration.gx;
|
||||
cal["gy"] = _gyroCalibration.gy;
|
||||
cal["gz"] = _gyroCalibration.gz;
|
||||
|
||||
JsonObject cal2 = doc.createNestedObject(CFG_PARAM_FORMULA_DATA);
|
||||
cal2["a1"] = reduceFloatPrecision(formulaData.a[0], 2);
|
||||
cal2["a2"] = reduceFloatPrecision(formulaData.a[1], 2);
|
||||
cal2["a3"] = reduceFloatPrecision(formulaData.a[2], 2);
|
||||
cal2["a4"] = reduceFloatPrecision(formulaData.a[3], 2);
|
||||
cal2["a5"] = reduceFloatPrecision(formulaData.a[4], 2);
|
||||
cal2["a1"] = reduceFloatPrecision(_formulaData.a[0], 2);
|
||||
cal2["a2"] = reduceFloatPrecision(_formulaData.a[1], 2);
|
||||
cal2["a3"] = reduceFloatPrecision(_formulaData.a[2], 2);
|
||||
cal2["a4"] = reduceFloatPrecision(_formulaData.a[3], 2);
|
||||
cal2["a5"] = reduceFloatPrecision(_formulaData.a[4], 2);
|
||||
|
||||
cal2["g1"] = reduceFloatPrecision(formulaData.g[0], 4);
|
||||
cal2["g2"] = reduceFloatPrecision(formulaData.g[1], 4);
|
||||
cal2["g3"] = reduceFloatPrecision(formulaData.g[2], 4);
|
||||
cal2["g4"] = reduceFloatPrecision(formulaData.g[3], 4);
|
||||
cal2["g5"] = reduceFloatPrecision(formulaData.g[4], 4);
|
||||
cal2["g1"] = reduceFloatPrecision(_formulaData.g[0], 4);
|
||||
cal2["g2"] = reduceFloatPrecision(_formulaData.g[1], 4);
|
||||
cal2["g3"] = reduceFloatPrecision(_formulaData.g[2], 4);
|
||||
cal2["g4"] = reduceFloatPrecision(_formulaData.g[3], 4);
|
||||
cal2["g5"] = reduceFloatPrecision(_formulaData.g[4], 4);
|
||||
}
|
||||
|
||||
//
|
||||
// Save json document to file
|
||||
//
|
||||
bool Config::saveFile() {
|
||||
if (!saveNeeded) {
|
||||
if (!_saveNeeded) {
|
||||
#if LOG_LEVEL == 6 && !defined(CFG_DISABLE_LOGGING)
|
||||
Log.verbose(F("CFG : Skipping save, not needed." CR));
|
||||
#endif
|
||||
@ -142,7 +142,7 @@ bool Config::saveFile() {
|
||||
configFile.flush();
|
||||
configFile.close();
|
||||
|
||||
saveNeeded = false;
|
||||
_saveNeeded = false;
|
||||
myConfig.debug();
|
||||
Log.notice(F("CFG : Configuration saved to " CFG_FILENAME "." CR));
|
||||
return true;
|
||||
@ -242,42 +242,42 @@ bool Config::loadFile() {
|
||||
setTempSensorAdjC(doc[CFG_PARAM_TEMP_ADJ].as<float>());
|
||||
|
||||
if (!doc[CFG_PARAM_GYRO_CALIBRATION]["ax"].isNull())
|
||||
gyroCalibration.ax = doc[CFG_PARAM_GYRO_CALIBRATION]["ax"];
|
||||
_gyroCalibration.ax = doc[CFG_PARAM_GYRO_CALIBRATION]["ax"];
|
||||
if (!doc[CFG_PARAM_GYRO_CALIBRATION]["ay"].isNull())
|
||||
gyroCalibration.ay = doc[CFG_PARAM_GYRO_CALIBRATION]["ay"];
|
||||
_gyroCalibration.ay = doc[CFG_PARAM_GYRO_CALIBRATION]["ay"];
|
||||
if (!doc[CFG_PARAM_GYRO_CALIBRATION]["az"].isNull())
|
||||
gyroCalibration.az = doc[CFG_PARAM_GYRO_CALIBRATION]["az"];
|
||||
_gyroCalibration.az = doc[CFG_PARAM_GYRO_CALIBRATION]["az"];
|
||||
if (!doc[CFG_PARAM_GYRO_CALIBRATION]["gx"].isNull())
|
||||
gyroCalibration.gx = doc[CFG_PARAM_GYRO_CALIBRATION]["gx"];
|
||||
_gyroCalibration.gx = doc[CFG_PARAM_GYRO_CALIBRATION]["gx"];
|
||||
if (!doc[CFG_PARAM_GYRO_CALIBRATION]["gy"].isNull())
|
||||
gyroCalibration.gy = doc[CFG_PARAM_GYRO_CALIBRATION]["gy"];
|
||||
_gyroCalibration.gy = doc[CFG_PARAM_GYRO_CALIBRATION]["gy"];
|
||||
if (!doc[CFG_PARAM_GYRO_CALIBRATION]["gz"].isNull())
|
||||
gyroCalibration.gz = doc[CFG_PARAM_GYRO_CALIBRATION]["gz"];
|
||||
_gyroCalibration.gz = doc[CFG_PARAM_GYRO_CALIBRATION]["gz"];
|
||||
|
||||
if (!doc[CFG_PARAM_FORMULA_DATA]["a1"].isNull())
|
||||
formulaData.a[0] = doc[CFG_PARAM_FORMULA_DATA]["a1"].as<double>();
|
||||
_formulaData.a[0] = doc[CFG_PARAM_FORMULA_DATA]["a1"].as<double>();
|
||||
if (!doc[CFG_PARAM_FORMULA_DATA]["a2"].isNull())
|
||||
formulaData.a[1] = doc[CFG_PARAM_FORMULA_DATA]["a2"].as<double>();
|
||||
_formulaData.a[1] = doc[CFG_PARAM_FORMULA_DATA]["a2"].as<double>();
|
||||
if (!doc[CFG_PARAM_FORMULA_DATA]["a3"].isNull())
|
||||
formulaData.a[2] = doc[CFG_PARAM_FORMULA_DATA]["a3"].as<double>();
|
||||
_formulaData.a[2] = doc[CFG_PARAM_FORMULA_DATA]["a3"].as<double>();
|
||||
if (!doc[CFG_PARAM_FORMULA_DATA]["a4"].isNull())
|
||||
formulaData.a[3] = doc[CFG_PARAM_FORMULA_DATA]["a4"].as<double>();
|
||||
_formulaData.a[3] = doc[CFG_PARAM_FORMULA_DATA]["a4"].as<double>();
|
||||
if (!doc[CFG_PARAM_FORMULA_DATA]["a5"].isNull())
|
||||
formulaData.a[4] = doc[CFG_PARAM_FORMULA_DATA]["a5"].as<double>();
|
||||
_formulaData.a[4] = doc[CFG_PARAM_FORMULA_DATA]["a5"].as<double>();
|
||||
|
||||
if (!doc[CFG_PARAM_FORMULA_DATA]["g1"].isNull())
|
||||
formulaData.g[0] = doc[CFG_PARAM_FORMULA_DATA]["g1"].as<double>();
|
||||
_formulaData.g[0] = doc[CFG_PARAM_FORMULA_DATA]["g1"].as<double>();
|
||||
if (!doc[CFG_PARAM_FORMULA_DATA]["g2"].isNull())
|
||||
formulaData.g[1] = doc[CFG_PARAM_FORMULA_DATA]["g2"].as<double>();
|
||||
_formulaData.g[1] = doc[CFG_PARAM_FORMULA_DATA]["g2"].as<double>();
|
||||
if (!doc[CFG_PARAM_FORMULA_DATA]["g3"].isNull())
|
||||
formulaData.g[2] = doc[CFG_PARAM_FORMULA_DATA]["g3"].as<double>();
|
||||
_formulaData.g[2] = doc[CFG_PARAM_FORMULA_DATA]["g3"].as<double>();
|
||||
if (!doc[CFG_PARAM_FORMULA_DATA]["g4"].isNull())
|
||||
formulaData.g[3] = doc[CFG_PARAM_FORMULA_DATA]["g4"].as<double>();
|
||||
_formulaData.g[3] = doc[CFG_PARAM_FORMULA_DATA]["g4"].as<double>();
|
||||
if (!doc[CFG_PARAM_FORMULA_DATA]["g5"].isNull())
|
||||
formulaData.g[4] = doc[CFG_PARAM_FORMULA_DATA]["g5"].as<double>();
|
||||
_formulaData.g[4] = doc[CFG_PARAM_FORMULA_DATA]["g5"].as<double>();
|
||||
|
||||
myConfig.debug();
|
||||
saveNeeded = false; // Reset save flag
|
||||
_saveNeeded = false; // Reset save flag
|
||||
Log.notice(F("CFG : Configuration file " CFG_FILENAME " loaded." CR));
|
||||
return true;
|
||||
}
|
||||
|
246
src/config.hpp
246
src/config.hpp
@ -113,230 +113,230 @@ struct RawFormulaData {
|
||||
// Main configuration class
|
||||
class Config {
|
||||
private:
|
||||
bool saveNeeded;
|
||||
bool _saveNeeded;
|
||||
|
||||
// Device configuration
|
||||
String id;
|
||||
String mDNS;
|
||||
String otaURL;
|
||||
char tempFormat;
|
||||
float voltageFactor;
|
||||
float tempSensorAdjC;
|
||||
int sleepInterval;
|
||||
bool gyroTemp;
|
||||
String _id;
|
||||
String _mDNS;
|
||||
String _otaURL;
|
||||
char _tempFormat;
|
||||
float _voltageFactor;
|
||||
float _tempSensorAdjC;
|
||||
int _sleepInterval;
|
||||
bool _gyroTemp;
|
||||
|
||||
// Wifi Config
|
||||
String wifiSSID;
|
||||
String wifiPASS;
|
||||
String _wifiSSID;
|
||||
String _wifiPASS;
|
||||
|
||||
// Push target settings
|
||||
String brewfatherPushUrl;
|
||||
String _brewfatherPushUrl;
|
||||
|
||||
String httpPushUrl;
|
||||
String httpPushUrl2;
|
||||
String _httpPushUrl;
|
||||
String _httpPushUrl2;
|
||||
|
||||
String influxDb2Url;
|
||||
String influxDb2Org;
|
||||
String influxDb2Bucket;
|
||||
String influxDb2Token;
|
||||
String _influxDb2Url;
|
||||
String _influxDb2Org;
|
||||
String _influxDb2Bucket;
|
||||
String _influxDb2Token;
|
||||
|
||||
String mqttUrl;
|
||||
String mqttTopic;
|
||||
String mqttUser;
|
||||
String mqttPass;
|
||||
String _mqttUrl;
|
||||
String _mqttTopic;
|
||||
String _mqttUser;
|
||||
String _mqttPass;
|
||||
|
||||
// Gravity and temperature calculations
|
||||
String gravityFormula;
|
||||
bool gravityTempAdj;
|
||||
char gravityFormat;
|
||||
String _gravityFormula;
|
||||
bool _gravityTempAdj;
|
||||
char _gravityFormat;
|
||||
|
||||
// Gyro calibration and formula calculation data
|
||||
RawGyroData gyroCalibration;
|
||||
RawFormulaData formulaData;
|
||||
RawGyroData _gyroCalibration;
|
||||
RawFormulaData _formulaData;
|
||||
|
||||
void debug();
|
||||
void formatFileSystem();
|
||||
|
||||
public:
|
||||
Config();
|
||||
const char* getID() { return id.c_str(); }
|
||||
const char* getID() { return _id.c_str(); }
|
||||
|
||||
const char* getMDNS() { return mDNS.c_str(); }
|
||||
const char* getMDNS() { return _mDNS.c_str(); }
|
||||
void setMDNS(String s) {
|
||||
mDNS = s;
|
||||
saveNeeded = true;
|
||||
_mDNS = s;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
|
||||
const bool isGyroTemp() { return gyroTemp; }
|
||||
const bool isGyroTemp() { return _gyroTemp; }
|
||||
void setGyroTemp(bool b) {
|
||||
gyroTemp = b;
|
||||
saveNeeded = true;
|
||||
_gyroTemp = b;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
|
||||
const char* getOtaURL() { return otaURL.c_str(); }
|
||||
const char* getOtaURL() { return _otaURL.c_str(); }
|
||||
void setOtaURL(String s) {
|
||||
otaURL = s;
|
||||
saveNeeded = true;
|
||||
_otaURL = s;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
bool isOtaActive() { return otaURL.length() ? true : false; }
|
||||
bool isOtaActive() { return _otaURL.length() ? true : false; }
|
||||
|
||||
const char* getWifiSSID() { return wifiSSID.c_str(); }
|
||||
const char* getWifiSSID() { return _wifiSSID.c_str(); }
|
||||
void setWifiSSID(String s) {
|
||||
wifiSSID = s;
|
||||
saveNeeded = true;
|
||||
_wifiSSID = s;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
const char* getWifiPass() { return wifiPASS.c_str(); }
|
||||
const char* getWifiPass() { return _wifiPASS.c_str(); }
|
||||
void setWifiPass(String s) {
|
||||
wifiPASS = s;
|
||||
saveNeeded = true;
|
||||
_wifiPASS = s;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
|
||||
// Brewfather
|
||||
const char* getBrewfatherPushUrl() { return brewfatherPushUrl.c_str(); }
|
||||
const char* getBrewfatherPushUrl() { return _brewfatherPushUrl.c_str(); }
|
||||
void setBrewfatherPushUrl(String s) {
|
||||
brewfatherPushUrl = s;
|
||||
saveNeeded = true;
|
||||
_brewfatherPushUrl = s;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
bool isBrewfatherActive() {
|
||||
return brewfatherPushUrl.length() ? true : false;
|
||||
return _brewfatherPushUrl.length() ? true : false;
|
||||
}
|
||||
|
||||
// Standard HTTP
|
||||
const char* getHttpPushUrl() { return httpPushUrl.c_str(); }
|
||||
const char* getHttpPushUrl() { return _httpPushUrl.c_str(); }
|
||||
void setHttpPushUrl(String s) {
|
||||
httpPushUrl = s;
|
||||
saveNeeded = true;
|
||||
_httpPushUrl = s;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
bool isHttpActive() { return httpPushUrl.length() ? true : false; }
|
||||
const char* getHttpPushUrl2() { return httpPushUrl2.c_str(); }
|
||||
bool isHttpActive() { return _httpPushUrl.length() ? true : false; }
|
||||
const char* getHttpPushUrl2() { return _httpPushUrl2.c_str(); }
|
||||
void setHttpPushUrl2(String s) {
|
||||
httpPushUrl2 = s;
|
||||
saveNeeded = true;
|
||||
_httpPushUrl2 = s;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
bool isHttpActive2() { return httpPushUrl2.length() ? true : false; }
|
||||
bool isHttpActive2() { return _httpPushUrl2.length() ? true : false; }
|
||||
|
||||
// InfluxDB2
|
||||
const char* getInfluxDb2PushUrl() { return influxDb2Url.c_str(); }
|
||||
const char* getInfluxDb2PushUrl() { return _influxDb2Url.c_str(); }
|
||||
void setInfluxDb2PushUrl(String s) {
|
||||
influxDb2Url = s;
|
||||
saveNeeded = true;
|
||||
_influxDb2Url = s;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
bool isInfluxDb2Active() { return influxDb2Url.length() ? true : false; }
|
||||
const char* getInfluxDb2PushOrg() { return influxDb2Org.c_str(); }
|
||||
bool isInfluxDb2Active() { return _influxDb2Url.length() ? true : false; }
|
||||
const char* getInfluxDb2PushOrg() { return _influxDb2Org.c_str(); }
|
||||
void setInfluxDb2PushOrg(String s) {
|
||||
influxDb2Org = s;
|
||||
saveNeeded = true;
|
||||
_influxDb2Org = s;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
const char* getInfluxDb2PushBucket() { return influxDb2Bucket.c_str(); }
|
||||
const char* getInfluxDb2PushBucket() { return _influxDb2Bucket.c_str(); }
|
||||
void setInfluxDb2PushBucket(String s) {
|
||||
influxDb2Bucket = s;
|
||||
saveNeeded = true;
|
||||
_influxDb2Bucket = s;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
const char* getInfluxDb2PushToken() { return influxDb2Token.c_str(); }
|
||||
const char* getInfluxDb2PushToken() { return _influxDb2Token.c_str(); }
|
||||
void setInfluxDb2PushToken(String s) {
|
||||
influxDb2Token = s;
|
||||
saveNeeded = true;
|
||||
_influxDb2Token = s;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
|
||||
// MQTT
|
||||
bool isMqttActive() { return mqttUrl.length() ? true : false; }
|
||||
const char* getMqttUrl() { return mqttUrl.c_str(); }
|
||||
bool isMqttActive() { return _mqttUrl.length() ? true : false; }
|
||||
const char* getMqttUrl() { return _mqttUrl.c_str(); }
|
||||
void setMqttUrl(String s) {
|
||||
mqttUrl = s;
|
||||
saveNeeded = true;
|
||||
_mqttUrl = s;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
const char* getMqttTopic() { return mqttTopic.c_str(); }
|
||||
const char* getMqttTopic() { return _mqttTopic.c_str(); }
|
||||
void setMqttTopic(String s) {
|
||||
mqttTopic = s;
|
||||
saveNeeded = true;
|
||||
_mqttTopic = s;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
const char* getMqttUser() { return mqttUser.c_str(); }
|
||||
const char* getMqttUser() { return _mqttUser.c_str(); }
|
||||
void setMqttUser(String s) {
|
||||
mqttUser = s;
|
||||
saveNeeded = true;
|
||||
_mqttUser = s;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
const char* getMqttPass() { return mqttPass.c_str(); }
|
||||
const char* getMqttPass() { return _mqttPass.c_str(); }
|
||||
void setMqttPass(String s) {
|
||||
mqttPass = s;
|
||||
saveNeeded = true;
|
||||
_mqttPass = s;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
|
||||
int getSleepInterval() { return sleepInterval; }
|
||||
int getSleepInterval() { return _sleepInterval; }
|
||||
void setSleepInterval(int v) {
|
||||
sleepInterval = v;
|
||||
saveNeeded = true;
|
||||
_sleepInterval = v;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
void setSleepInterval(String s) {
|
||||
sleepInterval = s.toInt();
|
||||
saveNeeded = true;
|
||||
_sleepInterval = s.toInt();
|
||||
_saveNeeded = true;
|
||||
}
|
||||
|
||||
char getTempFormat() { return tempFormat; }
|
||||
char getTempFormat() { return _tempFormat; }
|
||||
void setTempFormat(char c) {
|
||||
if (c == 'C' || c == 'F') {
|
||||
tempFormat = c;
|
||||
saveNeeded = true;
|
||||
_tempFormat = c;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
}
|
||||
bool isTempC() { return tempFormat == 'C'; }
|
||||
bool isTempF() { return tempFormat == 'F'; }
|
||||
bool isTempC() { return _tempFormat == 'C'; }
|
||||
bool isTempF() { return _tempFormat == 'F'; }
|
||||
|
||||
float getVoltageFactor() { return voltageFactor; }
|
||||
float getVoltageFactor() { return _voltageFactor; }
|
||||
void setVoltageFactor(float f) {
|
||||
voltageFactor = f;
|
||||
saveNeeded = true;
|
||||
_voltageFactor = f;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
void setVoltageFactor(String s) {
|
||||
voltageFactor = s.toFloat();
|
||||
saveNeeded = true;
|
||||
_voltageFactor = s.toFloat();
|
||||
_saveNeeded = true;
|
||||
}
|
||||
|
||||
float getTempSensorAdjC() { return tempSensorAdjC; }
|
||||
float getTempSensorAdjC() { return _tempSensorAdjC; }
|
||||
void setTempSensorAdjC(float f) {
|
||||
tempSensorAdjC = f;
|
||||
saveNeeded = true;
|
||||
_tempSensorAdjC = f;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
void setTempSensorAdjC(String s) {
|
||||
tempSensorAdjC = s.toFloat();
|
||||
saveNeeded = true;
|
||||
_tempSensorAdjC = s.toFloat();
|
||||
_saveNeeded = true;
|
||||
}
|
||||
void setTempSensorAdjF(String s) {
|
||||
tempSensorAdjC = convertFtoC(s.toFloat());
|
||||
saveNeeded = true;
|
||||
_tempSensorAdjC = convertFtoC(s.toFloat());
|
||||
_saveNeeded = true;
|
||||
}
|
||||
|
||||
const char* getGravityFormula() { return gravityFormula.c_str(); }
|
||||
const char* getGravityFormula() { return _gravityFormula.c_str(); }
|
||||
void setGravityFormula(String s) {
|
||||
gravityFormula = s;
|
||||
saveNeeded = true;
|
||||
_gravityFormula = s;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
|
||||
bool isGravityTempAdj() { return gravityTempAdj; }
|
||||
bool isGravityTempAdj() { return _gravityTempAdj; }
|
||||
void setGravityTempAdj(bool b) {
|
||||
gravityTempAdj = b;
|
||||
saveNeeded = true;
|
||||
_gravityTempAdj = b;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
|
||||
char getGravityFormat() { return gravityFormat; }
|
||||
char getGravityFormat() { return _gravityFormat; }
|
||||
void setGravityFormat(char c) {
|
||||
if (c == 'G' || c == 'P') {
|
||||
gravityFormat = c;
|
||||
saveNeeded = true;
|
||||
_gravityFormat = c;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
}
|
||||
bool isGravitySG() { return gravityFormat == 'G'; }
|
||||
bool isGravityPlato() { return gravityFormat == 'P'; }
|
||||
bool isGravitySG() { return _gravityFormat == 'G'; }
|
||||
bool isGravityPlato() { return _gravityFormat == 'P'; }
|
||||
|
||||
const RawGyroData& getGyroCalibration() { return gyroCalibration; }
|
||||
const RawGyroData& getGyroCalibration() { return _gyroCalibration; }
|
||||
void setGyroCalibration(const RawGyroData& r) {
|
||||
gyroCalibration = r;
|
||||
saveNeeded = true;
|
||||
_gyroCalibration = r;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
|
||||
const RawFormulaData& getFormulaData() { return formulaData; }
|
||||
const RawFormulaData& getFormulaData() { return _formulaData; }
|
||||
void setFormulaData(const RawFormulaData& r) {
|
||||
formulaData = r;
|
||||
saveNeeded = true;
|
||||
_formulaData = r;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
|
||||
// IO functions
|
||||
@ -344,8 +344,8 @@ class Config {
|
||||
bool saveFile();
|
||||
bool loadFile();
|
||||
void checkFileSystem();
|
||||
bool isSaveNeeded() { return saveNeeded; }
|
||||
void setSaveNeeded() { saveNeeded = true; }
|
||||
bool isSaveNeeded() { return _saveNeeded; }
|
||||
void setSaveNeeded() { _saveNeeded = true; }
|
||||
};
|
||||
|
||||
// Global instance created
|
||||
|
80
src/gyro.cpp
80
src/gyro.cpp
@ -49,13 +49,13 @@ bool GyroSensor::setup() {
|
||||
|
||||
if (!accelgyro.testConnection()) {
|
||||
Log.error(F("GYRO: Failed to connect to MPU6050 (gyro)." CR));
|
||||
sensorConnected = false;
|
||||
_sensorConnected = false;
|
||||
} else {
|
||||
#if !defined(GYRO_DISABLE_LOGGING)
|
||||
Log.notice(F("GYRO: Connected to MPU6050 (gyro)." CR));
|
||||
#endif
|
||||
accelgyro.initialize();
|
||||
sensorConnected = true;
|
||||
_sensorConnected = true;
|
||||
|
||||
// Configure the sensor
|
||||
accelgyro.setTempSensorEnabled(true);
|
||||
@ -77,10 +77,10 @@ bool GyroSensor::setup() {
|
||||
|
||||
// Once we have calibration values stored we just apply them from the
|
||||
// config.
|
||||
calibrationOffset = myConfig.getGyroCalibration();
|
||||
_calibrationOffset = myConfig.getGyroCalibration();
|
||||
applyCalibration();
|
||||
}
|
||||
return sensorConnected;
|
||||
return _sensorConnected;
|
||||
}
|
||||
|
||||
//
|
||||
@ -234,35 +234,35 @@ bool GyroSensor::read() {
|
||||
Log.verbose(F("GYRO: Getting new gyro position." CR));
|
||||
#endif
|
||||
|
||||
if (!sensorConnected) return false;
|
||||
if (!_sensorConnected) return false;
|
||||
|
||||
readSensor(lastGyroData, SENSOR_READ_COUNT,
|
||||
readSensor(_lastGyroData, SENSOR_READ_COUNT,
|
||||
SENSOR_READ_DELAY); // Last param is unused if GYRO_USE_INTERRUPT
|
||||
// is defined.
|
||||
|
||||
// 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));
|
||||
#endif
|
||||
validValue = false;
|
||||
_validValue = false;
|
||||
} else {
|
||||
validValue = true;
|
||||
angle = calculateAngle(lastGyroData);
|
||||
_validValue = true;
|
||||
_angle = calculateAngle(_lastGyroData);
|
||||
#if !defined(GYRO_DISABLE_LOGGING)
|
||||
Log.notice(F("GYRO: Sensor values %d,%d,%d\t%F" CR), lastGyroData.ax,
|
||||
lastGyroData.ay, lastGyroData.az, angle);
|
||||
Log.notice(F("GYRO: Sensor values %d,%d,%d\t%F" CR), _lastGyroData.ax,
|
||||
_lastGyroData.ay, _lastGyroData.az, _angle);
|
||||
#endif
|
||||
}
|
||||
|
||||
sensorTemp = (static_cast<float>(lastGyroData.temp)) / 340 + 36.53;
|
||||
_sensorTemp = (static_cast<float>(_lastGyroData.temp)) / 340 + 36.53;
|
||||
|
||||
// The first read value is close to the DS18 value according to my tests, if
|
||||
// more reads are done then the gyro temp will increase to much
|
||||
if (initialSensorTemp == INVALID_TEMPERATURE) initialSensorTemp = sensorTemp;
|
||||
if (_initialSensorTemp == INVALID_TEMPERATURE) _initialSensorTemp = _sensorTemp;
|
||||
|
||||
return validValue;
|
||||
return _validValue;
|
||||
}
|
||||
|
||||
//
|
||||
@ -270,10 +270,10 @@ bool GyroSensor::read() {
|
||||
//
|
||||
void GyroSensor::dumpCalibration() {
|
||||
#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: Gyro offset \t%d\t%d\t%d" CR), calibrationOffset.gx,
|
||||
calibrationOffset.gy, calibrationOffset.gz);
|
||||
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);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -285,19 +285,19 @@ void GyroSensor::applyCalibration() {
|
||||
Log.verbose(F("GYRO: Applying calibration offsets to sensor." CR));
|
||||
#endif
|
||||
|
||||
if ((calibrationOffset.ax + calibrationOffset.ay + calibrationOffset.az +
|
||||
calibrationOffset.gx + calibrationOffset.gy + calibrationOffset.gz) ==
|
||||
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));
|
||||
return;
|
||||
}
|
||||
|
||||
accelgyro.setXAccelOffset(calibrationOffset.ax);
|
||||
accelgyro.setYAccelOffset(calibrationOffset.ay);
|
||||
accelgyro.setZAccelOffset(calibrationOffset.az);
|
||||
accelgyro.setXGyroOffset(calibrationOffset.gx);
|
||||
accelgyro.setYGyroOffset(calibrationOffset.gy);
|
||||
accelgyro.setZGyroOffset(calibrationOffset.gz);
|
||||
accelgyro.setXAccelOffset(_calibrationOffset.ax);
|
||||
accelgyro.setYAccelOffset(_calibrationOffset.ay);
|
||||
accelgyro.setZAccelOffset(_calibrationOffset.az);
|
||||
accelgyro.setXGyroOffset(_calibrationOffset.gx);
|
||||
accelgyro.setYGyroOffset(_calibrationOffset.gy);
|
||||
accelgyro.setZGyroOffset(_calibrationOffset.gz);
|
||||
}
|
||||
|
||||
//
|
||||
@ -317,15 +317,15 @@ void GyroSensor::calibrateSensor() {
|
||||
accelgyro.PrintActiveOffsets();
|
||||
Serial.print(CR);
|
||||
|
||||
calibrationOffset.ax = accelgyro.getXAccelOffset();
|
||||
calibrationOffset.ay = accelgyro.getYAccelOffset();
|
||||
calibrationOffset.az = accelgyro.getZAccelOffset();
|
||||
calibrationOffset.gx = accelgyro.getXGyroOffset();
|
||||
calibrationOffset.gy = accelgyro.getYGyroOffset();
|
||||
calibrationOffset.gz = accelgyro.getZGyroOffset();
|
||||
_calibrationOffset.ax = accelgyro.getXAccelOffset();
|
||||
_calibrationOffset.ay = accelgyro.getYAccelOffset();
|
||||
_calibrationOffset.az = accelgyro.getZAccelOffset();
|
||||
_calibrationOffset.gx = accelgyro.getXGyroOffset();
|
||||
_calibrationOffset.gy = accelgyro.getYGyroOffset();
|
||||
_calibrationOffset.gz = accelgyro.getZGyroOffset();
|
||||
|
||||
// Save the calibrated values
|
||||
myConfig.setGyroCalibration(calibrationOffset);
|
||||
myConfig.setGyroCalibration(_calibrationOffset);
|
||||
myConfig.saveFile();
|
||||
}
|
||||
|
||||
@ -380,17 +380,17 @@ void GyroSensor::debug() {
|
||||
}
|
||||
|
||||
Log.verbose(F("GYRO: Debug - Acc OffX %d\t%d." CR),
|
||||
accelgyro.getXAccelOffset(), calibrationOffset.az);
|
||||
accelgyro.getXAccelOffset(), _calibrationOffset.az);
|
||||
Log.verbose(F("GYRO: Debug - Acc OffY %d\t%d." CR),
|
||||
accelgyro.getYAccelOffset(), calibrationOffset.ay);
|
||||
accelgyro.getYAccelOffset(), _calibrationOffset.ay);
|
||||
Log.verbose(F("GYRO: Debug - Acc OffZ %d\t%d." CR),
|
||||
accelgyro.getZAccelOffset(), calibrationOffset.az);
|
||||
accelgyro.getZAccelOffset(), _calibrationOffset.az);
|
||||
Log.verbose(F("GYRO: Debug - Gyr OffX %d\t%d." CR),
|
||||
accelgyro.getXGyroOffset(), calibrationOffset.gx);
|
||||
accelgyro.getXGyroOffset(), _calibrationOffset.gx);
|
||||
Log.verbose(F("GYRO: Debug - Gyr OffY %d\t%d." CR),
|
||||
accelgyro.getYGyroOffset(), calibrationOffset.gy);
|
||||
accelgyro.getYGyroOffset(), _calibrationOffset.gy);
|
||||
Log.verbose(F("GYRO: Debug - Gyr OffZ %d\t%d." CR),
|
||||
accelgyro.getZGyroOffset(), calibrationOffset.gz);
|
||||
accelgyro.getZGyroOffset(), _calibrationOffset.gz);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
26
src/gyro.hpp
26
src/gyro.hpp
@ -50,13 +50,13 @@ struct RawGyroDataL { // Used for average multiple readings
|
||||
|
||||
class GyroSensor {
|
||||
private:
|
||||
bool sensorConnected = false;
|
||||
bool validValue = false;
|
||||
float angle = 0;
|
||||
float sensorTemp = 0;
|
||||
float initialSensorTemp = INVALID_TEMPERATURE;
|
||||
RawGyroData calibrationOffset;
|
||||
RawGyroData lastGyroData;
|
||||
bool _sensorConnected = false;
|
||||
bool _validValue = false;
|
||||
float _angle = 0;
|
||||
float _sensorTemp = 0;
|
||||
float _initialSensorTemp = INVALID_TEMPERATURE;
|
||||
RawGyroData _calibrationOffset;
|
||||
RawGyroData _lastGyroData;
|
||||
|
||||
void debug();
|
||||
void applyCalibration();
|
||||
@ -71,12 +71,12 @@ class GyroSensor {
|
||||
bool read();
|
||||
void calibrateSensor();
|
||||
|
||||
const RawGyroData &getLastGyroData() { return lastGyroData; }
|
||||
float getAngle() { return angle; }
|
||||
float getSensorTempC() { return sensorTemp; }
|
||||
float getInitialSensorTempC() { return initialSensorTemp; }
|
||||
bool isConnected() { return sensorConnected; }
|
||||
bool hasValue() { return validValue; }
|
||||
const RawGyroData &getLastGyroData() { return _lastGyroData; }
|
||||
float getAngle() { return _angle; }
|
||||
float getSensorTempC() { return _sensorTemp; }
|
||||
float getInitialSensorTempC() { return _initialSensorTemp; }
|
||||
bool isConnected() { return _sensorConnected; }
|
||||
bool hasValue() { return _validValue; }
|
||||
void enterSleep();
|
||||
};
|
||||
|
||||
|
@ -125,11 +125,11 @@ void BatteryVoltage::read() {
|
||||
// the voltage (from max 5V)
|
||||
float factor = myConfig.getVoltageFactor(); // Default value is 1.63
|
||||
int v = analogRead(A0);
|
||||
batteryLevel = ((3.3 / 1023) * v) * factor;
|
||||
_batteryLevel = ((3.3 / 1023) * v) * factor;
|
||||
#if LOG_LEVEL == 6 && !defined(HELPER_DISABLE_LOGGING)
|
||||
Log.verbose(
|
||||
F("BATT: Reading voltage level. Factor=%F Value=%d, Voltage=%F." CR),
|
||||
factor, v, batteryLevel);
|
||||
factor, v, _batteryLevel);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -57,11 +57,11 @@ class SerialDebug {
|
||||
|
||||
class BatteryVoltage {
|
||||
private:
|
||||
float batteryLevel;
|
||||
float _batteryLevel;
|
||||
|
||||
public:
|
||||
void read();
|
||||
float getVoltage() { return batteryLevel; }
|
||||
float getVoltage() { return _batteryLevel; }
|
||||
};
|
||||
|
||||
#if defined(COLLECT_PERFDATA)
|
||||
|
@ -36,7 +36,7 @@ PushTarget myPushTarget;
|
||||
//
|
||||
void PushTarget::send(float angle, float gravity, float corrGravity,
|
||||
float tempC, float runTime, bool force) {
|
||||
uint32_t timePassed = abs((int32_t)(millis() - ms));
|
||||
uint32_t timePassed = abs((int32_t)(millis() - _ms));
|
||||
uint32_t interval = myConfig.getSleepInterval() * 1000;
|
||||
|
||||
if ((timePassed < interval) && !force) {
|
||||
@ -47,7 +47,7 @@ void PushTarget::send(float angle, float gravity, float corrGravity,
|
||||
return;
|
||||
}
|
||||
|
||||
ms = millis();
|
||||
_ms = millis();
|
||||
|
||||
if (myConfig.isBrewfatherActive()) {
|
||||
LOG_PERF_START("push-brewfather");
|
||||
|
@ -33,7 +33,7 @@ SOFTWARE.
|
||||
// Classes
|
||||
class PushTarget {
|
||||
private:
|
||||
uint32_t ms; // Used to check that we do not post to often
|
||||
uint32_t _ms; // Used to check that we do not post to often
|
||||
|
||||
void sendBrewfather(float angle, float gravity, float corrGravity,
|
||||
float tempC);
|
||||
@ -48,7 +48,7 @@ class PushTarget {
|
||||
float runTime);
|
||||
|
||||
public:
|
||||
PushTarget() { ms = millis(); }
|
||||
PushTarget() { _ms = millis(); }
|
||||
void send(float angle, float gravity, float corrGravity, float temp,
|
||||
float runTime, bool force = false);
|
||||
};
|
||||
|
@ -59,11 +59,11 @@ void TempSensor::setup() {
|
||||
}
|
||||
|
||||
// Set the temp sensor adjustment values
|
||||
tempSensorAdjC = myConfig.getTempSensorAdjC();
|
||||
_tempSensorAdjC = myConfig.getTempSensorAdjC();
|
||||
|
||||
#if LOG_LEVEL == 6 && !defined(TSEN_DISABLE_LOGGING)
|
||||
Log.verbose(F("TSEN: Adjustment values for temp sensor %F C." CR),
|
||||
tempSensorAdjC);
|
||||
_tempSensorAdjC);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ float TempSensor::getValue(bool useGyro) {
|
||||
#if LOG_LEVEL == 6 && !defined(TSEN_DISABLE_LOGGING)
|
||||
Log.verbose(F("TSEN: Reciving temp value for gyro sensor %F C." CR), c);
|
||||
#endif
|
||||
hasSensor = true;
|
||||
_hasSensor = true;
|
||||
return c;
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ float TempSensor::getValue(bool useGyro) {
|
||||
#if LOG_LEVEL == 6 && !defined(TSEN_DISABLE_LOGGING)
|
||||
Log.verbose(F("TSEN: Reciving temp value for DS18B20 sensor %F C." CR), c);
|
||||
#endif
|
||||
hasSensor = true;
|
||||
_hasSensor = true;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
@ -29,15 +29,15 @@ SOFTWARE.
|
||||
// classes
|
||||
class TempSensor {
|
||||
private:
|
||||
bool hasSensor = false;
|
||||
float tempSensorAdjC = 0;
|
||||
bool _hasSensor = false;
|
||||
float _tempSensorAdjC = 0;
|
||||
float getValue(bool useGyro);
|
||||
|
||||
public:
|
||||
void setup();
|
||||
bool isSensorAttached() { return hasSensor; }
|
||||
bool isSensorAttached() { return _hasSensor; }
|
||||
float getTempC(bool useGyro = false) {
|
||||
return getValue(useGyro) + tempSensorAdjC;
|
||||
return getValue(useGyro) + _tempSensorAdjC;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -55,7 +55,7 @@ void WebServer::webHandleDevice() {
|
||||
#endif
|
||||
String out;
|
||||
serializeJson(doc, out);
|
||||
server->send(200, "application/json", out.c_str());
|
||||
_server->send(200, "application/json", out.c_str());
|
||||
LOG_PERF_STOP("webserver-api-device");
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ void WebServer::webHandleConfig() {
|
||||
|
||||
String out;
|
||||
serializeJson(doc, out);
|
||||
server->send(200, "application/json", out.c_str());
|
||||
_server->send(200, "application/json", out.c_str());
|
||||
LOG_PERF_STOP("webserver-api-config");
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ void WebServer::webHandleUpload() {
|
||||
|
||||
String out;
|
||||
serializeJson(doc, out);
|
||||
server->send(200, "application/json", out.c_str());
|
||||
_server->send(200, "application/json", out.c_str());
|
||||
LOG_PERF_STOP("webserver-api-upload");
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ void WebServer::webHandleUpload() {
|
||||
void WebServer::webHandleUploadFile() {
|
||||
LOG_PERF_START("webserver-api-upload-file");
|
||||
Log.notice(F("WEB : webServer callback for /api/upload/file." CR));
|
||||
HTTPUpload& upload = server->upload();
|
||||
HTTPUpload& upload = _server->upload();
|
||||
String f = upload.filename;
|
||||
bool validFilename = false;
|
||||
|
||||
@ -153,23 +153,23 @@ void WebServer::webHandleUploadFile() {
|
||||
|
||||
if (upload.status == UPLOAD_FILE_START) {
|
||||
Log.notice(F("WEB : Start upload." CR));
|
||||
if (validFilename) uploadFile = LittleFS.open(f, "w");
|
||||
if (validFilename) _uploadFile = LittleFS.open(f, "w");
|
||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||
Log.notice(F("WEB : Writing upload." CR));
|
||||
if (uploadFile)
|
||||
uploadFile.write(
|
||||
if (_uploadFile)
|
||||
_uploadFile.write(
|
||||
upload.buf,
|
||||
upload.currentSize); // Write the received bytes to the file
|
||||
} else if (upload.status == UPLOAD_FILE_END) {
|
||||
Log.notice(F("WEB : Finish upload." CR));
|
||||
if (uploadFile) {
|
||||
uploadFile.close();
|
||||
if (_uploadFile) {
|
||||
_uploadFile.close();
|
||||
Log.notice(F("WEB : File uploaded %d bytes." CR), upload.totalSize);
|
||||
}
|
||||
server->sendHeader("Location", "/");
|
||||
server->send(303);
|
||||
_server->sendHeader("Location", "/");
|
||||
_server->send(303);
|
||||
} else {
|
||||
server->send(500, "text/plain", "Couldn't create file.");
|
||||
_server->send(500, "text/plain", "Couldn't create file.");
|
||||
}
|
||||
LOG_PERF_STOP("webserver-api-upload-file");
|
||||
}
|
||||
@ -179,18 +179,18 @@ void WebServer::webHandleUploadFile() {
|
||||
//
|
||||
void WebServer::webHandleCalibrate() {
|
||||
LOG_PERF_START("webserver-api-calibrate");
|
||||
String id = server->arg(CFG_PARAM_ID);
|
||||
String id = _server->arg(CFG_PARAM_ID);
|
||||
Log.notice(F("WEB : webServer callback for /api/calibrate." CR));
|
||||
|
||||
if (!id.equalsIgnoreCase(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-calibrate");
|
||||
return;
|
||||
}
|
||||
myGyro.calibrateSensor();
|
||||
server->send(200, "text/plain", "Device calibrated");
|
||||
_server->send(200, "text/plain", "Device calibrated");
|
||||
LOG_PERF_STOP("webserver-api-calibrate");
|
||||
}
|
||||
|
||||
@ -198,17 +198,17 @@ void WebServer::webHandleCalibrate() {
|
||||
// Callback from webServer when / has been accessed.
|
||||
//
|
||||
void WebServer::webHandleFactoryReset() {
|
||||
String id = server->arg(CFG_PARAM_ID);
|
||||
String id = _server->arg(CFG_PARAM_ID);
|
||||
Log.notice(F("WEB : webServer callback for /api/factory." CR));
|
||||
|
||||
if (!id.compareTo(myConfig.getID())) {
|
||||
server->send(200, "text/plain", "Doing reset...");
|
||||
_server->send(200, "text/plain", "Doing reset...");
|
||||
LittleFS.remove(CFG_FILENAME);
|
||||
LittleFS.end();
|
||||
delay(500);
|
||||
ESP.reset();
|
||||
} else {
|
||||
server->send(400, "text/plain", "Unknown ID.");
|
||||
_server->send(400, "text/plain", "Unknown ID.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,7 +250,7 @@ void WebServer::webHandleStatus() {
|
||||
|
||||
String out;
|
||||
serializeJson(doc, out);
|
||||
server->send(200, "application/json", out.c_str());
|
||||
_server->send(200, "application/json", out.c_str());
|
||||
LOG_PERF_STOP("webserver-api-status");
|
||||
}
|
||||
|
||||
@ -258,17 +258,17 @@ void WebServer::webHandleStatus() {
|
||||
// Callback from webServer when / has been accessed.
|
||||
//
|
||||
void WebServer::webHandleClearWIFI() {
|
||||
String id = server->arg(CFG_PARAM_ID);
|
||||
String id = _server->arg(CFG_PARAM_ID);
|
||||
Log.notice(F("WEB : webServer callback for /api/clearwifi." CR));
|
||||
|
||||
if (!id.compareTo(myConfig.getID())) {
|
||||
server->send(200, "text/plain",
|
||||
_server->send(200, "text/plain",
|
||||
"Clearing WIFI credentials and doing reset...");
|
||||
delay(1000);
|
||||
WiFi.disconnect(); // Clear credentials
|
||||
ESP.reset();
|
||||
} else {
|
||||
server->send(400, "text/plain", "Unknown ID.");
|
||||
_server->send(400, "text/plain", "Unknown ID.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -277,13 +277,13 @@ void WebServer::webHandleClearWIFI() {
|
||||
//
|
||||
void WebServer::webHandleStatusSleepmode() {
|
||||
LOG_PERF_START("webserver-api-sleepmode");
|
||||
String id = server->arg(CFG_PARAM_ID);
|
||||
String id = _server->arg(CFG_PARAM_ID);
|
||||
Log.notice(F("WEB : webServer callback for /api/status/sleepmode." CR));
|
||||
|
||||
if (!id.equalsIgnoreCase(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");
|
||||
return;
|
||||
}
|
||||
@ -292,11 +292,11 @@ void WebServer::webHandleStatusSleepmode() {
|
||||
Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str());
|
||||
#endif
|
||||
|
||||
if (server->arg(CFG_PARAM_SLEEP_MODE).equalsIgnoreCase("true"))
|
||||
if (_server->arg(CFG_PARAM_SLEEP_MODE).equalsIgnoreCase("true"))
|
||||
sleepModeAlwaysSkip = true;
|
||||
else
|
||||
sleepModeAlwaysSkip = false;
|
||||
server->send(200, "text/plain", "Sleep mode updated");
|
||||
_server->send(200, "text/plain", "Sleep mode updated");
|
||||
LOG_PERF_STOP("webserver-api-sleepmode");
|
||||
}
|
||||
|
||||
@ -305,13 +305,13 @@ void WebServer::webHandleStatusSleepmode() {
|
||||
//
|
||||
void WebServer::webHandleConfigDevice() {
|
||||
LOG_PERF_START("webserver-api-config-device");
|
||||
String id = server->arg(CFG_PARAM_ID);
|
||||
String id = _server->arg(CFG_PARAM_ID);
|
||||
Log.notice(F("WEB : webServer callback for /api/config/device." CR));
|
||||
|
||||
if (!id.equalsIgnoreCase(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");
|
||||
return;
|
||||
}
|
||||
@ -320,12 +320,12 @@ void WebServer::webHandleConfigDevice() {
|
||||
Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str());
|
||||
#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.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");
|
||||
_server->sendHeader("Location", "/config.htm#collapseOne", true);
|
||||
_server->send(302, "text/plain", "Device config updated");
|
||||
LOG_PERF_STOP("webserver-api-config-device");
|
||||
}
|
||||
|
||||
@ -334,13 +334,13 @@ void WebServer::webHandleConfigDevice() {
|
||||
//
|
||||
void WebServer::webHandleConfigPush() {
|
||||
LOG_PERF_START("webserver-api-config-push");
|
||||
String id = server->arg(CFG_PARAM_ID);
|
||||
String id = _server->arg(CFG_PARAM_ID);
|
||||
Log.notice(F("WEB : webServer callback for /api/config/push." CR));
|
||||
|
||||
if (!id.equalsIgnoreCase(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");
|
||||
return;
|
||||
}
|
||||
@ -348,23 +348,23 @@ void WebServer::webHandleConfigPush() {
|
||||
Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str());
|
||||
#endif
|
||||
|
||||
myConfig.setHttpPushUrl(server->arg(CFG_PARAM_PUSH_HTTP).c_str());
|
||||
myConfig.setHttpPushUrl2(server->arg(CFG_PARAM_PUSH_HTTP2).c_str());
|
||||
myConfig.setBrewfatherPushUrl(server->arg(CFG_PARAM_PUSH_BREWFATHER).c_str());
|
||||
myConfig.setInfluxDb2PushUrl(server->arg(CFG_PARAM_PUSH_INFLUXDB2).c_str());
|
||||
myConfig.setHttpPushUrl(_server->arg(CFG_PARAM_PUSH_HTTP).c_str());
|
||||
myConfig.setHttpPushUrl2(_server->arg(CFG_PARAM_PUSH_HTTP2).c_str());
|
||||
myConfig.setBrewfatherPushUrl(_server->arg(CFG_PARAM_PUSH_BREWFATHER).c_str());
|
||||
myConfig.setInfluxDb2PushUrl(_server->arg(CFG_PARAM_PUSH_INFLUXDB2).c_str());
|
||||
myConfig.setInfluxDb2PushOrg(
|
||||
server->arg(CFG_PARAM_PUSH_INFLUXDB2_ORG).c_str());
|
||||
_server->arg(CFG_PARAM_PUSH_INFLUXDB2_ORG).c_str());
|
||||
myConfig.setInfluxDb2PushBucket(
|
||||
server->arg(CFG_PARAM_PUSH_INFLUXDB2_BUCKET).c_str());
|
||||
_server->arg(CFG_PARAM_PUSH_INFLUXDB2_BUCKET).c_str());
|
||||
myConfig.setInfluxDb2PushToken(
|
||||
server->arg(CFG_PARAM_PUSH_INFLUXDB2_AUTH).c_str());
|
||||
myConfig.setMqttUrl(server->arg(CFG_PARAM_PUSH_MQTT).c_str());
|
||||
myConfig.setMqttTopic(server->arg(CFG_PARAM_PUSH_MQTT_TOPIC).c_str());
|
||||
myConfig.setMqttUser(server->arg(CFG_PARAM_PUSH_MQTT_USER).c_str());
|
||||
myConfig.setMqttPass(server->arg(CFG_PARAM_PUSH_MQTT_PASS).c_str());
|
||||
_server->arg(CFG_PARAM_PUSH_INFLUXDB2_AUTH).c_str());
|
||||
myConfig.setMqttUrl(_server->arg(CFG_PARAM_PUSH_MQTT).c_str());
|
||||
myConfig.setMqttTopic(_server->arg(CFG_PARAM_PUSH_MQTT_TOPIC).c_str());
|
||||
myConfig.setMqttUser(_server->arg(CFG_PARAM_PUSH_MQTT_USER).c_str());
|
||||
myConfig.setMqttPass(_server->arg(CFG_PARAM_PUSH_MQTT_PASS).c_str());
|
||||
myConfig.saveFile();
|
||||
server->sendHeader("Location", "/config.htm#collapseTwo", true);
|
||||
server->send(302, "text/plain", "Push config updated");
|
||||
_server->sendHeader("Location", "/config.htm#collapseTwo", true);
|
||||
_server->send(302, "text/plain", "Push config updated");
|
||||
LOG_PERF_STOP("webserver-api-config-push");
|
||||
}
|
||||
|
||||
@ -374,14 +374,14 @@ void WebServer::webHandleConfigPush() {
|
||||
String WebServer::getRequestArguments() {
|
||||
String debug;
|
||||
|
||||
for (int i = 0; i < server->args(); i++) {
|
||||
if (!server->argName(i).equals(
|
||||
for (int i = 0; i < _server->args(); i++) {
|
||||
if (!_server->argName(i).equals(
|
||||
"plain")) { // this contains all the arguments, we dont need that.
|
||||
if (debug.length()) debug += ", ";
|
||||
|
||||
debug += server->argName(i);
|
||||
debug += _server->argName(i);
|
||||
debug += "=";
|
||||
debug += server->arg(i);
|
||||
debug += _server->arg(i);
|
||||
}
|
||||
}
|
||||
return debug;
|
||||
@ -392,13 +392,13 @@ String WebServer::getRequestArguments() {
|
||||
//
|
||||
void WebServer::webHandleConfigGravity() {
|
||||
LOG_PERF_START("webserver-api-config-gravity");
|
||||
String id = server->arg(CFG_PARAM_ID);
|
||||
String id = _server->arg(CFG_PARAM_ID);
|
||||
Log.notice(F("WEB : webServer callback for /api/config/gravity." CR));
|
||||
|
||||
if (!id.equalsIgnoreCase(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");
|
||||
return;
|
||||
}
|
||||
@ -407,14 +407,14 @@ void WebServer::webHandleConfigGravity() {
|
||||
Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str());
|
||||
#endif
|
||||
|
||||
myConfig.setGravityFormat(server->arg(CFG_PARAM_GRAVITY_FORMAT).charAt(0));
|
||||
myConfig.setGravityFormula(server->arg(CFG_PARAM_GRAVITY_FORMULA).c_str());
|
||||
myConfig.setGravityFormat(_server->arg(CFG_PARAM_GRAVITY_FORMAT).charAt(0));
|
||||
myConfig.setGravityFormula(_server->arg(CFG_PARAM_GRAVITY_FORMULA).c_str());
|
||||
myConfig.setGravityTempAdj(
|
||||
server->arg(CFG_PARAM_GRAVITY_TEMP_ADJ).equalsIgnoreCase("on") ? true
|
||||
_server->arg(CFG_PARAM_GRAVITY_TEMP_ADJ).equalsIgnoreCase("on") ? true
|
||||
: false);
|
||||
myConfig.saveFile();
|
||||
server->sendHeader("Location", "/config.htm#collapseThree", true);
|
||||
server->send(302, "text/plain", "Gravity config updated");
|
||||
_server->sendHeader("Location", "/config.htm#collapseThree", true);
|
||||
_server->send(302, "text/plain", "Gravity config updated");
|
||||
LOG_PERF_STOP("webserver-api-config-gravity");
|
||||
}
|
||||
|
||||
@ -423,13 +423,13 @@ void WebServer::webHandleConfigGravity() {
|
||||
//
|
||||
void WebServer::webHandleConfigHardware() {
|
||||
LOG_PERF_START("webserver-api-config-hardware");
|
||||
String id = server->arg(CFG_PARAM_ID);
|
||||
String id = _server->arg(CFG_PARAM_ID);
|
||||
Log.notice(F("WEB : webServer callback for /api/config/hardware." CR));
|
||||
|
||||
if (!id.equalsIgnoreCase(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");
|
||||
return;
|
||||
}
|
||||
@ -438,18 +438,18 @@ void WebServer::webHandleConfigHardware() {
|
||||
Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str());
|
||||
#endif
|
||||
|
||||
myConfig.setVoltageFactor(server->arg(CFG_PARAM_VOLTAGEFACTOR).toFloat());
|
||||
myConfig.setVoltageFactor(_server->arg(CFG_PARAM_VOLTAGEFACTOR).toFloat());
|
||||
if (myConfig.isTempC()) {
|
||||
myConfig.setTempSensorAdjC(server->arg(CFG_PARAM_TEMP_ADJ));
|
||||
myConfig.setTempSensorAdjC(_server->arg(CFG_PARAM_TEMP_ADJ));
|
||||
} else {
|
||||
myConfig.setTempSensorAdjF(server->arg(CFG_PARAM_TEMP_ADJ));
|
||||
myConfig.setTempSensorAdjF(_server->arg(CFG_PARAM_TEMP_ADJ));
|
||||
}
|
||||
myConfig.setOtaURL(server->arg(CFG_PARAM_OTA).c_str());
|
||||
myConfig.setOtaURL(_server->arg(CFG_PARAM_OTA).c_str());
|
||||
myConfig.setGyroTemp(
|
||||
server->arg(CFG_PARAM_GYRO_TEMP).equalsIgnoreCase("on") ? true : false);
|
||||
_server->arg(CFG_PARAM_GYRO_TEMP).equalsIgnoreCase("on") ? true : false);
|
||||
myConfig.saveFile();
|
||||
server->sendHeader("Location", "/config.htm#collapseFour", true);
|
||||
server->send(302, "text/plain", "Hardware config updated");
|
||||
_server->sendHeader("Location", "/config.htm#collapseFour", true);
|
||||
_server->send(302, "text/plain", "Hardware config updated");
|
||||
LOG_PERF_STOP("webserver-api-config-hardware");
|
||||
}
|
||||
|
||||
@ -473,7 +473,7 @@ void WebServer::webHandleFormulaRead() {
|
||||
doc[CFG_PARAM_GRAVITY_FORMULA] = "";
|
||||
doc[CFG_PARAM_ERROR] = "";
|
||||
|
||||
switch (lastFormulaCreateError) {
|
||||
switch (_lastFormulaCreateError) {
|
||||
case ERR_FORMULA_INTERNAL:
|
||||
doc[CFG_PARAM_ERROR] = "Internal error creating formula.";
|
||||
break;
|
||||
@ -516,7 +516,7 @@ void WebServer::webHandleFormulaRead() {
|
||||
|
||||
String out;
|
||||
serializeJson(doc, out);
|
||||
server->send(200, "application/json", out.c_str());
|
||||
_server->send(200, "application/json", out.c_str());
|
||||
LOG_PERF_STOP("webserver-api-formula-read");
|
||||
}
|
||||
|
||||
@ -525,13 +525,13 @@ void WebServer::webHandleFormulaRead() {
|
||||
//
|
||||
void WebServer::webHandleFormulaWrite() {
|
||||
LOG_PERF_START("webserver-api-formula-write");
|
||||
String id = server->arg(CFG_PARAM_ID);
|
||||
String id = _server->arg(CFG_PARAM_ID);
|
||||
Log.notice(F("WEB : webServer callback for /api/formula/post." CR));
|
||||
|
||||
if (!id.equalsIgnoreCase(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");
|
||||
return;
|
||||
}
|
||||
@ -541,24 +541,24 @@ void WebServer::webHandleFormulaWrite() {
|
||||
#endif
|
||||
|
||||
RawFormulaData fd;
|
||||
fd.a[0] = server->arg("a1").toDouble();
|
||||
fd.a[1] = server->arg("a2").toDouble();
|
||||
fd.a[2] = server->arg("a3").toDouble();
|
||||
fd.a[3] = server->arg("a4").toDouble();
|
||||
fd.a[4] = server->arg("a5").toDouble();
|
||||
fd.a[0] = _server->arg("a1").toDouble();
|
||||
fd.a[1] = _server->arg("a2").toDouble();
|
||||
fd.a[2] = _server->arg("a3").toDouble();
|
||||
fd.a[3] = _server->arg("a4").toDouble();
|
||||
fd.a[4] = _server->arg("a5").toDouble();
|
||||
|
||||
if (myConfig.isGravityPlato()) {
|
||||
fd.g[0] = convertToSG(server->arg("g1").toDouble());
|
||||
fd.g[1] = convertToSG(server->arg("g2").toDouble());
|
||||
fd.g[2] = convertToSG(server->arg("g3").toDouble());
|
||||
fd.g[3] = convertToSG(server->arg("g4").toDouble());
|
||||
fd.g[4] = convertToSG(server->arg("g5").toDouble());
|
||||
fd.g[0] = convertToSG(_server->arg("g1").toDouble());
|
||||
fd.g[1] = convertToSG(_server->arg("g2").toDouble());
|
||||
fd.g[2] = convertToSG(_server->arg("g3").toDouble());
|
||||
fd.g[3] = convertToSG(_server->arg("g4").toDouble());
|
||||
fd.g[4] = convertToSG(_server->arg("g5").toDouble());
|
||||
} else {
|
||||
fd.g[0] = server->arg("g1").toDouble();
|
||||
fd.g[1] = server->arg("g2").toDouble();
|
||||
fd.g[2] = server->arg("g3").toDouble();
|
||||
fd.g[3] = server->arg("g4").toDouble();
|
||||
fd.g[4] = server->arg("g5").toDouble();
|
||||
fd.g[0] = _server->arg("g1").toDouble();
|
||||
fd.g[1] = _server->arg("g2").toDouble();
|
||||
fd.g[2] = _server->arg("g3").toDouble();
|
||||
fd.g[3] = _server->arg("g4").toDouble();
|
||||
fd.g[4] = _server->arg("g5").toDouble();
|
||||
}
|
||||
|
||||
myConfig.setFormulaData(fd);
|
||||
@ -585,17 +585,17 @@ void WebServer::webHandleFormulaWrite() {
|
||||
Log.error(
|
||||
F("WEB : Unable to find formula based on provided values err=%d." CR),
|
||||
e);
|
||||
lastFormulaCreateError = e;
|
||||
_lastFormulaCreateError = e;
|
||||
} else {
|
||||
// Save the formula as succesful
|
||||
Log.info(F("WEB : Found valid formula: '%s'" CR), &buf[0]);
|
||||
myConfig.setGravityFormula(buf);
|
||||
lastFormulaCreateError = 0;
|
||||
_lastFormulaCreateError = 0;
|
||||
}
|
||||
|
||||
myConfig.saveFile();
|
||||
server->sendHeader("Location", "/calibration.htm", true);
|
||||
server->send(302, "text/plain", "Formula updated");
|
||||
_server->sendHeader("Location", "/calibration.htm", true);
|
||||
_server->send(302, "text/plain", "Formula updated");
|
||||
LOG_PERF_STOP("webserver-api-formula-write");
|
||||
}
|
||||
|
||||
@ -641,8 +641,8 @@ bool WebServer::checkHtmlFile(HtmlFile item) {
|
||||
// Handler for page not found
|
||||
//
|
||||
void WebServer::webHandlePageNotFound() {
|
||||
Log.error(F("WEB : URL not found %s received." CR), server->uri().c_str());
|
||||
server->send(404, "text/plain", F("URL not found"));
|
||||
Log.error(F("WEB : URL not found %s received." CR), _server->uri().c_str());
|
||||
_server->send(404, "text/plain", F("URL not found"));
|
||||
}
|
||||
|
||||
//
|
||||
@ -651,20 +651,20 @@ void WebServer::webHandlePageNotFound() {
|
||||
bool WebServer::setupWebServer() {
|
||||
Log.notice(F("WEB : Configuring web server." CR));
|
||||
|
||||
server = new ESP8266WebServer();
|
||||
_server = new ESP8266WebServer();
|
||||
|
||||
MDNS.begin(myConfig.getMDNS());
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
|
||||
// Static content
|
||||
#if defined(EMBED_HTML)
|
||||
server->on("/", std::bind(&WebServer::webReturnIndexHtm, this));
|
||||
server->on("/index.htm", std::bind(&WebServer::webReturnIndexHtm, this));
|
||||
server->on("/device.htm", std::bind(&WebServer::webReturnDeviceHtm, this));
|
||||
server->on("/config.htm", std::bind(&WebServer::webReturnConfigHtm, this));
|
||||
server->on("/calibration.htm",
|
||||
_server->on("/", std::bind(&WebServer::webReturnIndexHtm, this));
|
||||
_server->on("/index.htm", std::bind(&WebServer::webReturnIndexHtm, this));
|
||||
_server->on("/device.htm", std::bind(&WebServer::webReturnDeviceHtm, this));
|
||||
_server->on("/config.htm", std::bind(&WebServer::webReturnConfigHtm, this));
|
||||
_server->on("/calibration.htm",
|
||||
std::bind(&WebServer::webReturnCalibrationHtm, this));
|
||||
server->on("/about.htm", std::bind(&WebServer::webReturnAboutHtm, this));
|
||||
_server->on("/about.htm", std::bind(&WebServer::webReturnAboutHtm, this));
|
||||
#else
|
||||
// Show files in the filessytem at startup
|
||||
|
||||
@ -685,69 +685,69 @@ bool WebServer::setupWebServer() {
|
||||
checkHtmlFile(HTML_ABOUT)) {
|
||||
Log.notice(F("WEB : All html files exist, starting in normal mode." CR));
|
||||
|
||||
server->serveStatic("/", LittleFS, "/index.min.htm");
|
||||
server->serveStatic("/index.htm", LittleFS, "/index.min.htm");
|
||||
server->serveStatic("/device.htm", LittleFS, "/device.min.htm");
|
||||
server->serveStatic("/config.htm", LittleFS, "/config.min.htm");
|
||||
server->serveStatic("/about.htm", LittleFS, "/about.min.htm");
|
||||
server->serveStatic("/calibration.htm", LittleFS, "/calibration.min.htm");
|
||||
_server->serveStatic("/", LittleFS, "/index.min.htm");
|
||||
_server->serveStatic("/index.htm", LittleFS, "/index.min.htm");
|
||||
_server->serveStatic("/device.htm", LittleFS, "/device.min.htm");
|
||||
_server->serveStatic("/config.htm", LittleFS, "/config.min.htm");
|
||||
_server->serveStatic("/about.htm", LittleFS, "/about.min.htm");
|
||||
_server->serveStatic("/calibration.htm", LittleFS, "/calibration.min.htm");
|
||||
|
||||
// Also add the static upload view in case we we have issues that needs to
|
||||
// be fixed.
|
||||
server->on("/upload.htm", std::bind(&WebServer::webReturnUploadHtm, this));
|
||||
_server->on("/upload.htm", std::bind(&WebServer::webReturnUploadHtm, this));
|
||||
} else {
|
||||
Log.error(F("WEB : Missing html files, starting with upload UI." CR));
|
||||
server->on("/", std::bind(&WebServer::webReturnUploadHtm, this));
|
||||
_server->on("/", std::bind(&WebServer::webReturnUploadHtm, this));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Dynamic content
|
||||
server->on("/api/config", HTTP_GET,
|
||||
_server->on("/api/config", HTTP_GET,
|
||||
std::bind(&WebServer::webHandleConfig, this)); // Get config.json
|
||||
server->on("/api/device", HTTP_GET,
|
||||
_server->on("/api/device", HTTP_GET,
|
||||
std::bind(&WebServer::webHandleDevice, this)); // Get device.json
|
||||
server->on("/api/formula", HTTP_GET,
|
||||
_server->on("/api/formula", HTTP_GET,
|
||||
std::bind(&WebServer::webHandleFormulaRead,
|
||||
this)); // Get formula.json (calibration page)
|
||||
server->on("/api/formula", HTTP_POST,
|
||||
_server->on("/api/formula", HTTP_POST,
|
||||
std::bind(&WebServer::webHandleFormulaWrite,
|
||||
this)); // Get formula.json (calibration page)
|
||||
server->on("/api/calibrate", HTTP_POST,
|
||||
_server->on("/api/calibrate", HTTP_POST,
|
||||
std::bind(&WebServer::webHandleCalibrate,
|
||||
this)); // Run calibration routine (param id)
|
||||
server->on(
|
||||
_server->on(
|
||||
"/api/factory", HTTP_GET,
|
||||
std::bind(&WebServer::webHandleFactoryReset, this)); // Reset the device
|
||||
server->on(
|
||||
_server->on(
|
||||
"/api/status", HTTP_GET,
|
||||
std::bind(&WebServer::webHandleStatus, this)); // Get the status.json
|
||||
server->on(
|
||||
_server->on(
|
||||
"/api/clearwifi", HTTP_GET,
|
||||
std::bind(&WebServer::webHandleClearWIFI, this)); // Clear wifi settings
|
||||
server->on("/api/upload", HTTP_GET,
|
||||
_server->on("/api/upload", HTTP_GET,
|
||||
std::bind(&WebServer::webHandleUpload, this)); // Get upload.json
|
||||
|
||||
server->on(
|
||||
_server->on(
|
||||
"/api/upload", HTTP_POST, std::bind(&WebServer::webReturnOK, this),
|
||||
std::bind(&WebServer::webHandleUploadFile, this)); // File upload data
|
||||
server->on("/api/status/sleepmode", HTTP_POST,
|
||||
_server->on("/api/status/sleepmode", HTTP_POST,
|
||||
std::bind(&WebServer::webHandleStatusSleepmode,
|
||||
this)); // Change sleep mode
|
||||
server->on("/api/config/device", HTTP_POST,
|
||||
_server->on("/api/config/device", HTTP_POST,
|
||||
std::bind(&WebServer::webHandleConfigDevice,
|
||||
this)); // Change device settings
|
||||
server->on("/api/config/push", HTTP_POST,
|
||||
_server->on("/api/config/push", HTTP_POST,
|
||||
std::bind(&WebServer::webHandleConfigPush,
|
||||
this)); // Change push settings
|
||||
server->on("/api/config/gravity", HTTP_POST,
|
||||
_server->on("/api/config/gravity", HTTP_POST,
|
||||
std::bind(&WebServer::webHandleConfigGravity,
|
||||
this)); // Change gravity settings
|
||||
server->on("/api/config/hardware", HTTP_POST,
|
||||
_server->on("/api/config/hardware", HTTP_POST,
|
||||
std::bind(&WebServer::webHandleConfigHardware,
|
||||
this)); // Change hardware settings
|
||||
|
||||
server->onNotFound(std::bind(&WebServer::webHandlePageNotFound, this));
|
||||
server->begin();
|
||||
_server->onNotFound(std::bind(&WebServer::webHandlePageNotFound, this));
|
||||
_server->begin();
|
||||
Log.notice(F("WEB : Web server started." CR));
|
||||
return true;
|
||||
}
|
||||
@ -757,7 +757,7 @@ bool WebServer::setupWebServer() {
|
||||
//
|
||||
void WebServer::loop() {
|
||||
MDNS.update();
|
||||
server->handleClient();
|
||||
_server->handleClient();
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
@ -44,9 +44,9 @@ INCBIN_EXTERN(UploadHtm);
|
||||
// classes
|
||||
class WebServer {
|
||||
private:
|
||||
ESP8266WebServer* server = 0;
|
||||
File uploadFile;
|
||||
int lastFormulaCreateError = 0;
|
||||
ESP8266WebServer* _server = 0;
|
||||
File _uploadFile;
|
||||
int _lastFormulaCreateError = 0;
|
||||
|
||||
void webHandleConfig();
|
||||
void webHandleFormulaWrite();
|
||||
@ -68,29 +68,29 @@ class WebServer {
|
||||
String getRequestArguments();
|
||||
|
||||
// Inline functions.
|
||||
void webReturnOK() { server->send(200); }
|
||||
void webReturnOK() { _server->send(200); }
|
||||
#if defined(EMBED_HTML)
|
||||
void webReturnIndexHtm() {
|
||||
server->send_P(200, "text/html", (const char*)gIndexHtmData, gIndexHtmSize);
|
||||
_server->send_P(200, "text/html", (const char*)gIndexHtmData, gIndexHtmSize);
|
||||
}
|
||||
void webReturnDeviceHtm() {
|
||||
server->send_P(200, "text/html", (const char*)gDeviceHtmData,
|
||||
_server->send_P(200, "text/html", (const char*)gDeviceHtmData,
|
||||
gDeviceHtmSize);
|
||||
}
|
||||
void webReturnConfigHtm() {
|
||||
server->send_P(200, "text/html", (const char*)gConfigHtmData,
|
||||
_server->send_P(200, "text/html", (const char*)gConfigHtmData,
|
||||
gConfigHtmSize);
|
||||
}
|
||||
void webReturnCalibrationHtm() {
|
||||
server->send_P(200, "text/html", (const char*)gCalibrationHtmData,
|
||||
_server->send_P(200, "text/html", (const char*)gCalibrationHtmData,
|
||||
gCalibrationHtmSize);
|
||||
}
|
||||
void webReturnAboutHtm() {
|
||||
server->send_P(200, "text/html", (const char*)gAboutHtmData, gAboutHtmSize);
|
||||
_server->send_P(200, "text/html", (const char*)gAboutHtmData, gAboutHtmSize);
|
||||
}
|
||||
#else
|
||||
void webReturnUploadHtm() {
|
||||
server->send_P(200, "text/html", (const char*)gUploadHtmData,
|
||||
_server->send_P(200, "text/html", (const char*)gUploadHtmData,
|
||||
gUploadHtmSize);
|
||||
}
|
||||
#endif
|
||||
|
14
src/wifi.cpp
14
src/wifi.cpp
@ -224,7 +224,7 @@ bool WifiConnection::disconnect() {
|
||||
//
|
||||
//
|
||||
bool WifiConnection::updateFirmware() {
|
||||
if (!newFirmware) {
|
||||
if (!_newFirmware) {
|
||||
Log.notice(F("WIFI: No newer version exist, skipping update." CR));
|
||||
return false;
|
||||
}
|
||||
@ -345,19 +345,19 @@ bool WifiConnection::checkFirmwareVersion() {
|
||||
curVer[2]);
|
||||
#endif
|
||||
// Compare major version
|
||||
if (newVer[0] > curVer[0]) newFirmware = true;
|
||||
if (newVer[0] > curVer[0]) _newFirmware = true;
|
||||
// Compare minor version
|
||||
if (newVer[0] == curVer[0] && newVer[1] > curVer[1])
|
||||
newFirmware = true;
|
||||
_newFirmware = true;
|
||||
// Compare patch version
|
||||
if (newVer[0] == curVer[0] && newVer[1] == curVer[1] &&
|
||||
newVer[2] > curVer[2])
|
||||
newFirmware = true;
|
||||
_newFirmware = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Download new html files to filesystem if they are present.
|
||||
if (!ver["html"].isNull() && newFirmware) {
|
||||
if (!ver["html"].isNull() && _newFirmware) {
|
||||
Log.notice(F("WIFI: OTA downloading new html files." CR));
|
||||
JsonArray htmlFiles = ver["html"].as<JsonArray>();
|
||||
for (JsonVariant v : htmlFiles) {
|
||||
@ -377,9 +377,9 @@ bool WifiConnection::checkFirmwareVersion() {
|
||||
myWifi.closeWifiClient();
|
||||
#if LOG_LEVEL == 6
|
||||
Log.verbose(F("WIFI: OTA found new version %s." CR),
|
||||
newFirmware ? "true" : "false");
|
||||
_newFirmware ? "true" : "false");
|
||||
#endif
|
||||
return newFirmware;
|
||||
return _newFirmware;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -41,7 +41,7 @@ class WifiConnection {
|
||||
WiFiClientSecure _secureClient;
|
||||
|
||||
// OTA
|
||||
bool newFirmware = false;
|
||||
bool _newFirmware = false;
|
||||
bool parseFirmwareVersionString(int (&num)[3], const char* version);
|
||||
void downloadFile(const char* fname);
|
||||
void connectAsync();
|
||||
|
Loading…
Reference in New Issue
Block a user