pre-commit updates
This commit is contained in:
parent
2d67a44ad0
commit
c779a45ea9
11
src/ble.cpp
11
src/ble.cpp
@ -24,6 +24,7 @@ SOFTWARE.
|
|||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
|
|
||||||
#include <ble.hpp>
|
#include <ble.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
// Tilt UUID variants and data format, based on tilt-sim
|
// Tilt UUID variants and data format, based on tilt-sim
|
||||||
//
|
//
|
||||||
@ -38,7 +39,8 @@ SOFTWARE.
|
|||||||
BleSender::BleSender(const char* color) {
|
BleSender::BleSender(const char* color) {
|
||||||
BLEDevice::init("");
|
BLEDevice::init("");
|
||||||
|
|
||||||
// boost power to maximum, these might be changed once battery life using BLE has been tested.
|
// boost power to maximum, these might be changed once battery life using BLE
|
||||||
|
// has been tested.
|
||||||
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, ESP_PWR_LVL_P9);
|
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, ESP_PWR_LVL_P9);
|
||||||
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV, ESP_PWR_LVL_P9);
|
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV, ESP_PWR_LVL_P9);
|
||||||
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_SCAN, ESP_PWR_LVL_P9);
|
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_SCAN, ESP_PWR_LVL_P9);
|
||||||
@ -72,13 +74,14 @@ void BleSender::sendData(float tempF, float gravSG) {
|
|||||||
uint16_t temperature = tempF; // Deg F _or_ Deg F * 10 for Tilt Pro/HD
|
uint16_t temperature = tempF; // Deg F _or_ Deg F * 10 for Tilt Pro/HD
|
||||||
|
|
||||||
BLEBeacon oBeacon = BLEBeacon();
|
BLEBeacon oBeacon = BLEBeacon();
|
||||||
oBeacon.setManufacturerId(0x4C00); // fake Apple 0x004C LSB (ENDIAN_CHANGE_U16!)
|
oBeacon.setManufacturerId(
|
||||||
|
0x4C00); // fake Apple 0x004C LSB (ENDIAN_CHANGE_U16!)
|
||||||
oBeacon.setProximityUUID(_uuid);
|
oBeacon.setProximityUUID(_uuid);
|
||||||
oBeacon.setMajor(temperature);
|
oBeacon.setMajor(temperature);
|
||||||
oBeacon.setMinor(gravity);
|
oBeacon.setMinor(gravity);
|
||||||
std::string strServiceData = "";
|
std::string strServiceData = "";
|
||||||
strServiceData += (char)26; // Len
|
strServiceData += static_cast<char>(26); // Len
|
||||||
strServiceData += (char)0xFF; // Type
|
strServiceData += static_cast<char>(0xFF); // Type
|
||||||
strServiceData += oBeacon.getData();
|
strServiceData += oBeacon.getData();
|
||||||
|
|
||||||
BLEAdvertisementData oAdvertisementData = BLEAdvertisementData();
|
BLEAdvertisementData oAdvertisementData = BLEAdvertisementData();
|
||||||
|
@ -26,10 +26,11 @@ SOFTWARE.
|
|||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
|
|
||||||
#include <NimBLEDevice.h>
|
|
||||||
#include <NimBLEBeacon.h>
|
#include <NimBLEBeacon.h>
|
||||||
#include <main.hpp>
|
#include <NimBLEDevice.h>
|
||||||
|
|
||||||
#include <config.hpp>
|
#include <config.hpp>
|
||||||
|
#include <main.hpp>
|
||||||
|
|
||||||
class BleSender {
|
class BleSender {
|
||||||
private:
|
private:
|
||||||
@ -38,11 +39,9 @@ class BleSender {
|
|||||||
BLEUUID _uuid;
|
BLEUUID _uuid;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BleSender(const char* color);
|
explicit BleSender(const char* color);
|
||||||
void sendData(float tempF, float gravSG);
|
void sendData(float tempF, float gravSG);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ESP32
|
#endif // ESP32
|
||||||
#endif // SRC_BLE_HPP_
|
#endif // SRC_BLE_HPP_
|
||||||
|
|
||||||
// EOF
|
|
@ -300,10 +300,11 @@ bool Config::loadFile() {
|
|||||||
_formulaData.g[4] = doc[PARAM_FORMULA_DATA]["g5"].as<double>();
|
_formulaData.g[4] = doc[PARAM_FORMULA_DATA]["g5"].as<double>();
|
||||||
|
|
||||||
/*if( doc[PARAM_CONFIG_VER].isNull() ) {
|
/*if( doc[PARAM_CONFIG_VER].isNull() ) {
|
||||||
// If this parameter is missing we need to reset the gyrocalibaration due to bug #29
|
// If this parameter is missing we need to reset the gyrocalibaration due to
|
||||||
_gyroCalibration.ax = _gyroCalibration.ay = _gyroCalibration.az = 0;
|
bug #29 _gyroCalibration.ax = _gyroCalibration.ay = _gyroCalibration.az = 0;
|
||||||
_gyroCalibration.gx = _gyroCalibration.gy = _gyroCalibration.gz = 0;
|
_gyroCalibration.gx = _gyroCalibration.gy = _gyroCalibration.gz = 0;
|
||||||
Log.warning(F("CFG : Old configuration format, clearing gyro calibration." CR));
|
Log.warning(F("CFG : Old configuration format, clearing gyro calibration."
|
||||||
|
CR));
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
_saveNeeded = false; // Reset save flag
|
_saveNeeded = false; // Reset save flag
|
||||||
|
@ -360,7 +360,10 @@ class Config {
|
|||||||
}
|
}
|
||||||
bool isBLEActive() { return _colorBLE.length() ? true : false; }
|
bool isBLEActive() { return _colorBLE.length() ? true : false; }
|
||||||
bool isWifiPushActive() {
|
bool isWifiPushActive() {
|
||||||
return (isHttpActive() || isHttp2Active() || isHttp3Active() || isBrewfatherActive() || isInfluxDb2Active() || isMqttActive()) ? true : false;
|
return (isHttpActive() || isHttp2Active() || isHttp3Active() ||
|
||||||
|
isBrewfatherActive() || isInfluxDb2Active() || isMqttActive())
|
||||||
|
? true
|
||||||
|
: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RawGyroData& getGyroCalibration() { return _gyroCalibration; }
|
const RawGyroData& getGyroCalibration() { return _gyroCalibration; }
|
||||||
|
@ -197,8 +197,9 @@ float GyroSensor::calculateAngle(RawGyroData &raw) {
|
|||||||
|
|
||||||
// Source: https://www.nxp.com/docs/en/application-note/AN3461.pdf
|
// Source: https://www.nxp.com/docs/en/application-note/AN3461.pdf
|
||||||
float vY = (acos(abs(ay) / sqrt(ax * ax + ay * ay + az * az)) * 180.0 / PI);
|
float vY = (acos(abs(ay) / sqrt(ax * ax + ay * ay + az * az)) * 180.0 / PI);
|
||||||
//float vZ = (acos(abs(az) / sqrt(ax * ax + ay * ay + az * az)) * 180.0 / PI);
|
// float vZ = (acos(abs(az) / sqrt(ax * ax + ay * ay + az * az)) * 180.0 /
|
||||||
//float vX = (acos(abs(ax) / sqrt(ax * ax + ay * ay + az * az)) * 180.0 / PI);
|
// PI); float vX = (acos(abs(ax) / sqrt(ax * ax + ay * ay + az * az)) * 180.0
|
||||||
|
// / PI);
|
||||||
#if LOG_LEVEL == 6 && !defined(GYRO_DISABLE_LOGGING)
|
#if LOG_LEVEL == 6 && !defined(GYRO_DISABLE_LOGGING)
|
||||||
// Log.notice(F("GYRO: angleX= %F." CR), vX);
|
// Log.notice(F("GYRO: angleX= %F." CR), vX);
|
||||||
Log.notice(F("GYRO: angleY= %F." CR), vY);
|
Log.notice(F("GYRO: angleY= %F." CR), vY);
|
||||||
|
@ -51,8 +51,7 @@ void tcp_cleanup() {
|
|||||||
// Convert sg to plato
|
// Convert sg to plato
|
||||||
//
|
//
|
||||||
double convertToPlato(double sg) {
|
double convertToPlato(double sg) {
|
||||||
if (sg)
|
if (sg) return 259 - (259 / sg);
|
||||||
return 259 - (259 / sg);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,19 +357,24 @@ void PerfLogging::pushInflux() {
|
|||||||
myConfig.getMDNS(), myConfig.getID());
|
myConfig.getMDNS(), myConfig.getID());
|
||||||
body += &buf[0];
|
body += &buf[0];
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
snprintf(
|
snprintf(&buf[0], sizeof(buf),
|
||||||
&buf[0], sizeof(buf),
|
"angle=%.4f,gyro-ax=%d,gyro-ay=%d,gyro-az=%d,gyro-temp=%.2f,ds-temp="
|
||||||
"angle=%.4f,gyro-ax=%d,gyro-ay=%d,gyro-az=%d,gyro-temp=%.2f,ds-temp=%.2f,heap=%d,heap-frag=%d,heap-max=%d,stack=%d",
|
"%.2f,heap=%d,heap-frag=%d,heap-max=%d,stack=%d",
|
||||||
myGyro.getAngle(), myGyro.getLastGyroData().ax,
|
myGyro.getAngle(), myGyro.getLastGyroData().ax,
|
||||||
myGyro.getLastGyroData().ay, myGyro.getLastGyroData().az,
|
myGyro.getLastGyroData().ay, myGyro.getLastGyroData().az,
|
||||||
myGyro.getSensorTempC(), myTempSensor.getTempC(myConfig.isGyroTemp()), ESP.getFreeHeap(), ESP.getHeapFragmentation(), ESP.getMaxFreeBlockSize(), ESP.getFreeContStack());
|
myGyro.getSensorTempC(),
|
||||||
|
myTempSensor.getTempC(myConfig.isGyroTemp()), ESP.getFreeHeap(),
|
||||||
|
ESP.getHeapFragmentation(), ESP.getMaxFreeBlockSize(),
|
||||||
|
ESP.getFreeContStack());
|
||||||
#else // defined (ESP32)
|
#else // defined (ESP32)
|
||||||
snprintf(
|
snprintf(&buf[0], sizeof(buf),
|
||||||
&buf[0], sizeof(buf),
|
"angle=%.4f,gyro-ax=%d,gyro-ay=%d,gyro-az=%d,gyro-temp=%.2f,ds-temp="
|
||||||
"angle=%.4f,gyro-ax=%d,gyro-ay=%d,gyro-az=%d,gyro-temp=%.2f,ds-temp=%.2f,heap=%d,heap-frag=%d,heap-max=%d",
|
"%.2f,heap=%d,heap-frag=%d,heap-max=%d",
|
||||||
myGyro.getAngle(), myGyro.getLastGyroData().ax,
|
myGyro.getAngle(), myGyro.getLastGyroData().ax,
|
||||||
myGyro.getLastGyroData().ay, myGyro.getLastGyroData().az,
|
myGyro.getLastGyroData().ay, myGyro.getLastGyroData().az,
|
||||||
myGyro.getSensorTempC(), myTempSensor.getTempC(myConfig.isGyroTemp()), ESP.getFreeHeap(), 0, ESP.getMaxAllocHeap());
|
myGyro.getSensorTempC(),
|
||||||
|
myTempSensor.getTempC(myConfig.isGyroTemp()), ESP.getFreeHeap(), 0,
|
||||||
|
ESP.getMaxAllocHeap());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
body += &buf[0];
|
body += &buf[0];
|
||||||
|
16
src/main.cpp
16
src/main.cpp
@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
#include <ble.hpp>
|
||||||
#include <calc.hpp>
|
#include <calc.hpp>
|
||||||
#include <config.hpp>
|
#include <config.hpp>
|
||||||
#include <gyro.hpp>
|
#include <gyro.hpp>
|
||||||
@ -30,7 +31,6 @@ SOFTWARE.
|
|||||||
#include <tempsensor.hpp>
|
#include <tempsensor.hpp>
|
||||||
#include <webserver.hpp>
|
#include <webserver.hpp>
|
||||||
#include <wifi.hpp>
|
#include <wifi.hpp>
|
||||||
#include <ble.hpp>
|
|
||||||
|
|
||||||
// Define constats for this program
|
// Define constats for this program
|
||||||
#ifdef DEACTIVATE_SLEEPMODE
|
#ifdef DEACTIVATE_SLEEPMODE
|
||||||
@ -161,7 +161,8 @@ void setup() {
|
|||||||
runMode = RunMode::wifiSetupMode;
|
runMode = RunMode::wifiSetupMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool needWifi = true; // Under ESP32 we dont need wifi if only BLE is active in gravityMode
|
bool needWifi = true; // Under ESP32 we dont need wifi if only BLE is active
|
||||||
|
// in gravityMode
|
||||||
|
|
||||||
// Do this setup for all modes exect wifi setup
|
// Do this setup for all modes exect wifi setup
|
||||||
switch (runMode) {
|
switch (runMode) {
|
||||||
@ -185,7 +186,9 @@ void setup() {
|
|||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
if (!myConfig.isWifiPushActive() && runMode == RunMode::gravityMode) {
|
if (!myConfig.isWifiPushActive() && runMode == RunMode::gravityMode) {
|
||||||
Log.notice(F("Main: Wifi is not needed in gravity mode, skipping connection." CR));
|
Log.notice(
|
||||||
|
F("Main: Wifi is not needed in gravity mode, skipping "
|
||||||
|
"connection." CR));
|
||||||
needWifi = false;
|
needWifi = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -277,7 +280,8 @@ bool loopReadGravity() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (myWifi.isConnected()) { // no need to try if there is no wifi connection.
|
if (myWifi.isConnected()) { // no need to try if there is no wifi
|
||||||
|
// connection.
|
||||||
PushTarget push;
|
PushTarget push;
|
||||||
push.sendAll(angle, gravitySG, corrGravitySG, tempC,
|
push.sendAll(angle, gravitySG, corrGravitySG, tempC,
|
||||||
(millis() - runtimeMillis) / 1000);
|
(millis() - runtimeMillis) / 1000);
|
||||||
@ -356,7 +360,9 @@ void loop() {
|
|||||||
case RunMode::gravityMode:
|
case RunMode::gravityMode:
|
||||||
// If we didnt get a wifi connection, we enter sleep for a short time to
|
// If we didnt get a wifi connection, we enter sleep for a short time to
|
||||||
// conserve battery.
|
// conserve battery.
|
||||||
if (!myWifi.isConnected() && myConfig.isWifiPushActive()) { // no connection to wifi and we have defined push targets.
|
if (!myWifi.isConnected() &&
|
||||||
|
myConfig.isWifiPushActive()) { // no connection to wifi and we have
|
||||||
|
// defined push targets.
|
||||||
Log.notice(
|
Log.notice(
|
||||||
F("MAIN: No connection to wifi established, sleeping for 60s." CR));
|
F("MAIN: No connection to wifi established, sleeping for 60s." CR));
|
||||||
myWifi.stopDoubleReset();
|
myWifi.stopDoubleReset();
|
||||||
|
@ -111,12 +111,10 @@ void PushTarget::sendInfluxDb2(TemplatingEngine& engine) {
|
|||||||
|
|
||||||
if (_lastCode == 204) {
|
if (_lastCode == 204) {
|
||||||
_lastSuccess = true;
|
_lastSuccess = true;
|
||||||
Log.notice(F("PUSH: InfluxDB2 push successful, response=%d" CR),
|
Log.notice(F("PUSH: InfluxDB2 push successful, response=%d" CR), _lastCode);
|
||||||
_lastCode);
|
|
||||||
} else {
|
} else {
|
||||||
ErrorFileLog errLog;
|
ErrorFileLog errLog;
|
||||||
errLog.addEntry("PUSH: Influxdb push failed response=" +
|
errLog.addEntry("PUSH: Influxdb push failed response=" + String(_lastCode));
|
||||||
String(_lastCode));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_http.end();
|
_http.end();
|
||||||
@ -186,7 +184,8 @@ void PushTarget::addHttpHeader(HTTPClient& http, String header) {
|
|||||||
//
|
//
|
||||||
// Send data to http target using POST
|
// Send data to http target using POST
|
||||||
//
|
//
|
||||||
void PushTarget::sendHttpPost(TemplatingEngine& engine, bool isSecure, int index) {
|
void PushTarget::sendHttpPost(TemplatingEngine& engine, bool isSecure,
|
||||||
|
int index) {
|
||||||
#if !defined(PUSH_DISABLE_LOGGING)
|
#if !defined(PUSH_DISABLE_LOGGING)
|
||||||
Log.notice(F("PUSH: Sending values to http (%s)" CR),
|
Log.notice(F("PUSH: Sending values to http (%s)" CR),
|
||||||
index ? "http2" : "http");
|
index ? "http2" : "http");
|
||||||
@ -214,10 +213,11 @@ void PushTarget::sendHttpPost(TemplatingEngine& engine, bool isSecure, int index
|
|||||||
_wifiSecure.setInsecure();
|
_wifiSecure.setInsecure();
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
String host = serverPath.substring(8); // remove the prefix or the probe will fail, it needs a pure host name.
|
String host =
|
||||||
|
serverPath.substring(8); // remove the prefix or the probe will fail,
|
||||||
|
// it needs a pure host name.
|
||||||
int idx = host.indexOf("/");
|
int idx = host.indexOf("/");
|
||||||
if (idx!=-1)
|
if (idx != -1) host = host.substring(0, idx);
|
||||||
host = host.substring(0, idx);
|
|
||||||
|
|
||||||
if (_wifiSecure.probeMaxFragmentLength(host, 443, 512)) {
|
if (_wifiSecure.probeMaxFragmentLength(host, 443, 512)) {
|
||||||
Log.notice(F("PUSH: HTTP server supports smaller SSL buffer." CR));
|
Log.notice(F("PUSH: HTTP server supports smaller SSL buffer." CR));
|
||||||
@ -254,12 +254,10 @@ void PushTarget::sendHttpPost(TemplatingEngine& engine, bool isSecure, int index
|
|||||||
|
|
||||||
if (_lastCode == 200) {
|
if (_lastCode == 200) {
|
||||||
_lastSuccess = true;
|
_lastSuccess = true;
|
||||||
Log.notice(F("PUSH: HTTP post successful, response=%d" CR),
|
Log.notice(F("PUSH: HTTP post successful, response=%d" CR), _lastCode);
|
||||||
_lastCode);
|
|
||||||
} else {
|
} else {
|
||||||
ErrorFileLog errLog;
|
ErrorFileLog errLog;
|
||||||
errLog.addEntry(
|
errLog.addEntry("PUSH: HTTP post failed response=" + String(_lastCode) +
|
||||||
"PUSH: HTTP post failed response=" + String(_lastCode) +
|
|
||||||
String(index == 0 ? " (http)" : " (http2)"));
|
String(index == 0 ? " (http)" : " (http2)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,10 +295,11 @@ void PushTarget::sendHttpGet(TemplatingEngine& engine, bool isSecure) {
|
|||||||
_wifiSecure.setInsecure();
|
_wifiSecure.setInsecure();
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
String host = serverPath.substring(8); // remove the prefix or the probe will fail, it needs a pure host name.
|
String host =
|
||||||
|
serverPath.substring(8); // remove the prefix or the probe will fail,
|
||||||
|
// it needs a pure host name.
|
||||||
int idx = host.indexOf("/");
|
int idx = host.indexOf("/");
|
||||||
if (idx!=-1)
|
if (idx != -1) host = host.substring(0, idx);
|
||||||
host = host.substring(0, idx);
|
|
||||||
|
|
||||||
if (_wifiSecure.probeMaxFragmentLength(host, 443, 512)) {
|
if (_wifiSecure.probeMaxFragmentLength(host, 443, 512)) {
|
||||||
Log.notice(F("PUSH: HTTP server supports smaller SSL buffer." CR));
|
Log.notice(F("PUSH: HTTP server supports smaller SSL buffer." CR));
|
||||||
@ -319,12 +318,10 @@ void PushTarget::sendHttpGet(TemplatingEngine& engine, bool isSecure) {
|
|||||||
|
|
||||||
if (_lastCode == 200) {
|
if (_lastCode == 200) {
|
||||||
_lastSuccess = true;
|
_lastSuccess = true;
|
||||||
Log.notice(F("PUSH: HTTP get successful, response=%d" CR),
|
Log.notice(F("PUSH: HTTP get successful, response=%d" CR), _lastCode);
|
||||||
_lastCode);
|
|
||||||
} else {
|
} else {
|
||||||
ErrorFileLog errLog;
|
ErrorFileLog errLog;
|
||||||
errLog.addEntry(
|
errLog.addEntry("PUSH: HTTP get failed response=" + String(_lastCode));
|
||||||
"PUSH: HTTP get failed response=" + String(_lastCode));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSecure) {
|
if (isSecure) {
|
||||||
|
@ -51,9 +51,15 @@ class PushTarget {
|
|||||||
float runTime);
|
float runTime);
|
||||||
|
|
||||||
void sendBrewfather(TemplatingEngine& engine);
|
void sendBrewfather(TemplatingEngine& engine);
|
||||||
void sendHttp1(TemplatingEngine& engine, bool isSecure) { sendHttpPost(engine, isSecure, 0); }
|
void sendHttp1(TemplatingEngine& engine, bool isSecure) {
|
||||||
void sendHttp2(TemplatingEngine& engine, bool isSecure) { sendHttpPost(engine, isSecure, 1); }
|
sendHttpPost(engine, isSecure, 0);
|
||||||
void sendHttp3(TemplatingEngine& engine, bool isSecure) { sendHttpGet(engine, isSecure); }
|
}
|
||||||
|
void sendHttp2(TemplatingEngine& engine, bool isSecure) {
|
||||||
|
sendHttpPost(engine, isSecure, 1);
|
||||||
|
}
|
||||||
|
void sendHttp3(TemplatingEngine& engine, bool isSecure) {
|
||||||
|
sendHttpGet(engine, isSecure);
|
||||||
|
}
|
||||||
void sendInfluxDb2(TemplatingEngine& engine);
|
void sendInfluxDb2(TemplatingEngine& engine);
|
||||||
void sendMqtt(TemplatingEngine& engine, bool isSecure);
|
void sendMqtt(TemplatingEngine& engine, bool isSecure);
|
||||||
int getLastCode() { return _lastCode; }
|
int getLastCode() { return _lastCode; }
|
||||||
|
@ -42,5 +42,4 @@ INCBIN(UploadHtm, "data/upload.min.htm");
|
|||||||
#endif
|
#endif
|
||||||
INCBIN(FirmwareHtm, "data/firmware.min.htm");
|
INCBIN(FirmwareHtm, "data/firmware.min.htm");
|
||||||
|
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
|
@ -21,8 +21,8 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <templating.hpp>
|
|
||||||
#include <config.hpp>
|
#include <config.hpp>
|
||||||
|
#include <templating.hpp>
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
@ -83,8 +83,10 @@ const char brewfatherFormat[] PROGMEM =
|
|||||||
"}";
|
"}";
|
||||||
|
|
||||||
const char influxDbFormat[] PROGMEM =
|
const char influxDbFormat[] PROGMEM =
|
||||||
"measurement,host=${mdns},device=${id},temp-format=${temp-unit},gravity-format=${gravity-unit} "
|
"measurement,host=${mdns},device=${id},temp-format=${temp-unit},gravity-"
|
||||||
"gravity=${gravity},corr-gravity=${corr-gravity},angle=${angle},temp=${temp},battery=${battery},"
|
"format=${gravity-unit} "
|
||||||
|
"gravity=${gravity},corr-gravity=${corr-gravity},angle=${angle},temp=${"
|
||||||
|
"temp},battery=${battery},"
|
||||||
"rssi=${rssi}\n";
|
"rssi=${rssi}\n";
|
||||||
|
|
||||||
const char mqttFormat[] PROGMEM =
|
const char mqttFormat[] PROGMEM =
|
||||||
@ -99,8 +101,9 @@ const char mqttFormat[] PROGMEM =
|
|||||||
//
|
//
|
||||||
// Initialize the variables
|
// Initialize the variables
|
||||||
//
|
//
|
||||||
void TemplatingEngine::initialize(float angle, float gravitySG, float corrGravitySG, float tempC, float runTime) {
|
void TemplatingEngine::initialize(float angle, float gravitySG,
|
||||||
|
float corrGravitySG, float tempC,
|
||||||
|
float runTime) {
|
||||||
// Names
|
// Names
|
||||||
setVal(TPL_MDNS, myConfig.getMDNS());
|
setVal(TPL_MDNS, myConfig.getMDNS());
|
||||||
setVal(TPL_ID, myConfig.getID());
|
setVal(TPL_ID, myConfig.getID());
|
||||||
@ -134,8 +137,7 @@ void TemplatingEngine::initialize(float angle, float gravitySG, float corrGravit
|
|||||||
if (myConfig.isGravitySG()) {
|
if (myConfig.isGravitySG()) {
|
||||||
setVal(TPL_GRAVITY, gravitySG, 4);
|
setVal(TPL_GRAVITY, gravitySG, 4);
|
||||||
setVal(TPL_GRAVITY_CORR, corrGravitySG, 4);
|
setVal(TPL_GRAVITY_CORR, corrGravitySG, 4);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
setVal(TPL_GRAVITY, convertToPlato(gravitySG), 1);
|
setVal(TPL_GRAVITY, convertToPlato(gravitySG), 1);
|
||||||
setVal(TPL_GRAVITY_CORR, convertToPlato(corrGravitySG), 1);
|
setVal(TPL_GRAVITY_CORR, convertToPlato(corrGravitySG), 1);
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,10 @@ SOFTWARE.
|
|||||||
#include <gyro.hpp>
|
#include <gyro.hpp>
|
||||||
#include <helper.hpp>
|
#include <helper.hpp>
|
||||||
#include <main.hpp>
|
#include <main.hpp>
|
||||||
|
#include <pushtarget.hpp>
|
||||||
#include <resources.hpp>
|
#include <resources.hpp>
|
||||||
#include <templating.hpp>
|
#include <templating.hpp>
|
||||||
#include <tempsensor.hpp>
|
#include <tempsensor.hpp>
|
||||||
#include <pushtarget.hpp>
|
|
||||||
#include <webserver.hpp>
|
#include <webserver.hpp>
|
||||||
#include <wifi.hpp>
|
#include <wifi.hpp>
|
||||||
|
|
||||||
@ -51,8 +51,7 @@ void WebServerHandler::webHandleConfig() {
|
|||||||
|
|
||||||
double angle = 0;
|
double angle = 0;
|
||||||
|
|
||||||
if (myGyro.hasValue())
|
if (myGyro.hasValue()) angle = myGyro.getAngle();
|
||||||
angle = myGyro.getAngle();
|
|
||||||
|
|
||||||
double tempC = myTempSensor.getTempC(myConfig.isGyroTemp());
|
double tempC = myTempSensor.getTempC(myConfig.isGyroTemp());
|
||||||
double gravity = calculateGravity(angle, tempC);
|
double gravity = calculateGravity(angle, tempC);
|
||||||
@ -62,7 +61,8 @@ void WebServerHandler::webHandleConfig() {
|
|||||||
|
|
||||||
// Format the adjustment so we get rid of rounding errors
|
// Format the adjustment so we get rid of rounding errors
|
||||||
if (myConfig.isTempF())
|
if (myConfig.isTempF())
|
||||||
doc[PARAM_TEMP_ADJ] = reduceFloatPrecision(convertCtoF(myConfig.getTempSensorAdjC()), 1);
|
doc[PARAM_TEMP_ADJ] =
|
||||||
|
reduceFloatPrecision(convertCtoF(myConfig.getTempSensorAdjC()), 1);
|
||||||
else
|
else
|
||||||
doc[PARAM_TEMP_ADJ] = reduceFloatPrecision(myConfig.getTempSensorAdjC(), 1);
|
doc[PARAM_TEMP_ADJ] = reduceFloatPrecision(myConfig.getTempSensorAdjC(), 1);
|
||||||
|
|
||||||
@ -188,31 +188,38 @@ void WebServerHandler::webHandleUploadFile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if LOG_LEVEL == 6 && !defined(WEB_DISABLE_LOGGING)
|
#if LOG_LEVEL == 6 && !defined(WEB_DISABLE_LOGGING)
|
||||||
Log.verbose(F("WEB : webServer callback for /api/upload, receiving file %s, %d(%d) "
|
Log.verbose(
|
||||||
|
F("WEB : webServer callback for /api/upload, receiving file %s, %d(%d) "
|
||||||
"valid=%s, firmware=%s." CR),
|
"valid=%s, firmware=%s." CR),
|
||||||
f.c_str(), upload.currentSize, upload.totalSize, validFilename ? "yes" : "no", firmware ? "yes" : "no");
|
f.c_str(), upload.currentSize, upload.totalSize,
|
||||||
|
validFilename ? "yes" : "no", firmware ? "yes" : "no");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (firmware) {
|
if (firmware) {
|
||||||
// Handle firmware update
|
// Handle firmware update, hardcode since function return wrong value.
|
||||||
uint32_t maxSketchSpace = 1044464; //(ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
uint32_t maxSketchSpace =
|
||||||
|
1044464; // (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||||
|
|
||||||
if (upload.status == UPLOAD_FILE_START) {
|
if (upload.status == UPLOAD_FILE_START) {
|
||||||
_uploadReturn = 200;
|
_uploadReturn = 200;
|
||||||
Log.notice(F("WEB : Start firmware upload, max sketch size %d kb." CR), maxSketchSpace/1024);
|
Log.notice(F("WEB : Start firmware upload, max sketch size %d kb." CR),
|
||||||
|
maxSketchSpace / 1024);
|
||||||
|
|
||||||
if (!Update.begin(maxSketchSpace, U_FLASH, PIN_LED)) {
|
if (!Update.begin(maxSketchSpace, U_FLASH, PIN_LED)) {
|
||||||
ErrorFileLog errLog;
|
ErrorFileLog errLog;
|
||||||
errLog.addEntry(F("WEB : Not enough space to store for this firmware."));
|
errLog.addEntry(
|
||||||
|
F("WEB : Not enough space to store for this firmware."));
|
||||||
_uploadReturn = 500;
|
_uploadReturn = 500;
|
||||||
}
|
}
|
||||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||||
Log.notice(F("WEB : Writing firmware upload %d (%d)." CR), upload.totalSize, maxSketchSpace);
|
Log.notice(F("WEB : Writing firmware upload %d (%d)." CR),
|
||||||
|
upload.totalSize, maxSketchSpace);
|
||||||
|
|
||||||
if (upload.totalSize > maxSketchSpace) {
|
if (upload.totalSize > maxSketchSpace) {
|
||||||
Log.error(F("WEB : Firmware file is to large." CR));
|
Log.error(F("WEB : Firmware file is to large." CR));
|
||||||
_uploadReturn = 500;
|
_uploadReturn = 500;
|
||||||
} else if (Update.write(upload.buf, upload.currentSize) != upload.currentSize){
|
} else if (Update.write(upload.buf, upload.currentSize) !=
|
||||||
|
upload.currentSize) {
|
||||||
Log.warning(F("WEB : Firmware write was unsuccessful." CR));
|
Log.warning(F("WEB : Firmware write was unsuccessful." CR));
|
||||||
_uploadReturn = 500;
|
_uploadReturn = 500;
|
||||||
}
|
}
|
||||||
@ -224,7 +231,8 @@ void WebServerHandler::webHandleUploadFile() {
|
|||||||
ESP_RESET();
|
ESP_RESET();
|
||||||
} else {
|
} else {
|
||||||
ErrorFileLog errLog;
|
ErrorFileLog errLog;
|
||||||
errLog.addEntry(F("WEB : Failed to finish firmware flashing error=") + String(Update.getError()));
|
errLog.addEntry(F("WEB : Failed to finish firmware flashing error=") +
|
||||||
|
String(Update.getError()));
|
||||||
_uploadReturn = 500;
|
_uploadReturn = 500;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -244,15 +252,13 @@ void WebServerHandler::webHandleUploadFile() {
|
|||||||
if (validFilename) _uploadFile = LittleFS.open(f, "w");
|
if (validFilename) _uploadFile = LittleFS.open(f, "w");
|
||||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||||
Log.notice(F("WEB : Writing html upload." CR));
|
Log.notice(F("WEB : Writing html upload." CR));
|
||||||
if (_uploadFile)
|
if (_uploadFile) _uploadFile.write(upload.buf, upload.currentSize);
|
||||||
_uploadFile.write(
|
|
||||||
upload.buf,
|
|
||||||
upload.currentSize);
|
|
||||||
} else if (upload.status == UPLOAD_FILE_END) {
|
} else if (upload.status == UPLOAD_FILE_END) {
|
||||||
Log.notice(F("WEB : Finish html upload." CR));
|
Log.notice(F("WEB : Finish html upload." CR));
|
||||||
if (_uploadFile) {
|
if (_uploadFile) {
|
||||||
_uploadFile.close();
|
_uploadFile.close();
|
||||||
Log.notice(F("WEB : Html file uploaded %d bytes." CR), upload.totalSize);
|
Log.notice(F("WEB : Html file uploaded %d bytes." CR),
|
||||||
|
upload.totalSize);
|
||||||
}
|
}
|
||||||
_server->sendHeader("Location", "/");
|
_server->sendHeader("Location", "/");
|
||||||
_server->send(303);
|
_server->send(303);
|
||||||
@ -321,8 +327,7 @@ void WebServerHandler::webHandleStatus() {
|
|||||||
|
|
||||||
double angle = 0;
|
double angle = 0;
|
||||||
|
|
||||||
if (myGyro.hasValue())
|
if (myGyro.hasValue()) angle = myGyro.getAngle();
|
||||||
angle = myGyro.getAngle();
|
|
||||||
|
|
||||||
double tempC = myTempSensor.getTempC(myConfig.isGyroTemp());
|
double tempC = myTempSensor.getTempC(myConfig.isGyroTemp());
|
||||||
double gravity = calculateGravity(angle, tempC);
|
double gravity = calculateGravity(angle, tempC);
|
||||||
@ -833,7 +838,8 @@ void WebServerHandler::webHandleTestPush() {
|
|||||||
PushTarget push;
|
PushTarget push;
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
|
|
||||||
if (!type.compareTo(PARAM_FORMAT_BREWFATHER) && myConfig.isBrewfatherActive()) {
|
if (!type.compareTo(PARAM_FORMAT_BREWFATHER) &&
|
||||||
|
myConfig.isBrewfatherActive()) {
|
||||||
push.sendBrewfather(engine);
|
push.sendBrewfather(engine);
|
||||||
enabled = true;
|
enabled = true;
|
||||||
} else if (!type.compareTo(PARAM_FORMAT_HTTP1) && myConfig.isHttpActive()) {
|
} else if (!type.compareTo(PARAM_FORMAT_HTTP1) && myConfig.isHttpActive()) {
|
||||||
@ -845,7 +851,8 @@ void WebServerHandler::webHandleTestPush() {
|
|||||||
} else if (!type.compareTo(PARAM_FORMAT_HTTP3) && myConfig.isHttp3Active()) {
|
} else if (!type.compareTo(PARAM_FORMAT_HTTP3) && myConfig.isHttp3Active()) {
|
||||||
push.sendHttp3(engine, myConfig.isHttp3SSL());
|
push.sendHttp3(engine, myConfig.isHttp3SSL());
|
||||||
enabled = true;
|
enabled = true;
|
||||||
} else if (!type.compareTo(PARAM_FORMAT_INFLUXDB) && myConfig.isInfluxDb2Active()) {
|
} else if (!type.compareTo(PARAM_FORMAT_INFLUXDB) &&
|
||||||
|
myConfig.isInfluxDb2Active()) {
|
||||||
push.sendInfluxDb2(engine);
|
push.sendInfluxDb2(engine);
|
||||||
enabled = true;
|
enabled = true;
|
||||||
} else if (!type.compareTo(PARAM_FORMAT_MQTT) && myConfig.isMqttActive()) {
|
} else if (!type.compareTo(PARAM_FORMAT_MQTT) && myConfig.isMqttActive()) {
|
||||||
|
@ -29,9 +29,9 @@ SOFTWARE.
|
|||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266mDNS.h>
|
#include <ESP8266mDNS.h>
|
||||||
#else // defined (ESP32)
|
#else // defined (ESP32)
|
||||||
|
#include <ESPmDNS.h>
|
||||||
#include <WebServer.h>
|
#include <WebServer.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <ESPmDNS.h>
|
|
||||||
#endif
|
#endif
|
||||||
#include <incbin.h>
|
#include <incbin.h>
|
||||||
|
|
||||||
@ -103,8 +103,7 @@ class WebServerHandler {
|
|||||||
gAboutHtmSize);
|
gAboutHtmSize);
|
||||||
}
|
}
|
||||||
void webReturnTestHtm() {
|
void webReturnTestHtm() {
|
||||||
_server->send_P(200, "text/html", (const char*)gTestHtmData,
|
_server->send_P(200, "text/html", (const char*)gTestHtmData, gTestHtmSize);
|
||||||
gTestHtmSize);
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void webReturnUploadHtm() {
|
void webReturnUploadHtm() {
|
||||||
|
@ -364,7 +364,8 @@ bool WifiConnection::checkFirmwareVersion() {
|
|||||||
|
|
||||||
// Download new html files to filesystem if they are present.
|
// 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 checking if html files should be downloaded." CR));
|
Log.notice(
|
||||||
|
F("WIFI: OTA checking if html files should be downloaded." CR));
|
||||||
JsonArray htmlFiles = ver["html"].as<JsonArray>();
|
JsonArray htmlFiles = ver["html"].as<JsonArray>();
|
||||||
for (JsonVariant v : htmlFiles) {
|
for (JsonVariant v : htmlFiles) {
|
||||||
String s = v;
|
String s = v;
|
||||||
|
Loading…
Reference in New Issue
Block a user