Added BLE on ESP32 target.

This commit is contained in:
Magnus Persson 2022-03-10 11:10:54 +01:00
parent 6dfe5a80fd
commit 21fba0481c
13 changed files with 241 additions and 5 deletions

View File

@ -374,7 +374,23 @@
</div> </div>
</div> </div>
</div> </div>
<div class="form-group row"> <div class="form-group row d-none" id="esp32-tilt">
<label class="col-sm-2 col-form-label" for="ble">Bluetooth tilt color:</label>
<div class="col-sm-2">
<select class="form-control" id="ble" name="ble">
<option value="">-not active-</option>
<option value="red">red</option>
<option value="green">green</option>
<option value="black">black</option>
<option value="purple">purple</option>
<option value="orange">orange</option>
<option value="blue">blue</option>
<option value="yellow">yellow</option>
<option value="pink">pink</option>
</select>
</div>
</div>
<div class="form-group row" id="esp32-ota">
<label for="ota-url" class="col-sm-2 col-form-label">OTA base URL:</label> <label for="ota-url" class="col-sm-2 col-form-label">OTA base URL:</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="url" maxlength="90" class="form-control" name="ota-url" id="ota-url"> <input type="url" maxlength="90" class="form-control" name="ota-url" id="ota-url">
@ -537,6 +553,13 @@ function checkHeader(input) {
$('#spinner').show(); $('#spinner').show();
$.getJSON(url, function (cfg) { $.getJSON(url, function (cfg) {
console.log( cfg ); console.log( cfg );
if(cfg["platform"]=="esp32") {
$('#esp32-tilt').removeClass('d-none');
$('#esp32-ota').addClass('d-none');
$("#ble").val(cfg["ble"]);
}
$("#id1").val(cfg["id"]); $("#id1").val(cfg["id"]);
$("#id2").val(cfg["id"]); $("#id2").val(cfg["id"]);
$("#id3").val(cfg["id"]); $("#id3").val(cfg["id"]);

File diff suppressed because one or more lines are too long

View File

@ -88,6 +88,10 @@
<div class="col-md-8 themed-grid-col bg-light">Device ID:</div> <div class="col-md-8 themed-grid-col bg-light">Device ID:</div>
<div class="col-md-4 themed-grid-col bg-light" id="id">Loading...</div> <div class="col-md-4 themed-grid-col bg-light" id="id">Loading...</div>
</div> </div>
<div class="row mb-3">
<div class="col-md-8 themed-grid-col bg-light">Platform:</div>
<div class="col-md-4 themed-grid-col bg-light" id="platform">Loading...</div>
</div>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-md-8 themed-grid-col bg-light">Average runtime:</div> <div class="col-md-8 themed-grid-col bg-light">Average runtime:</div>
<div class="col-md-4 themed-grid-col bg-light" id="runtime">Loading...</div> <div class="col-md-4 themed-grid-col bg-light" id="runtime">Loading...</div>
@ -135,6 +139,7 @@
$("#app-ver").text(cfg["app-ver"] + " (html 0.8.0)"); $("#app-ver").text(cfg["app-ver"] + " (html 0.8.0)");
$("#mdns").text(cfg["mdns"]); $("#mdns").text(cfg["mdns"]);
$("#id").text(cfg["id"]); $("#id").text(cfg["id"]);
$("#platform").text(cfg["platform"]);
$("#runtime").text(cfg["runtime-average"] + " seconds"); $("#runtime").text(cfg["runtime-average"] + " seconds");
}) })
.fail(function () { .fail(function () {

View File

@ -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 rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" 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://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" 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"><a class="nav-link" href="/index.htm">Home <span class="sr-only">(current)</span></a></li><li class="nav-item active"><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><div class="spinner-border text-light" id="spinner" role="status"></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">&times;</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="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Current version:</div><div class="col-md-4 themed-grid-col bg-light" id="app-ver">Loading...</div></div><div class="row mb-3" id="h-app-ver-new" hidden><div class="col-md-8 themed-grid-col bg-light">New version:</div><div class="col-md-4 themed-grid-col bg-light" id="app-ver-new">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Host name:</div><div class="col-md-4 themed-grid-col bg-light" id="mdns">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Device ID:</div><div class="col-md-4 themed-grid-col bg-light" id="id">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Average runtime:</div><div class="col-md-4 themed-grid-col bg-light" id="runtime">Loading...</div></div><div class="row mb-3"><a class="badge badge-primary" data-toggle="collapse" href="#collapseLog" role="button" aria-expanded="false" aria-controls="collapseLog" id="log-btn">View error log</a></div><script>function loadLog(){$("#logContent").load("/log")}$("#log-btn").click(function(o){loadLog()}),setInterval(function(){loadLog()},3e3)</script><div class="collapse" id="collapseLog"><div class="card card-body"><pre><code id="logContent"></code></pre></div></div><hr class="my-4"></div><script type="text/javascript">function getConfig(){var e="/api/device";$("#spinner").show(),$.getJSON(e,function(e){console.log(e),$("#app-ver").text(e["app-ver"]+" (html 0.8.0)"),$("#mdns").text(e.mdns),$("#id").text(e.id),$("#runtime").text(e["runtime-average"]+" seconds")}).fail(function(){showError("Unable to get data from the device.")}).always(function(){$("#spinner").hide()})}window.onload=getConfig</script><!-- START FOOTER --><div class="container-fluid themed-container bg-primary text-light">(C) Copyright 2021-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 rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" 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://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" 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"><a class="nav-link" href="/index.htm">Home <span class="sr-only">(current)</span></a></li><li class="nav-item active"><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><div class="spinner-border text-light" id="spinner" role="status"></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">&times;</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="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Current version:</div><div class="col-md-4 themed-grid-col bg-light" id="app-ver">Loading...</div></div><div class="row mb-3" id="h-app-ver-new" hidden><div class="col-md-8 themed-grid-col bg-light">New version:</div><div class="col-md-4 themed-grid-col bg-light" id="app-ver-new">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Host name:</div><div class="col-md-4 themed-grid-col bg-light" id="mdns">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Device ID:</div><div class="col-md-4 themed-grid-col bg-light" id="id">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Platform:</div><div class="col-md-4 themed-grid-col bg-light" id="platform">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Average runtime:</div><div class="col-md-4 themed-grid-col bg-light" id="runtime">Loading...</div></div><div class="row mb-3"><a class="badge badge-primary" data-toggle="collapse" href="#collapseLog" role="button" aria-expanded="false" aria-controls="collapseLog" id="log-btn">View error log</a></div><script>function loadLog(){$("#logContent").load("/log")}$("#log-btn").click(function(o){loadLog()}),setInterval(function(){loadLog()},3e3)</script><div class="collapse" id="collapseLog"><div class="card card-body"><pre><code id="logContent"></code></pre></div></div><hr class="my-4"></div><script type="text/javascript">function getConfig(){var e="/api/device";$("#spinner").show(),$.getJSON(e,function(e){console.log(e),$("#app-ver").text(e["app-ver"]+" (html 0.8.0)"),$("#mdns").text(e.mdns),$("#id").text(e.id),$("#platform").text(e.platform),$("#runtime").text(e["runtime-average"]+" seconds")}).fail(function(){showError("Unable to get data from the device.")}).always(function(){$("#spinner").hide()})}window.onload=getConfig</script><!-- START FOOTER --><div class="container-fluid themed-container bg-primary text-light">(C) Copyright 2021-22 Magnus Persson</div></body></html>

99
src/ble.cpp Normal file
View File

@ -0,0 +1,99 @@
/*
MIT License
Copyright (c) 2021-22 Magnus
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
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(ESP32)
#include <ble.hpp>
// Tilt UUID variants and data format, based on tilt-sim
//
// https://github.com/spouliot/tilt-sim
//
// Tilt data format is described here. Only SG and Temp is transmitted over BLE.
// https://kvurd.com/blog/tilt-hydrometer-ibeacon-data-format/
//
// Create ble sender
//
BleSender::BleSender(const char* color) {
BLEDevice::init("");
// 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);
_advertising = BLEDevice::getAdvertising();
_color = color;
if (!_color.compareTo("red"))
_uuid = BLEUUID::fromString("A495BB10-C5B1-4B44-B512-1370F02D74DE");
else if (!_color.compareTo("green"))
_uuid = BLEUUID::fromString("A495BB20-C5B1-4B44-B512-1370F02D74DE");
else if (!_color.compareTo("black"))
_uuid = BLEUUID::fromString("A495BB30-C5B1-4B44-B512-1370F02D74DE");
else if (!_color.compareTo("purple"))
_uuid = BLEUUID::fromString("A495BB40-C5B1-4B44-B512-1370F02D74DE");
else if (!_color.compareTo("orange"))
_uuid = BLEUUID::fromString("A495BB50-C5B1-4B44-B512-1370F02D74DE");
else if (!_color.compareTo("blue"))
_uuid = BLEUUID::fromString("A495BB60-C5B1-4B44-B512-1370F02D74DE");
else if (!_color.compareTo("yellow"))
_uuid = BLEUUID::fromString("A495BB70-C5B1-4B44-B512-1370F02D74DE");
else // if (_color.compareTo("pink"))
_uuid = BLEUUID::fromString("A495BB80-C5B1-4B44-B512-1370F02D74DE");
}
//
// 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 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.setProximityUUID(_uuid);
oBeacon.setMajor(temperature);
oBeacon.setMinor(gravity);
std::string strServiceData = "";
strServiceData += (char)26; // Len
strServiceData += (char)0xFF; // Type
strServiceData += oBeacon.getData();
BLEAdvertisementData oAdvertisementData = BLEAdvertisementData();
oAdvertisementData.setFlags(0x04); // BR_EDR_NOT_SUPPORTED 0x04
oAdvertisementData.addData(strServiceData);
BLEAdvertisementData oScanResponseData = BLEAdvertisementData();
_advertising->setAdvertisementData(oAdvertisementData);
_advertising->setScanResponseData(oScanResponseData);
_advertising->setAdvertisementType(BLE_GAP_CONN_MODE_NON);
_advertising->start();
delay(100);
_advertising->stop();
delay(100);
}
#endif // ESP32

48
src/ble.hpp Normal file
View File

@ -0,0 +1,48 @@
/*
MIT License
Copyright (c) 2021-22 Magnus
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
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.
*/
#ifndef SRC_BLE_HPP_
#define SRC_BLE_HPP_
#if defined (ESP32)
#include <main.hpp>
#include <config.hpp>
#include "NimBLEDevice.h"
#include "NimBLEBeacon.h"
class BleSender {
private:
BLEAdvertising *_advertising;
String _color;
BLEUUID _uuid;
public:
BleSender(const char* color);
void sendData(float tempF, float gravSG);
};
#endif // ESP32
#endif // SRC_BLE_HPP_
// EOF

View File

@ -70,6 +70,7 @@ void Config::createJson(DynamicJsonDocument& doc) {
doc[PARAM_OTA] = getOtaURL(); doc[PARAM_OTA] = getOtaURL();
doc[PARAM_SSID] = getWifiSSID(); doc[PARAM_SSID] = getWifiSSID();
doc[PARAM_PASS] = getWifiPass(); doc[PARAM_PASS] = getWifiPass();
doc[PARAM_BLE] = getColorBLE();
doc[PARAM_TEMPFORMAT] = String(getTempFormat()); doc[PARAM_TEMPFORMAT] = String(getTempFormat());
doc[PARAM_PUSH_BREWFATHER] = getBrewfatherPushUrl(); doc[PARAM_PUSH_BREWFATHER] = getBrewfatherPushUrl();
doc[PARAM_TOKEN] = getToken(); doc[PARAM_TOKEN] = getToken();
@ -203,6 +204,7 @@ bool Config::loadFile() {
if (!doc[PARAM_MDNS].isNull()) setMDNS(doc[PARAM_MDNS]); if (!doc[PARAM_MDNS].isNull()) setMDNS(doc[PARAM_MDNS]);
if (!doc[PARAM_SSID].isNull()) setWifiSSID(doc[PARAM_SSID]); if (!doc[PARAM_SSID].isNull()) setWifiSSID(doc[PARAM_SSID]);
if (!doc[PARAM_PASS].isNull()) setWifiPass(doc[PARAM_PASS]); if (!doc[PARAM_PASS].isNull()) setWifiPass(doc[PARAM_PASS]);
if (!doc[PARAM_BLE].isNull()) setColorBLE(doc[PARAM_BLE]);
if (!doc[PARAM_TEMPFORMAT].isNull()) { if (!doc[PARAM_TEMPFORMAT].isNull()) {
String s = doc[PARAM_TEMPFORMAT]; String s = doc[PARAM_TEMPFORMAT];

View File

@ -130,6 +130,9 @@ class Config {
bool _gravityTempAdj = false; bool _gravityTempAdj = false;
char _gravityFormat = 'G'; char _gravityFormat = 'G';
// BLE (ESP32 only)
String _colorBLE;
// Gyro calibration and formula calculation data // Gyro calibration and formula calculation data
RawGyroData _gyroCalibration = {0, 0, 0, 0, 0, 0}; RawGyroData _gyroCalibration = {0, 0, 0, 0, 0, 0};
RawFormulaData _formulaData = {{0, 0, 0, 0, 0}, {1, 1, 1, 1, 1}}; RawFormulaData _formulaData = {{0, 0, 0, 0, 0}, {1, 1, 1, 1, 1}};
@ -335,6 +338,16 @@ class Config {
bool isGravitySG() { return _gravityFormat == 'G'; } bool isGravitySG() { return _gravityFormat == 'G'; }
bool isGravityPlato() { return _gravityFormat == 'P'; } bool isGravityPlato() { return _gravityFormat == 'P'; }
const char* getColorBLE() { return _colorBLE.c_str(); }
void setColorBLE(String c) {
_colorBLE = c;
_saveNeeded = true;
}
bool isBLEActive() { return _colorBLE.length() ? true : false; }
bool isWifiPushActive() {
return (isHttpActive() || isHttp2Active() || isBrewfatherActive() || isInfluxDb2Active() || isMqttActive()) ? true : false;
}
const RawGyroData& getGyroCalibration() { return _gyroCalibration; } const RawGyroData& getGyroCalibration() { return _gyroCalibration; }
void setGyroCalibration(const RawGyroData& r) { void setGyroCalibration(const RawGyroData& r) {
_gyroCalibration = r; _gyroCalibration = r;

View File

@ -30,6 +30,7 @@ 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
@ -248,6 +249,14 @@ bool loopReadGravity() {
angle, tempC, gravity, corrGravity); angle, tempC, gravity, corrGravity);
#endif #endif
#if defined (ESP32)
if (myConfig.isBLEActive()) {
BleSender ble(myConfig.getColorBLE());
ble.sendData( convertCtoF(tempC), gravitySG);
Log.notice(F("MAIN: Broadcast data over bluetooth." CR));
}
#endif
bool pushExpired = (abs((int32_t)(millis() - pushMillis)) > bool pushExpired = (abs((int32_t)(millis() - pushMillis)) >
(myConfig.getSleepInterval() * 1000)); (myConfig.getSleepInterval() * 1000));

View File

@ -71,6 +71,8 @@ SOFTWARE.
#define PARAM_SLEEP_MODE "sleep-mode" #define PARAM_SLEEP_MODE "sleep-mode"
#define PARAM_RSSI "rssi" #define PARAM_RSSI "rssi"
#define PARAM_ERROR "error" #define PARAM_ERROR "error"
#define PARAM_PLATFORM "platform"
#define PARAM_BLE "ble"
#define PARAM_HW_GYRO_READ_COUNT "gyro-read-count" #define PARAM_HW_GYRO_READ_COUNT "gyro-read-count"
#define PARAM_HW_GYRO_READ_DELAY "gyro-read-delay" #define PARAM_HW_GYRO_READ_DELAY "gyro-read-delay"
#define PARAM_HW_GYRO_MOVING_THREASHOLD "gyro-moving-threashold" #define PARAM_HW_GYRO_MOVING_THREASHOLD "gyro-moving-threashold"

View File

@ -55,6 +55,12 @@ void WebServerHandler::webHandleDevice() {
doc[PARAM_RUNTIME_AVERAGE] = reduceFloatPrecision( doc[PARAM_RUNTIME_AVERAGE] = reduceFloatPrecision(
runLog.getAverage() ? runLog.getAverage() / 1000 : 0, 1); runLog.getAverage() ? runLog.getAverage() / 1000 : 0, 1);
#if defined(ESP8266)
doc[PARAM_PLATFORM] = "esp8266";
#else
doc[PARAM_PLATFORM] = "esp32";
#endif
#if LOG_LEVEL == 6 #if LOG_LEVEL == 6
serializeJson(doc, Serial); serializeJson(doc, Serial);
Serial.print(CR); Serial.print(CR);
@ -106,6 +112,12 @@ void WebServerHandler::webHandleConfig() {
doc[PARAM_RUNTIME_AVERAGE] = reduceFloatPrecision( doc[PARAM_RUNTIME_AVERAGE] = reduceFloatPrecision(
runLog.getAverage() ? runLog.getAverage() / 1000 : 0, 1); runLog.getAverage() ? runLog.getAverage() / 1000 : 0, 1);
#if defined(ESP8266)
doc[PARAM_PLATFORM] = "esp8266";
#else
doc[PARAM_PLATFORM] = "esp32";
#endif
#if LOG_LEVEL == 6 && !defined(WEB_DISABLE_LOGGING) #if LOG_LEVEL == 6 && !defined(WEB_DISABLE_LOGGING)
serializeJson(doc, Serial); serializeJson(doc, Serial);
Serial.print(CR); Serial.print(CR);
@ -146,7 +158,25 @@ void WebServerHandler::webHandleUpload() {
obj[PARAM_FILE_SIZE] = dir.fileSize(); obj[PARAM_FILE_SIZE] = dir.fileSize();
} }
#else // defined(ESP32) #else // defined(ESP32)
#warning "TODO: Implement file listing for ESP32" JsonArray files = doc.createNestedArray(PARAM_FILES);
File dir = LittleFS.open("/");
while (true) {
File entry = dir.openNextFile();
if (!entry) {
// no more files
break;
}
if (!entry.isDirectory()) {
JsonObject obj = files.createNestedObject();
obj[PARAM_FILE_NAME] = entry.name();
obj[PARAM_FILE_SIZE] = entry.size();
}
entry.close();
}
dir.close();
#endif #endif
#if LOG_LEVEL == 6 && !defined(WEB_DISABLE_LOGGING) #if LOG_LEVEL == 6 && !defined(WEB_DISABLE_LOGGING)
@ -521,6 +551,8 @@ void WebServerHandler::webHandleConfigHardware() {
myConfig.setTempSensorAdjF(_server->arg(PARAM_TEMP_ADJ)); myConfig.setTempSensorAdjF(_server->arg(PARAM_TEMP_ADJ));
} }
} }
if (_server->hasArg(PARAM_BLE))
myConfig.setColorBLE(_server->arg(PARAM_BLE).c_str());
if (_server->hasArg(PARAM_OTA)) if (_server->hasArg(PARAM_OTA))
myConfig.setOtaURL(_server->arg(PARAM_OTA).c_str()); myConfig.setOtaURL(_server->arg(PARAM_OTA).c_str());
if (_server->hasArg(PARAM_GYRO_TEMP)) if (_server->hasArg(PARAM_GYRO_TEMP))

View File

@ -37,5 +37,7 @@
"angle": 90.93, "angle": 90.93,
"gravity": 1.105, "gravity": 1.105,
"battery": 0.04, "battery": 0.04,
"runtime-average": 2.0 "runtime-average": 2.0,
"ble": "pink",
"platform": "esp32"
} }

View File

@ -3,5 +3,6 @@
"app-ver": "0.0.0", "app-ver": "0.0.0",
"id": "7376ef", "id": "7376ef",
"mdns": "gravmon", "mdns": "gravmon",
"platform": "esp32",
"runtime-average": 3.12 "runtime-average": 3.12
} }