pre-commit updates
This commit is contained in:
parent
2d67a44ad0
commit
c779a45ea9
15
src/ble.cpp
15
src/ble.cpp
@ -24,6 +24,7 @@ SOFTWARE.
|
||||
#if defined(ESP32)
|
||||
|
||||
#include <ble.hpp>
|
||||
#include <string>
|
||||
|
||||
// Tilt UUID variants and data format, based on tilt-sim
|
||||
//
|
||||
@ -38,10 +39,11 @@ SOFTWARE.
|
||||
BleSender::BleSender(const char* color) {
|
||||
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_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);
|
||||
|
||||
_advertising = BLEDevice::getAdvertising();
|
||||
_color = color;
|
||||
@ -68,17 +70,18 @@ BleSender::BleSender(const char* color) {
|
||||
// Send temp and gravity via BLE
|
||||
//
|
||||
void BleSender::sendData(float tempF, float gravSG) {
|
||||
uint16_t gravity = gravSG*1000; // SG * 1000 or SG * 10000 for Tilt Pro/HD
|
||||
uint16_t gravity = gravSG * 1000; // SG * 1000 or SG * 10000 for Tilt Pro/HD
|
||||
uint16_t temperature = tempF; // Deg F _or_ Deg F * 10 for Tilt Pro/HD
|
||||
|
||||
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.setMajor(temperature);
|
||||
oBeacon.setMinor(gravity);
|
||||
std::string strServiceData = "";
|
||||
strServiceData += (char)26; // Len
|
||||
strServiceData += (char)0xFF; // Type
|
||||
strServiceData += static_cast<char>(26); // Len
|
||||
strServiceData += static_cast<char>(0xFF); // Type
|
||||
strServiceData += oBeacon.getData();
|
||||
|
||||
BLEAdvertisementData oAdvertisementData = BLEAdvertisementData();
|
||||
|
13
src/ble.hpp
13
src/ble.hpp
@ -24,25 +24,24 @@ SOFTWARE.
|
||||
#ifndef SRC_BLE_HPP_
|
||||
#define SRC_BLE_HPP_
|
||||
|
||||
#if defined (ESP32)
|
||||
#if defined(ESP32)
|
||||
|
||||
#include <NimBLEDevice.h>
|
||||
#include <NimBLEBeacon.h>
|
||||
#include <main.hpp>
|
||||
#include <NimBLEDevice.h>
|
||||
|
||||
#include <config.hpp>
|
||||
#include <main.hpp>
|
||||
|
||||
class BleSender {
|
||||
private:
|
||||
BLEAdvertising *_advertising;
|
||||
BLEAdvertising* _advertising;
|
||||
String _color;
|
||||
BLEUUID _uuid;
|
||||
|
||||
public:
|
||||
BleSender(const char* color);
|
||||
explicit BleSender(const char* color);
|
||||
void sendData(float tempF, float gravSG);
|
||||
};
|
||||
|
||||
#endif // ESP32
|
||||
#endif // SRC_BLE_HPP_
|
||||
|
||||
// EOF
|
@ -65,7 +65,7 @@ Config::Config() {
|
||||
//
|
||||
void Config::createJson(DynamicJsonDocument& doc) {
|
||||
doc[PARAM_MDNS] = getMDNS();
|
||||
//doc[PARAM_CONFIG_VER] = getConfigVersion();
|
||||
// doc[PARAM_CONFIG_VER] = getConfigVersion();
|
||||
doc[PARAM_ID] = getID();
|
||||
doc[PARAM_OTA] = getOtaURL();
|
||||
doc[PARAM_SSID] = getWifiSSID();
|
||||
@ -300,10 +300,11 @@ bool Config::loadFile() {
|
||||
_formulaData.g[4] = doc[PARAM_FORMULA_DATA]["g5"].as<double>();
|
||||
|
||||
/*if( doc[PARAM_CONFIG_VER].isNull() ) {
|
||||
// If this parameter is missing we need to reset the gyrocalibaration due to bug #29
|
||||
_gyroCalibration.ax = _gyroCalibration.ay = _gyroCalibration.az = 0;
|
||||
// If this parameter is missing we need to reset the gyrocalibaration due to
|
||||
bug #29 _gyroCalibration.ax = _gyroCalibration.ay = _gyroCalibration.az = 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
|
||||
|
@ -360,7 +360,10 @@ class Config {
|
||||
}
|
||||
bool isBLEActive() { return _colorBLE.length() ? true : false; }
|
||||
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; }
|
||||
|
@ -197,12 +197,13 @@ float GyroSensor::calculateAngle(RawGyroData &raw) {
|
||||
|
||||
// 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 vZ = (acos(abs(az) / sqrt(ax * ax + ay * ay + az * az)) * 180.0 / PI);
|
||||
//float vX = (acos(abs(ax) / 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 vX = (acos(abs(ax) / sqrt(ax * ax + ay * ay + az * az)) * 180.0
|
||||
// / PI);
|
||||
#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: angleZ= %F." CR), vZ);
|
||||
// Log.notice(F("GYRO: angleZ= %F." CR), vZ);
|
||||
#endif
|
||||
return vY;
|
||||
}
|
||||
|
@ -51,8 +51,7 @@ void tcp_cleanup() {
|
||||
// Convert sg to plato
|
||||
//
|
||||
double convertToPlato(double sg) {
|
||||
if (sg)
|
||||
return 259 - (259 / sg);
|
||||
if (sg) return 259 - (259 / sg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -357,20 +356,25 @@ void PerfLogging::pushInflux() {
|
||||
snprintf(&buf[0], sizeof(buf), "\ndebug,host=%s,device=%s ",
|
||||
myConfig.getMDNS(), myConfig.getID());
|
||||
body += &buf[0];
|
||||
#if defined (ESP8266)
|
||||
snprintf(
|
||||
&buf[0], sizeof(buf),
|
||||
"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",
|
||||
#if defined(ESP8266)
|
||||
snprintf(&buf[0], sizeof(buf),
|
||||
"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",
|
||||
myGyro.getAngle(), myGyro.getLastGyroData().ax,
|
||||
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)
|
||||
snprintf(
|
||||
&buf[0], sizeof(buf),
|
||||
"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",
|
||||
snprintf(&buf[0], sizeof(buf),
|
||||
"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",
|
||||
myGyro.getAngle(), myGyro.getLastGyroData().ax,
|
||||
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
|
||||
|
||||
body += &buf[0];
|
||||
@ -429,7 +433,7 @@ float reduceFloatPrecision(float f, int dec) {
|
||||
//
|
||||
String urlencode(String str) {
|
||||
String encodedString;
|
||||
encodedString.reserve(str.length()*2);
|
||||
encodedString.reserve(str.length() * 2);
|
||||
encodedString = "";
|
||||
char c;
|
||||
char code0;
|
||||
|
22
src/main.cpp
22
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
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include <ble.hpp>
|
||||
#include <calc.hpp>
|
||||
#include <config.hpp>
|
||||
#include <gyro.hpp>
|
||||
@ -30,7 +31,6 @@ SOFTWARE.
|
||||
#include <tempsensor.hpp>
|
||||
#include <webserver.hpp>
|
||||
#include <wifi.hpp>
|
||||
#include <ble.hpp>
|
||||
|
||||
// Define constats for this program
|
||||
#ifdef DEACTIVATE_SLEEPMODE
|
||||
@ -161,7 +161,8 @@ void setup() {
|
||||
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
|
||||
switch (runMode) {
|
||||
@ -183,9 +184,11 @@ void setup() {
|
||||
myBatteryVoltage.read();
|
||||
checkSleepMode(myGyro.getAngle(), myBatteryVoltage.getVoltage());
|
||||
|
||||
#if defined (ESP32)
|
||||
#if defined(ESP32)
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
@ -269,15 +272,16 @@ bool loopReadGravity() {
|
||||
pushMillis = millis();
|
||||
LOG_PERF_START("loop-push");
|
||||
|
||||
#if defined (ESP32)
|
||||
#if defined(ESP32)
|
||||
if (myConfig.isBLEActive()) {
|
||||
BleSender ble(myConfig.getColorBLE());
|
||||
ble.sendData( convertCtoF(tempC), gravitySG);
|
||||
ble.sendData(convertCtoF(tempC), gravitySG);
|
||||
Log.notice(F("MAIN: Broadcast data over bluetooth." CR));
|
||||
}
|
||||
#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;
|
||||
push.sendAll(angle, gravitySG, corrGravitySG, tempC,
|
||||
(millis() - runtimeMillis) / 1000);
|
||||
@ -356,7 +360,9 @@ void loop() {
|
||||
case RunMode::gravityMode:
|
||||
// If we didnt get a wifi connection, we enter sleep for a short time to
|
||||
// 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(
|
||||
F("MAIN: No connection to wifi established, sleeping for 60s." CR));
|
||||
myWifi.stopDoubleReset();
|
||||
|
@ -29,16 +29,16 @@ SOFTWARE.
|
||||
#include <ArduinoLog.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined (ESP8266)
|
||||
#if defined(ESP8266)
|
||||
#include <LittleFS.h>
|
||||
#define ESP_RESET ESP.reset
|
||||
#define PIN_SDA D3
|
||||
#define PIN_SCL D4
|
||||
#define PIN_DS D6
|
||||
#define PIN_LED 2
|
||||
//#define PIN_A0 A0
|
||||
// #define PIN_A0 A0
|
||||
#else // defined (ESP32)
|
||||
#if defined (ESPRESSIF32_20)
|
||||
#if defined(ESPRESSIF32_20)
|
||||
#include <LittleFS.h>
|
||||
#else
|
||||
#include <LITTLEFS.h>
|
||||
|
@ -111,12 +111,10 @@ void PushTarget::sendInfluxDb2(TemplatingEngine& engine) {
|
||||
|
||||
if (_lastCode == 204) {
|
||||
_lastSuccess = true;
|
||||
Log.notice(F("PUSH: InfluxDB2 push successful, response=%d" CR),
|
||||
_lastCode);
|
||||
Log.notice(F("PUSH: InfluxDB2 push successful, response=%d" CR), _lastCode);
|
||||
} else {
|
||||
ErrorFileLog errLog;
|
||||
errLog.addEntry("PUSH: Influxdb push failed response=" +
|
||||
String(_lastCode));
|
||||
errLog.addEntry("PUSH: Influxdb push failed response=" + String(_lastCode));
|
||||
}
|
||||
|
||||
_http.end();
|
||||
@ -186,7 +184,8 @@ void PushTarget::addHttpHeader(HTTPClient& http, String header) {
|
||||
//
|
||||
// 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)
|
||||
Log.notice(F("PUSH: Sending values to http (%s)" CR),
|
||||
index ? "http2" : "http");
|
||||
@ -213,11 +212,12 @@ void PushTarget::sendHttpPost(TemplatingEngine& engine, bool isSecure, int index
|
||||
Log.notice(F("PUSH: HTTP, SSL enabled without validation." CR));
|
||||
_wifiSecure.setInsecure();
|
||||
|
||||
#if defined (ESP8266)
|
||||
String host = serverPath.substring(8); // remove the prefix or the probe will fail, it needs a pure host name.
|
||||
#if defined(ESP8266)
|
||||
String host =
|
||||
serverPath.substring(8); // remove the prefix or the probe will fail,
|
||||
// it needs a pure host name.
|
||||
int idx = host.indexOf("/");
|
||||
if (idx!=-1)
|
||||
host = host.substring(0, idx);
|
||||
if (idx != -1) host = host.substring(0, idx);
|
||||
|
||||
if (_wifiSecure.probeMaxFragmentLength(host, 443, 512)) {
|
||||
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) {
|
||||
_lastSuccess = true;
|
||||
Log.notice(F("PUSH: HTTP post successful, response=%d" CR),
|
||||
_lastCode);
|
||||
Log.notice(F("PUSH: HTTP post successful, response=%d" CR), _lastCode);
|
||||
} else {
|
||||
ErrorFileLog errLog;
|
||||
errLog.addEntry(
|
||||
"PUSH: HTTP post failed response=" + String(_lastCode) +
|
||||
errLog.addEntry("PUSH: HTTP post failed response=" + String(_lastCode) +
|
||||
String(index == 0 ? " (http)" : " (http2)"));
|
||||
}
|
||||
|
||||
@ -296,11 +294,12 @@ void PushTarget::sendHttpGet(TemplatingEngine& engine, bool isSecure) {
|
||||
Log.notice(F("PUSH: HTTP, SSL enabled without validation." CR));
|
||||
_wifiSecure.setInsecure();
|
||||
|
||||
#if defined (ESP8266)
|
||||
String host = serverPath.substring(8); // remove the prefix or the probe will fail, it needs a pure host name.
|
||||
#if defined(ESP8266)
|
||||
String host =
|
||||
serverPath.substring(8); // remove the prefix or the probe will fail,
|
||||
// it needs a pure host name.
|
||||
int idx = host.indexOf("/");
|
||||
if (idx!=-1)
|
||||
host = host.substring(0, idx);
|
||||
if (idx != -1) host = host.substring(0, idx);
|
||||
|
||||
if (_wifiSecure.probeMaxFragmentLength(host, 443, 512)) {
|
||||
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) {
|
||||
_lastSuccess = true;
|
||||
Log.notice(F("PUSH: HTTP get successful, response=%d" CR),
|
||||
_lastCode);
|
||||
Log.notice(F("PUSH: HTTP get successful, response=%d" CR), _lastCode);
|
||||
} else {
|
||||
ErrorFileLog errLog;
|
||||
errLog.addEntry(
|
||||
"PUSH: HTTP get failed response=" + String(_lastCode));
|
||||
errLog.addEntry("PUSH: HTTP get failed response=" + String(_lastCode));
|
||||
}
|
||||
|
||||
if (isSecure) {
|
||||
@ -356,7 +353,7 @@ void PushTarget::sendMqtt(TemplatingEngine& engine, bool isSecure) {
|
||||
Log.notice(F("PUSH: MQTT, SSL enabled without validation." CR));
|
||||
_wifiSecure.setInsecure();
|
||||
|
||||
#if defined (ESP8266)
|
||||
#if defined(ESP8266)
|
||||
if (_wifiSecure.probeMaxFragmentLength(host, port, 512)) {
|
||||
Log.notice(F("PUSH: MQTT server supports smaller SSL buffer." CR));
|
||||
_wifiSecure.setBufferSizes(512, 512);
|
||||
|
@ -51,9 +51,15 @@ class PushTarget {
|
||||
float runTime);
|
||||
|
||||
void sendBrewfather(TemplatingEngine& engine);
|
||||
void sendHttp1(TemplatingEngine& engine, bool isSecure) { sendHttpPost(engine, isSecure, 0); }
|
||||
void sendHttp2(TemplatingEngine& engine, bool isSecure) { sendHttpPost(engine, isSecure, 1); }
|
||||
void sendHttp3(TemplatingEngine& engine, bool isSecure) { sendHttpGet(engine, isSecure); }
|
||||
void sendHttp1(TemplatingEngine& engine, bool isSecure) {
|
||||
sendHttpPost(engine, isSecure, 0);
|
||||
}
|
||||
void sendHttp2(TemplatingEngine& engine, bool isSecure) {
|
||||
sendHttpPost(engine, isSecure, 1);
|
||||
}
|
||||
void sendHttp3(TemplatingEngine& engine, bool isSecure) {
|
||||
sendHttpGet(engine, isSecure);
|
||||
}
|
||||
void sendInfluxDb2(TemplatingEngine& engine);
|
||||
void sendMqtt(TemplatingEngine& engine, bool isSecure);
|
||||
int getLastCode() { return _lastCode; }
|
||||
|
@ -21,7 +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
|
||||
SOFTWARE.
|
||||
*/
|
||||
#if defined (ESP8266)
|
||||
#if defined(ESP8266)
|
||||
#define INCBIN_OUTPUT_SECTION ".irom.text"
|
||||
#endif
|
||||
#include <incbin.h>
|
||||
@ -42,5 +42,4 @@ INCBIN(UploadHtm, "data/upload.min.htm");
|
||||
#endif
|
||||
INCBIN(FirmwareHtm, "data/firmware.min.htm");
|
||||
|
||||
|
||||
// EOF
|
||||
|
@ -21,10 +21,10 @@ 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
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include <templating.hpp>
|
||||
#include <config.hpp>
|
||||
#include <templating.hpp>
|
||||
|
||||
#if defined (ESP8266)
|
||||
#if defined(ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
#else // defined (ESP32)
|
||||
#include <WiFi.h>
|
||||
@ -83,8 +83,10 @@ const char brewfatherFormat[] PROGMEM =
|
||||
"}";
|
||||
|
||||
const char influxDbFormat[] PROGMEM =
|
||||
"measurement,host=${mdns},device=${id},temp-format=${temp-unit},gravity-format=${gravity-unit} "
|
||||
"gravity=${gravity},corr-gravity=${corr-gravity},angle=${angle},temp=${temp},battery=${battery},"
|
||||
"measurement,host=${mdns},device=${id},temp-format=${temp-unit},gravity-"
|
||||
"format=${gravity-unit} "
|
||||
"gravity=${gravity},corr-gravity=${corr-gravity},angle=${angle},temp=${"
|
||||
"temp},battery=${battery},"
|
||||
"rssi=${rssi}\n";
|
||||
|
||||
const char mqttFormat[] PROGMEM =
|
||||
@ -99,8 +101,9 @@ const char mqttFormat[] PROGMEM =
|
||||
//
|
||||
// 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
|
||||
setVal(TPL_MDNS, myConfig.getMDNS());
|
||||
setVal(TPL_ID, myConfig.getID());
|
||||
@ -134,8 +137,7 @@ void TemplatingEngine::initialize(float angle, float gravitySG, float corrGravit
|
||||
if (myConfig.isGravitySG()) {
|
||||
setVal(TPL_GRAVITY, gravitySG, 4);
|
||||
setVal(TPL_GRAVITY_CORR, corrGravitySG, 4);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
setVal(TPL_GRAVITY, convertToPlato(gravitySG), 1);
|
||||
setVal(TPL_GRAVITY_CORR, convertToPlato(corrGravitySG), 1);
|
||||
}
|
||||
@ -174,7 +176,7 @@ const String& TemplatingEngine::create(TemplatingEngine::Templates idx) {
|
||||
break;
|
||||
case TEMPLATE_BREWFATHER:
|
||||
baseTemplate = String(brewfatherFormat);
|
||||
//fname = TPL_FNAME_BREWFATHER;
|
||||
// fname = TPL_FNAME_BREWFATHER;
|
||||
break;
|
||||
case TEMPLATE_INFLUX:
|
||||
baseTemplate = String(influxDbFormat);
|
||||
@ -189,8 +191,8 @@ const String& TemplatingEngine::create(TemplatingEngine::Templates idx) {
|
||||
// TODO: Add code to load templates from disk if they exist.
|
||||
File file = LittleFS.open(fname, "r");
|
||||
if (file) {
|
||||
char buf[file.size()+1];
|
||||
memset(&buf[0], 0, file.size()+1);
|
||||
char buf[file.size() + 1];
|
||||
memset(&buf[0], 0, file.size() + 1);
|
||||
file.readBytes(&buf[0], file.size());
|
||||
baseTemplate = String(&buf[0]);
|
||||
file.close();
|
||||
@ -198,14 +200,14 @@ const String& TemplatingEngine::create(TemplatingEngine::Templates idx) {
|
||||
}
|
||||
|
||||
#if LOG_LEVEL == 6
|
||||
//Log.verbose(F("TPL : Base '%s'." CR), baseTemplate.c_str());
|
||||
// Log.verbose(F("TPL : Base '%s'." CR), baseTemplate.c_str());
|
||||
#endif
|
||||
|
||||
// Insert data into template.
|
||||
transform(baseTemplate);
|
||||
|
||||
#if LOG_LEVEL == 6
|
||||
//Log.verbose(F("TPL : Transformed '%s'." CR), baseTemplate.c_str());
|
||||
// Log.verbose(F("TPL : Transformed '%s'." CR), baseTemplate.c_str());
|
||||
#endif
|
||||
|
||||
return baseTemplate;
|
||||
|
@ -85,7 +85,7 @@ class TemplatingEngine {
|
||||
{TPL_GRAVITY_P, ""}, {TPL_GRAVITY_CORR, ""},
|
||||
{TPL_GRAVITY_CORR_G, ""}, {TPL_GRAVITY_CORR_P, ""},
|
||||
{TPL_GRAVITY_UNIT, ""}, {TPL_TOKEN, ""},
|
||||
{TPL_TOKEN2, ""} };
|
||||
{TPL_TOKEN2, ""}};
|
||||
|
||||
char buffer[20];
|
||||
String baseTemplate;
|
||||
|
@ -26,10 +26,10 @@ SOFTWARE.
|
||||
#include <gyro.hpp>
|
||||
#include <helper.hpp>
|
||||
#include <main.hpp>
|
||||
#include <pushtarget.hpp>
|
||||
#include <resources.hpp>
|
||||
#include <templating.hpp>
|
||||
#include <tempsensor.hpp>
|
||||
#include <pushtarget.hpp>
|
||||
#include <webserver.hpp>
|
||||
#include <wifi.hpp>
|
||||
|
||||
@ -51,8 +51,7 @@ void WebServerHandler::webHandleConfig() {
|
||||
|
||||
double angle = 0;
|
||||
|
||||
if (myGyro.hasValue())
|
||||
angle = myGyro.getAngle();
|
||||
if (myGyro.hasValue()) angle = myGyro.getAngle();
|
||||
|
||||
double tempC = myTempSensor.getTempC(myConfig.isGyroTemp());
|
||||
double gravity = calculateGravity(angle, tempC);
|
||||
@ -62,7 +61,8 @@ void WebServerHandler::webHandleConfig() {
|
||||
|
||||
// Format the adjustment so we get rid of rounding errors
|
||||
if (myConfig.isTempF())
|
||||
doc[PARAM_TEMP_ADJ] = reduceFloatPrecision(convertCtoF(myConfig.getTempSensorAdjC()), 1);
|
||||
doc[PARAM_TEMP_ADJ] =
|
||||
reduceFloatPrecision(convertCtoF(myConfig.getTempSensorAdjC()), 1);
|
||||
else
|
||||
doc[PARAM_TEMP_ADJ] = reduceFloatPrecision(myConfig.getTempSensorAdjC(), 1);
|
||||
|
||||
@ -188,43 +188,51 @@ void WebServerHandler::webHandleUploadFile() {
|
||||
}
|
||||
|
||||
#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),
|
||||
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
|
||||
|
||||
if (firmware) {
|
||||
// Handle firmware update
|
||||
uint32_t maxSketchSpace = 1044464; //(ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||
// Handle firmware update, hardcode since function return wrong value.
|
||||
uint32_t maxSketchSpace =
|
||||
1044464; // (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||
|
||||
if (upload.status == UPLOAD_FILE_START) {
|
||||
_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;
|
||||
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;
|
||||
}
|
||||
} 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) {
|
||||
Log.error(F("WEB : Firmware file is to large." CR));
|
||||
_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));
|
||||
_uploadReturn = 500;
|
||||
}
|
||||
} else if (upload.status == UPLOAD_FILE_END) {
|
||||
Log.notice(F("WEB : Finish firmware upload." CR));
|
||||
if(Update.end(true)) {
|
||||
if (Update.end(true)) {
|
||||
_server->send(200);
|
||||
delay(500);
|
||||
ESP_RESET();
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
@ -244,15 +252,13 @@ void WebServerHandler::webHandleUploadFile() {
|
||||
if (validFilename) _uploadFile = LittleFS.open(f, "w");
|
||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||
Log.notice(F("WEB : Writing html upload." CR));
|
||||
if (_uploadFile)
|
||||
_uploadFile.write(
|
||||
upload.buf,
|
||||
upload.currentSize);
|
||||
if (_uploadFile) _uploadFile.write(upload.buf, upload.currentSize);
|
||||
} else if (upload.status == UPLOAD_FILE_END) {
|
||||
Log.notice(F("WEB : Finish html upload." CR));
|
||||
if (_uploadFile) {
|
||||
_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->send(303);
|
||||
@ -321,8 +327,7 @@ void WebServerHandler::webHandleStatus() {
|
||||
|
||||
double angle = 0;
|
||||
|
||||
if (myGyro.hasValue())
|
||||
angle = myGyro.getAngle();
|
||||
if (myGyro.hasValue()) angle = myGyro.getAngle();
|
||||
|
||||
double tempC = myTempSensor.getTempC(myConfig.isGyroTemp());
|
||||
double gravity = calculateGravity(angle, tempC);
|
||||
@ -833,7 +838,8 @@ void WebServerHandler::webHandleTestPush() {
|
||||
PushTarget push;
|
||||
bool enabled = false;
|
||||
|
||||
if (!type.compareTo(PARAM_FORMAT_BREWFATHER) && myConfig.isBrewfatherActive()) {
|
||||
if (!type.compareTo(PARAM_FORMAT_BREWFATHER) &&
|
||||
myConfig.isBrewfatherActive()) {
|
||||
push.sendBrewfather(engine);
|
||||
enabled = true;
|
||||
} 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()) {
|
||||
push.sendHttp3(engine, myConfig.isHttp3SSL());
|
||||
enabled = true;
|
||||
} else if (!type.compareTo(PARAM_FORMAT_INFLUXDB) && myConfig.isInfluxDb2Active()) {
|
||||
} else if (!type.compareTo(PARAM_FORMAT_INFLUXDB) &&
|
||||
myConfig.isInfluxDb2Active()) {
|
||||
push.sendInfluxDb2(engine);
|
||||
enabled = true;
|
||||
} else if (!type.compareTo(PARAM_FORMAT_MQTT) && myConfig.isMqttActive()) {
|
||||
@ -1145,7 +1152,7 @@ bool WebServerHandler::setupWebServer() {
|
||||
// upload page.
|
||||
if (checkHtmlFile(HTML_INDEX) && checkHtmlFile(HTML_CONFIG) &&
|
||||
checkHtmlFile(HTML_CALIBRATION) && checkHtmlFile(HTML_FORMAT) &&
|
||||
checkHtmlFile(HTML_ABOUT) && checkHtmlFile(HTML_TEST) ) {
|
||||
checkHtmlFile(HTML_ABOUT) && checkHtmlFile(HTML_TEST)) {
|
||||
Log.notice(F("WEB : All html files exist, starting in normal mode." CR));
|
||||
|
||||
_server->serveStatic("/", LittleFS, "/index.min.htm");
|
||||
|
@ -24,14 +24,14 @@ SOFTWARE.
|
||||
#ifndef SRC_WEBSERVER_HPP_
|
||||
#define SRC_WEBSERVER_HPP_
|
||||
|
||||
#if defined (ESP8266)
|
||||
#if defined(ESP8266)
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#else // defined (ESP32)
|
||||
#include <ESPmDNS.h>
|
||||
#include <WebServer.h>
|
||||
#include <WiFi.h>
|
||||
#include <ESPmDNS.h>
|
||||
#endif
|
||||
#include <incbin.h>
|
||||
|
||||
@ -103,8 +103,7 @@ class WebServerHandler {
|
||||
gAboutHtmSize);
|
||||
}
|
||||
void webReturnTestHtm() {
|
||||
_server->send_P(200, "text/html", (const char*)gTestHtmData,
|
||||
gTestHtmSize);
|
||||
_server->send_P(200, "text/html", (const char*)gTestHtmData, gTestHtmSize);
|
||||
}
|
||||
#else
|
||||
void webReturnUploadHtm() {
|
||||
|
@ -244,7 +244,7 @@ bool WifiConnection::updateFirmware() {
|
||||
WiFiClientSecure wifiSecure;
|
||||
HTTPUpdateResult ret;
|
||||
String serverPath = myConfig.getOtaURL();
|
||||
#if defined (ESP8266)
|
||||
#if defined(ESP8266)
|
||||
serverPath += "firmware.bin";
|
||||
#else // defined (ESP32)
|
||||
serverPath += "firmware32.bin";
|
||||
@ -280,7 +280,7 @@ bool WifiConnection::updateFirmware() {
|
||||
//
|
||||
// Download and save file
|
||||
//
|
||||
void WifiConnection::downloadFile(HTTPClient& http, String& fname) {
|
||||
void WifiConnection::downloadFile(HTTPClient &http, String &fname) {
|
||||
#if LOG_LEVEL == 6 && !defined(WIFI_DISABLE_LOGGING)
|
||||
Log.verbose(F("WIFI: Download file %s." CR), fname);
|
||||
#endif
|
||||
@ -364,7 +364,8 @@ bool WifiConnection::checkFirmwareVersion() {
|
||||
|
||||
// Download new html files to filesystem if they are present.
|
||||
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>();
|
||||
for (JsonVariant v : htmlFiles) {
|
||||
String s = v;
|
||||
|
Loading…
Reference in New Issue
Block a user