Logging improvements
This commit is contained in:
@@ -35,7 +35,7 @@ struct ConfigDef {
|
|||||||
static const ConfigDef configdefs[] = {
|
static const ConfigDef configdefs[] = {
|
||||||
{"systemName", ConfigType::STRING, String("OBPkp61")},
|
{"systemName", ConfigType::STRING, String("OBPkp61")},
|
||||||
{"systemMode", ConfigType::CHAR, 'K'},
|
{"systemMode", ConfigType::CHAR, 'K'},
|
||||||
{"logLevel", ConfigType::BYTE, uint8_t(0)},
|
{"logLevel", ConfigType::BYTE, uint8_t(1)},
|
||||||
{"adminPassword", ConfigType::STRING, String("obpkp61")},
|
{"adminPassword", ConfigType::STRING, String("obpkp61")},
|
||||||
{"useAdminPass", ConfigType::BOOL, true},
|
{"useAdminPass", ConfigType::BOOL, true},
|
||||||
{"apEnable", ConfigType::BOOL, true},
|
{"apEnable", ConfigType::BOOL, true},
|
||||||
@@ -63,7 +63,7 @@ static const ConfigDef configdefs[] = {
|
|||||||
{"n2kDestA", ConfigType::STRING, String("")},
|
{"n2kDestA", ConfigType::STRING, String("")},
|
||||||
{"n2kDestB", ConfigType::STRING, String("")},
|
{"n2kDestB", ConfigType::STRING, String("")},
|
||||||
{"n2kDestC", ConfigType::STRING, String("")},
|
{"n2kDestC", ConfigType::STRING, String("")},
|
||||||
{"envInterval", ConfigType::SHORT, int16_t(5000)},
|
{"envInterval", ConfigType::SHORT, int16_t(5)},
|
||||||
|
|
||||||
// no user access
|
// no user access
|
||||||
{"LastNodeId", ConfigType::BYTE, uint8_t(N2K_DEFAULT_NODEID)}
|
{"LastNodeId", ConfigType::BYTE, uint8_t(N2K_DEFAULT_NODEID)}
|
||||||
|
|||||||
@@ -3,6 +3,22 @@
|
|||||||
#include "Nmea2kTwai.h"
|
#include "Nmea2kTwai.h"
|
||||||
#include "N2kDeviceList.h"
|
#include "N2kDeviceList.h"
|
||||||
|
|
||||||
|
#define LOGE(tag, fmt, ...) \
|
||||||
|
do { if (loglevel >= ESP_LOG_ERROR) ESP_LOGE(tag, fmt, ##__VA_ARGS__); } while(0)
|
||||||
|
|
||||||
|
#define LOGW(tag, fmt, ...) \
|
||||||
|
do { if (loglevel >= ESP_LOG_WARN) ESP_LOGW(tag, fmt, ##__VA_ARGS__); } while(0)
|
||||||
|
|
||||||
|
#define LOGI(tag, fmt, ...) \
|
||||||
|
do { if (loglevel >= ESP_LOG_INFO) ESP_LOGI(tag, fmt, ##__VA_ARGS__); } while(0)
|
||||||
|
|
||||||
|
#define LOGD(tag, fmt, ...) \
|
||||||
|
do { if (loglevel >= ESP_LOG_DEBUG) ESP_LOGD(tag, fmt, ##__VA_ARGS__); } while(0)
|
||||||
|
|
||||||
|
#define LOGV(tag, fmt, ...) \
|
||||||
|
do { if (loglevel >= ESP_LOG_VERBOSE) ESP_LOGV(tag, fmt, ##__VA_ARGS__); } while(0)
|
||||||
|
|
||||||
|
|
||||||
#define STRINGIFY_IMPL(x) #x
|
#define STRINGIFY_IMPL(x) #x
|
||||||
#define STRINGIFY(x) STRINGIFY_IMPL(x)
|
#define STRINGIFY(x) STRINGIFY_IMPL(x)
|
||||||
|
|
||||||
@@ -117,6 +133,7 @@ extern Nmea2kTwai &NMEA2000;
|
|||||||
extern tN2kDeviceList *pN2kDeviceList;
|
extern tN2kDeviceList *pN2kDeviceList;
|
||||||
|
|
||||||
extern char globalmode;
|
extern char globalmode;
|
||||||
|
extern uint8_t loglevel;
|
||||||
|
|
||||||
extern uint64_t chipid;
|
extern uint64_t chipid;
|
||||||
extern int16_t led_brightness;
|
extern int16_t led_brightness;
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
|
#include "../../include/main.h"
|
||||||
#include "Nmea2kTwai.h"
|
#include "Nmea2kTwai.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "driver/twai.h"
|
#include "driver/twai.h"
|
||||||
|
|
||||||
#define LOGID(id) ((id >> 8) & 0x1ffff)
|
#define LOGID(id) ((id >> 8) & 0x1ffff)
|
||||||
|
|
||||||
|
// Logging
|
||||||
|
static const char* TAG = "TWAI";
|
||||||
|
|
||||||
static const int TIMEOUT_OFFLINE = 256; // number of timeouts to consider offline
|
static const int TIMEOUT_OFFLINE = 256; // number of timeouts to consider offline
|
||||||
|
|
||||||
Nmea2kTwai::Nmea2kTwai(gpio_num_t _TxPin, gpio_num_t _RxPin, unsigned long recP, unsigned long logP):
|
Nmea2kTwai::Nmea2kTwai(gpio_num_t _TxPin, gpio_num_t _RxPin, unsigned long recP, unsigned long logP):
|
||||||
tNMEA2000(), RxPin(_RxPin), TxPin(_TxPin)
|
tNMEA2000(), RxPin(_RxPin), TxPin(_TxPin)
|
||||||
{
|
{
|
||||||
if (RxPin < 0 || TxPin < 0){
|
if (RxPin < 0 || TxPin < 0) {
|
||||||
disabled = true;
|
disabled = true;
|
||||||
} else {
|
} else {
|
||||||
// timers.addAction(logP,[this](){ logStatus(); });
|
// timers.addAction(logP,[this](){ logStatus(); });
|
||||||
@@ -27,32 +31,34 @@ bool Nmea2kTwai::CANSendFrame(unsigned long id, unsigned char len, const unsigne
|
|||||||
message.identifier = id;
|
message.identifier = id;
|
||||||
message.extd = 1;
|
message.extd = 1;
|
||||||
message.data_length_code = len;
|
message.data_length_code = len;
|
||||||
memcpy(message.data, buf,len);
|
memcpy(message.data, buf, len);
|
||||||
esp_err_t rt = twai_transmit(&message, 0);
|
esp_err_t rt = twai_transmit(&message, 0);
|
||||||
if (rt != ESP_OK){
|
if (rt != ESP_OK) {
|
||||||
if (rt == ESP_ERR_TIMEOUT) {
|
if (rt == ESP_ERR_TIMEOUT) {
|
||||||
if (txTimeouts < TIMEOUT_OFFLINE) txTimeouts++;
|
if (txTimeouts < TIMEOUT_OFFLINE) {
|
||||||
|
txTimeouts++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// logDebug(LOG_MSG,"twai transmit for %ld failed: %x",LOGID(id),(int)rt);
|
LOGW(TAG, "twai transmit for %ld failed: %x", LOGID(id), (int)rt);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
txTimeouts = 0;
|
txTimeouts = 0;
|
||||||
// logDebug(LOG_MSG,"twai transmit id %ld, len %d",LOGID(id),(int)len);
|
LOGD(TAG, "twai transmit id %ld, len %d", LOGID(id), (int)len);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Nmea2kTwai::CANOpen()
|
bool Nmea2kTwai::CANOpen()
|
||||||
{
|
{
|
||||||
if (disabled){
|
if (disabled) {
|
||||||
// logDebug(LOG_INFO,"CAN disabled");
|
LOGD(TAG, "CAN disabled");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
esp_err_t rt = twai_start();
|
esp_err_t rt = twai_start();
|
||||||
if (rt != ESP_OK){
|
if (rt != ESP_OK) {
|
||||||
// logDebug(LOG_ERR,"CANOpen failed: %x",(int)rt);
|
LOGE(TAG, "CANOpen failed: %x", (int)rt);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// logDebug(LOG_INFO, "CANOpen ok");
|
LOGI(TAG, "CANOpen ok");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -73,10 +79,11 @@ bool Nmea2kTwai::CANGetFrame(unsigned long &id, unsigned char &len, unsigned cha
|
|||||||
id = message.identifier;
|
id = message.identifier;
|
||||||
len = message.data_length_code;
|
len = message.data_length_code;
|
||||||
if (len > 8) {
|
if (len > 8) {
|
||||||
// logDebug(LOG_DEBUG,"twai: received invalid message %lld, len %d",LOGID(id),len);
|
LOGD(TAG, "twai: received invalid message %lld, len %d", LOGID(id), len);
|
||||||
len = 8;
|
len = 8;
|
||||||
}
|
}
|
||||||
// logDebug(LOG_MSG,"twai rcv id=%ld,len=%d, ext=%d",LOGID(message.identifier),message.data_length_code,message.extd);
|
LOGD(TAG, "twai rcv id=%ld,len=%d, ext=%d",
|
||||||
|
LOGID(message.identifier), message.data_length_code, message.extd);
|
||||||
if (! message.rtr) {
|
if (! message.rtr) {
|
||||||
memcpy(buf, message.data, message.data_length_code);
|
memcpy(buf, message.data, message.data_length_code);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,11 +30,11 @@ public:
|
|||||||
void loop();
|
void loop();
|
||||||
static const char *stateStr(const STATE &st);
|
static const char *stateStr(const STATE &st);
|
||||||
virtual bool CANOpen();
|
virtual bool CANOpen();
|
||||||
virtual ~Nmea2kTwai(){};
|
virtual ~Nmea2kTwai() {};
|
||||||
static const int LOG_ERR = 0;
|
// static const int LOG_ERR = 0;
|
||||||
static const int LOG_INFO = 1;
|
// static const int LOG_INFO = 1;
|
||||||
static const int LOG_DEBUG = 2;
|
// static const int LOG_DEBUG = 2;
|
||||||
static const int LOG_MSG = 3;
|
// static const int LOG_MSG = 3;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool CANSendFrame(unsigned long id, unsigned char len, const unsigned char *buf, bool wait_sent=true);
|
virtual bool CANSendFrame(unsigned long id, unsigned char len, const unsigned char *buf, bool wait_sent=true);
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ build_flags =
|
|||||||
-DBOARD_HAS_PSRAM
|
-DBOARD_HAS_PSRAM
|
||||||
-DARDUINO_USB_CDC_ON_BOOT=1
|
-DARDUINO_USB_CDC_ON_BOOT=1
|
||||||
-DCORE_DEBUG_LEVEL=4 # Max. possible loglevel: 0=None, 1=Error, 2=Warning, 3=Info, 4=Debug, 5=Verbose
|
-DCORE_DEBUG_LEVEL=4 # Max. possible loglevel: 0=None, 1=Error, 2=Warning, 3=Info, 4=Debug, 5=Verbose
|
||||||
|
# -DLOG_LOCAL_LEVEL=5 # No limits for ESP_LOG
|
||||||
-DCONFIG_LOG_TX_BUF_SIZE=8192
|
-DCONFIG_LOG_TX_BUF_SIZE=8192
|
||||||
-std=gnu++17
|
-std=gnu++17
|
||||||
build_unflags =
|
build_unflags =
|
||||||
|
|||||||
@@ -18,18 +18,18 @@ Config::Config(Preferences& prefs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] void Config::error_abort() const {
|
[[noreturn]] void Config::error_abort() const {
|
||||||
ESP_LOGD(TAG, "Rebooting in about 2 seconds");
|
LOGD(TAG, "Rebooting in about 2 seconds");
|
||||||
esp_rom_uart_tx_wait_idle(0);
|
esp_rom_uart_tx_wait_idle(0);
|
||||||
delay(2000); // to have a chance to read
|
delay(2000); // to have a chance to read
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Config::load() {
|
void Config::load() {
|
||||||
ESP_LOGD(TAG, "Loading configuration");
|
LOGD(TAG, "Loading configuration");
|
||||||
prefs.begin(PREF_NAME, true);
|
prefs.begin(PREF_NAME, true);
|
||||||
for (const auto& def : configdefs) {
|
for (const auto& def : configdefs) {
|
||||||
if (prefs.isKey(def.key)) {
|
if (prefs.isKey(def.key)) {
|
||||||
ESP_LOGD(TAG, "Config option '%s' loaded from NVS", def.key);
|
LOGD(TAG, "Config option '%s' loaded from NVS", def.key);
|
||||||
switch (def.type) {
|
switch (def.type) {
|
||||||
case ConfigType::BYTE:
|
case ConfigType::BYTE:
|
||||||
values[def.key] = (uint8_t)prefs.getUChar(def.key, std::get<uint8_t>(def.defval));
|
values[def.key] = (uint8_t)prefs.getUChar(def.key, std::get<uint8_t>(def.defval));
|
||||||
@@ -54,7 +54,7 @@ void Config::load() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGD(TAG, "Using default for '%s'", def.key);
|
LOGD(TAG, "Using default for '%s'", def.key);
|
||||||
switch (def.type) {
|
switch (def.type) {
|
||||||
case ConfigType::BYTE:
|
case ConfigType::BYTE:
|
||||||
values[def.key] = std::get<uint8_t>(def.defval);
|
values[def.key] = std::get<uint8_t>(def.defval);
|
||||||
@@ -96,13 +96,13 @@ bool Config::save(JsonObject json) {
|
|||||||
|
|
||||||
auto it = values.find(key);
|
auto it = values.find(key);
|
||||||
if (it == values.end()) {
|
if (it == values.end()) {
|
||||||
ESP_LOGE(TAG, "Unexpected missing key: %s", key);
|
LOGE(TAG, "Unexpected missing key: %s", key);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto itdef = defs.find(key);
|
auto itdef = defs.find(key);
|
||||||
if (itdef == defs.end()) {
|
if (itdef == defs.end()) {
|
||||||
ESP_LOGE(TAG, "Unexpected missing defs key: %s", key);
|
LOGE(TAG, "Unexpected missing defs key: %s", key);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ bool Config::save(JsonObject json) {
|
|||||||
if (newval != *curval) {
|
if (newval != *curval) {
|
||||||
values[key] = newval;
|
values[key] = newval;
|
||||||
//prefs.putUChar(key, newval);
|
//prefs.putUChar(key, newval);
|
||||||
ESP_LOGI(TAG, "changing %s, replacing %d with %d", key, *curval, newval);
|
LOGI(TAG, "changing %s, replacing %d with %d", key, *curval, newval);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -164,46 +164,46 @@ bool Config::save(JsonObject json) {
|
|||||||
|
|
||||||
void Config::dump() {
|
void Config::dump() {
|
||||||
// only for debugging purposes,
|
// only for debugging purposes,
|
||||||
ESP_LOGI(TAG, "========== Config options ==========");
|
LOGI(TAG, "========== Config options ==========");
|
||||||
for (const auto& def : configdefs) {
|
for (const auto& def : configdefs) {
|
||||||
auto it = values.find(def.key);
|
auto it = values.find(def.key);
|
||||||
if (it == values.end()) {
|
if (it == values.end()) {
|
||||||
ESP_LOGW(TAG, "%s = <missing>", def.key);
|
LOGW(TAG, "%s = <missing>", def.key);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const ConfigValue& value = it->second;
|
const ConfigValue& value = it->second;
|
||||||
switch (def.type) {
|
switch (def.type) {
|
||||||
case ConfigType::BYTE:
|
case ConfigType::BYTE:
|
||||||
if (auto v = std::get_if<uint8_t>(&value))
|
if (auto v = std::get_if<uint8_t>(&value))
|
||||||
ESP_LOGI(TAG, "%s = %u", def.key, *v);
|
LOGI(TAG, "%s = %u", def.key, *v);
|
||||||
break;
|
break;
|
||||||
case ConfigType::SHORT:
|
case ConfigType::SHORT:
|
||||||
if (auto v = std::get_if<int16_t>(&value))
|
if (auto v = std::get_if<int16_t>(&value))
|
||||||
ESP_LOGI(TAG, "%s = %d", def.key, *v);
|
LOGI(TAG, "%s = %d", def.key, *v);
|
||||||
break;
|
break;
|
||||||
case ConfigType::INT:
|
case ConfigType::INT:
|
||||||
if (auto v = std::get_if<int32_t>(&value))
|
if (auto v = std::get_if<int32_t>(&value))
|
||||||
ESP_LOGI(TAG, "%s = %d", def.key, *v);
|
LOGI(TAG, "%s = %d", def.key, *v);
|
||||||
break;
|
break;
|
||||||
case ConfigType::BOOL:
|
case ConfigType::BOOL:
|
||||||
if (auto v = std::get_if<bool>(&value))
|
if (auto v = std::get_if<bool>(&value))
|
||||||
ESP_LOGI(TAG, "%s = %s", def.key, *v ? "true" : "false");
|
LOGI(TAG, "%s = %s", def.key, *v ? "true" : "false");
|
||||||
break;
|
break;
|
||||||
case ConfigType::FLOAT:
|
case ConfigType::FLOAT:
|
||||||
if (auto v = std::get_if<float>(&value))
|
if (auto v = std::get_if<float>(&value))
|
||||||
ESP_LOGI(TAG, "%s = %.3f", def.key, *v);
|
LOGI(TAG, "%s = %.3f", def.key, *v);
|
||||||
break;
|
break;
|
||||||
case ConfigType::CHAR:
|
case ConfigType::CHAR:
|
||||||
if (auto v = std::get_if<char>(&value))
|
if (auto v = std::get_if<char>(&value))
|
||||||
ESP_LOGI(TAG, "%s = '%c'", def.key, *v);
|
LOGI(TAG, "%s = '%c'", def.key, *v);
|
||||||
break;
|
break;
|
||||||
case ConfigType::STRING:
|
case ConfigType::STRING:
|
||||||
if (auto v = std::get_if<String>(&value))
|
if (auto v = std::get_if<String>(&value))
|
||||||
ESP_LOGI(TAG, "%s = \"%s\"", def.key, v->c_str());
|
LOGI(TAG, "%s = \"%s\"", def.key, v->c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ESP_LOGI(TAG, "====================================");
|
LOGI(TAG, "====================================");
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -214,12 +214,12 @@ T Config::get(const char* key) const {
|
|||||||
uint8_t Config::getByte(const char* key) const {
|
uint8_t Config::getByte(const char* key) const {
|
||||||
auto it = values.find(key);
|
auto it = values.find(key);
|
||||||
if (it == values.end()) {
|
if (it == values.end()) {
|
||||||
ESP_LOGE(TAG, "Missing config key: %s", key);
|
LOGE(TAG, "Missing config key: %s", key);
|
||||||
error_abort();
|
error_abort();
|
||||||
}
|
}
|
||||||
if (auto v = std::get_if<uint8_t>(&it->second))
|
if (auto v = std::get_if<uint8_t>(&it->second))
|
||||||
return *v;
|
return *v;
|
||||||
ESP_LOGE(TAG, "Type mismatch for key: %s", key);
|
LOGE(TAG, "Type mismatch for key: %s", key);
|
||||||
error_abort();
|
error_abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,59 +238,59 @@ int16_t Config::getShort(const char* key) const {
|
|||||||
int32_t Config::getInt(const char* key) const {
|
int32_t Config::getInt(const char* key) const {
|
||||||
auto it = values.find(key);
|
auto it = values.find(key);
|
||||||
if (it == values.end()) {
|
if (it == values.end()) {
|
||||||
ESP_LOGE(TAG, "Missing config key: %s", key);
|
LOGE(TAG, "Missing config key: %s", key);
|
||||||
error_abort();
|
error_abort();
|
||||||
}
|
}
|
||||||
if (auto v = std::get_if<int32_t>(&it->second))
|
if (auto v = std::get_if<int32_t>(&it->second))
|
||||||
return *v;
|
return *v;
|
||||||
ESP_LOGE(TAG, "Type mismatch for key: %s", key);
|
LOGE(TAG, "Type mismatch for key: %s", key);
|
||||||
error_abort();
|
error_abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Config::getBool(const char* key) const {
|
bool Config::getBool(const char* key) const {
|
||||||
auto it = values.find(key);
|
auto it = values.find(key);
|
||||||
if (it == values.end())
|
if (it == values.end())
|
||||||
ESP_LOGE(TAG, "Missing config key: %s", key);
|
LOGE(TAG, "Missing config key: %s", key);
|
||||||
abort();
|
abort();
|
||||||
if (auto v = std::get_if<bool>(&it->second))
|
if (auto v = std::get_if<bool>(&it->second))
|
||||||
return *v;
|
return *v;
|
||||||
ESP_LOGE(TAG, "Type mismatch for key: %s", key);
|
LOGE(TAG, "Type mismatch for key: %s", key);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
float Config::getFloat(const char* key) const {
|
float Config::getFloat(const char* key) const {
|
||||||
auto it = values.find(key);
|
auto it = values.find(key);
|
||||||
if (it == values.end()) {
|
if (it == values.end()) {
|
||||||
ESP_LOGE(TAG, "Missing config key: %s", key);
|
LOGE(TAG, "Missing config key: %s", key);
|
||||||
error_abort();
|
error_abort();
|
||||||
}
|
}
|
||||||
if (auto v = std::get_if<float>(&it->second))
|
if (auto v = std::get_if<float>(&it->second))
|
||||||
return *v;
|
return *v;
|
||||||
ESP_LOGE(TAG, "Type mismatch for key: %s", key);
|
LOGE(TAG, "Type mismatch for key: %s", key);
|
||||||
error_abort();
|
error_abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
char Config::getChar(const char* key) const {
|
char Config::getChar(const char* key) const {
|
||||||
auto it = values.find(key);
|
auto it = values.find(key);
|
||||||
if (it == values.end()) {
|
if (it == values.end()) {
|
||||||
ESP_LOGE(TAG, "Missing config key: %s", key);
|
LOGE(TAG, "Missing config key: %s", key);
|
||||||
error_abort();
|
error_abort();
|
||||||
}
|
}
|
||||||
if (auto v = std::get_if<char>(&it->second))
|
if (auto v = std::get_if<char>(&it->second))
|
||||||
return *v;
|
return *v;
|
||||||
ESP_LOGE(TAG, "Type mismatch for key: %s", key);
|
LOGE(TAG, "Type mismatch for key: %s", key);
|
||||||
error_abort();
|
error_abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
const String& Config::getString(const char* key) const {
|
const String& Config::getString(const char* key) const {
|
||||||
auto it = values.find(key);
|
auto it = values.find(key);
|
||||||
if (it == values.end()) {
|
if (it == values.end()) {
|
||||||
ESP_LOGE(TAG, "Missing config key: %s", key);
|
LOGE(TAG, "Missing config key: %s", key);
|
||||||
error_abort();
|
error_abort();
|
||||||
}
|
}
|
||||||
if (auto v = std::get_if<String>(&it->second))
|
if (auto v = std::get_if<String>(&it->second))
|
||||||
return *v;
|
return *v;
|
||||||
ESP_LOGE(TAG, "Type mismatch for key: %s", key);
|
LOGE(TAG, "Type mismatch for key: %s", key);
|
||||||
error_abort();
|
error_abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
17
src/hash.cpp
17
src/hash.cpp
@@ -1,6 +1,9 @@
|
|||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "mbedtls/md.h" // for SHA256
|
#include "mbedtls/md.h" // for SHA256
|
||||||
|
|
||||||
|
// Logging
|
||||||
|
static const char* TAG = "HASH";
|
||||||
|
|
||||||
String get_sha256(String payload) {
|
String get_sha256(String payload) {
|
||||||
byte shaResult[32];
|
byte shaResult[32];
|
||||||
mbedtls_md_context_t ctx;
|
mbedtls_md_context_t ctx;
|
||||||
@@ -21,12 +24,14 @@ String get_sha256(String payload) {
|
|||||||
buffer[sizeof(buffer) - 1] = '\0';
|
buffer[sizeof(buffer) - 1] = '\0';
|
||||||
String hash = String(buffer);
|
String hash = String(buffer);
|
||||||
|
|
||||||
Serial.print("SHA256 payload: ");
|
ESP_LOGI(TAG, "SHA256 payload: %s", payload);
|
||||||
Serial.print(payload);
|
ESP_LOGI(TAG, "SHA256 hash: %s", hash.c_str());
|
||||||
Serial.println();
|
//Serial.print("SHA256 payload: ");
|
||||||
Serial.print("SHA256-Hash: ");
|
//Serial.print(payload);
|
||||||
Serial.print(hash);
|
//Serial.println();
|
||||||
Serial.println();
|
//Serial.print("SHA256-Hash: ");
|
||||||
|
//Serial.print(hash);
|
||||||
|
//Serial.println();
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|||||||
64
src/main.cpp
64
src/main.cpp
@@ -35,6 +35,7 @@ __attribute__((section(".rodata_custom_desc"))) esp_app_desc_t custom_app_desc =
|
|||||||
static const char* TAG = "MAIN";
|
static const char* TAG = "MAIN";
|
||||||
|
|
||||||
uint64_t chipid = ESP.getEfuseMac();
|
uint64_t chipid = ESP.getEfuseMac();
|
||||||
|
uint8_t loglevel = 5;
|
||||||
|
|
||||||
const char* wifi_ssid = "OBPKP61";
|
const char* wifi_ssid = "OBPKP61";
|
||||||
const char* wifi_pass = "keypad61";
|
const char* wifi_pass = "keypad61";
|
||||||
@@ -83,7 +84,7 @@ QueueHandle_t ledQueue = NULL;
|
|||||||
QueueHandle_t keyQueue = NULL;
|
QueueHandle_t keyQueue = NULL;
|
||||||
|
|
||||||
void ledTask(void *parameter) {
|
void ledTask(void *parameter) {
|
||||||
ESP_LOGI(TAG, "Starting LED task");
|
LOGI(TAG, "Starting LED task");
|
||||||
for (;;) {
|
for (;;) {
|
||||||
vTaskDelay(5000);
|
vTaskDelay(5000);
|
||||||
ledcWrite(LEDC_RGBLED_G, 160); // a short activity flash
|
ledcWrite(LEDC_RGBLED_G, 160); // a short activity flash
|
||||||
@@ -93,7 +94,7 @@ void ledTask(void *parameter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sensorTask(void *parameter) {
|
void sensorTask(void *parameter) {
|
||||||
ESP_LOGI(TAG, "Starting sensor task");
|
LOGI(TAG, "Starting sensor task");
|
||||||
for (;;) {
|
for (;;) {
|
||||||
vTaskDelay(10000); // nothing yet
|
vTaskDelay(10000); // nothing yet
|
||||||
}
|
}
|
||||||
@@ -103,7 +104,7 @@ void keyTask(void *parameter) {
|
|||||||
// short key press <= 1s
|
// short key press <= 1s
|
||||||
// medium key press >1s and < 3s
|
// medium key press >1s and < 3s
|
||||||
// long key press >= 3s
|
// long key press >= 3s
|
||||||
ESP_LOGI(TAG, "Starting keyboard task");
|
LOGI(TAG, "Starting keyboard task");
|
||||||
|
|
||||||
constexpr uint8_t NUM_BUTTONS = 7;
|
constexpr uint8_t NUM_BUTTONS = 7;
|
||||||
constexpr gpio_num_t buttonPins[NUM_BUTTONS] = {
|
constexpr gpio_num_t buttonPins[NUM_BUTTONS] = {
|
||||||
@@ -160,12 +161,12 @@ void keyTask(void *parameter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void stopApTimerCallback(TimerHandle_t xTimer) {
|
void stopApTimerCallback(TimerHandle_t xTimer) {
|
||||||
ESP_LOGI(TAG, "reached AP switchoff time: accesspoint switched off ");
|
LOGI(TAG, "reached AP switchoff time: accesspoint switched off ");
|
||||||
WiFi.softAPdisconnect(true);
|
WiFi.softAPdisconnect(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cpuFreqTimerCallback(TimerHandle_t xTimer) {
|
void cpuFreqTimerCallback(TimerHandle_t xTimer) {
|
||||||
ESP_LOGI(TAG, "after 3 minutes: set CPU frequency to 160MHz");
|
LOGI(TAG, "after 3 minutes: set CPU frequency to 160MHz");
|
||||||
setCpuFrequencyMhz(cpuspeed);
|
setCpuFrequencyMhz(cpuspeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,19 +213,20 @@ void setup() {
|
|||||||
digitalWrite(RGBLED_G, LOW);
|
digitalWrite(RGBLED_G, LOW);
|
||||||
digitalWrite(RGBLED_B, LOW);
|
digitalWrite(RGBLED_B, LOW);
|
||||||
|
|
||||||
// Arduino ESP32 logging
|
LOGI(TAG, "Starting ...");
|
||||||
esp_log_level_set("*", ESP_LOG_INFO);
|
|
||||||
esp_log_level_set("default", ESP_LOG_INFO);
|
|
||||||
esp_log_level_set("wifi", ESP_LOG_INFO);
|
|
||||||
esp_log_level_set("esp_timer", ESP_LOG_INFO);
|
|
||||||
esp_log_level_set("spi_flash", ESP_LOG_INFO);
|
|
||||||
esp_log_level_set("arduino", ESP_LOG_INFO);
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Starting ...");
|
|
||||||
|
|
||||||
config.load();
|
config.load();
|
||||||
config.dump();
|
config.dump();
|
||||||
|
|
||||||
|
loglevel = config.getByte("logLevel");
|
||||||
|
if (loglevel > ESP_LOG_VERBOSE) {
|
||||||
|
loglevel = ESP_LOG_VERBOSE;
|
||||||
|
} else if (loglevel < 0) {
|
||||||
|
loglevel = ESP_LOG_NONE;
|
||||||
|
}
|
||||||
|
LOGI(TAG, "Setting loglevel to %d", loglevel);
|
||||||
|
esp_log_level_set("*", static_cast<esp_log_level_t>(loglevel));
|
||||||
|
|
||||||
keycode[0] = config.getByte("key1");
|
keycode[0] = config.getByte("key1");
|
||||||
keycode[1] = config.getByte("key2");
|
keycode[1] = config.getByte("key2");
|
||||||
keycode[2] = config.getByte("key3");
|
keycode[2] = config.getByte("key3");
|
||||||
@@ -240,19 +242,19 @@ void setup() {
|
|||||||
|
|
||||||
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
|
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
|
||||||
if (cause == ESP_SLEEP_WAKEUP_EXT0) {
|
if (cause == ESP_SLEEP_WAKEUP_EXT0) {
|
||||||
ESP_LOGI(TAG, "Wake up by key");
|
LOGI(TAG, "Wake up by key");
|
||||||
} else {
|
} else {
|
||||||
destination = 'A';
|
destination = 'A';
|
||||||
}
|
}
|
||||||
|
|
||||||
// N2K basics
|
// N2K basics
|
||||||
nodeid = N2K_DEFAULT_NODEID;
|
nodeid = N2K_DEFAULT_NODEID;
|
||||||
ESP_LOGI(TAG, "N2K default node is %d", nodeid);
|
LOGI(TAG, "N2K default node is %d", nodeid);
|
||||||
//preferences.begin(PREF_NAME, false);
|
//preferences.begin(PREF_NAME, false);
|
||||||
//nodeid = preferences.getInt("LastNodeId", N2K_DEFAULT_NODEID);
|
//nodeid = preferences.getInt("LastNodeId", N2K_DEFAULT_NODEID);
|
||||||
//preferences.end();
|
//preferences.end();
|
||||||
nodeid = config.getByte("LastNodeId");
|
nodeid = config.getByte("LastNodeId");
|
||||||
ESP_LOGI(TAG, "N2K node id set to %d from preferences", nodeid);
|
LOGI(TAG, "N2K node id set to %d from preferences", nodeid);
|
||||||
|
|
||||||
//cpuspeed = preferences.getInt("cpuSpeed", 160);
|
//cpuspeed = preferences.getInt("cpuSpeed", 160);
|
||||||
cpuspeed = config.getShort("cpuSpeed");
|
cpuspeed = config.getShort("cpuSpeed");
|
||||||
@@ -388,14 +390,14 @@ void setup() {
|
|||||||
// I²C
|
// I²C
|
||||||
// Serial.print("SHT31_LIB_VERSION: ");
|
// Serial.print("SHT31_LIB_VERSION: ");
|
||||||
// Serial.println(SHT31_LIB_VERSION);
|
// Serial.println(SHT31_LIB_VERSION);
|
||||||
ESP_LOGI(TAG, "SHT31_LIB_VERSION: %s", SHT31_LIB_VERSION);
|
LOGI(TAG, "SHT31_LIB_VERSION: %s", SHT31_LIB_VERSION);
|
||||||
Wire.begin(I2C_SDA, I2C_SCL);
|
Wire.begin(I2C_SDA, I2C_SCL);
|
||||||
Wire.setClock(I2C_SPEED);
|
Wire.setClock(I2C_SPEED);
|
||||||
uint16_t stat = sht.readStatus();
|
uint16_t stat = sht.readStatus();
|
||||||
// stat = ffff anscheinend Fehler
|
// stat = ffff anscheinend Fehler
|
||||||
// = 8010 läuft anscheinend
|
// = 8010 läuft anscheinend
|
||||||
sht_available = (stat == 0x8010);
|
sht_available = (stat == 0x8010);
|
||||||
ESP_LOGI(TAG, "SHT31 state=0x%X", stat);
|
LOGI(TAG, "SHT31 state=0x%X", stat);
|
||||||
|
|
||||||
// Additional tests
|
// Additional tests
|
||||||
String passhash = get_sha256("secretTEST");
|
String passhash = get_sha256("secretTEST");
|
||||||
@@ -417,10 +419,10 @@ void setup() {
|
|||||||
ledQueue = xQueueCreate(5, sizeof(uint8_t));
|
ledQueue = xQueueCreate(5, sizeof(uint8_t));
|
||||||
|
|
||||||
if (esp_sleep_is_valid_wakeup_gpio(KEY_DST)) {
|
if (esp_sleep_is_valid_wakeup_gpio(KEY_DST)) {
|
||||||
ESP_LOGI(TAG, "DST-key configured as wakeup-pin");
|
LOGI(TAG, "DST-key configured as wakeup-pin");
|
||||||
esp_sleep_enable_ext0_wakeup(KEY_DST, 0);
|
esp_sleep_enable_ext0_wakeup(KEY_DST, 0);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGI(TAG, "No wakeup feature available! Deep-sleep disabled.");
|
LOGI(TAG, "No wakeup feature available! Deep-sleep disabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cpuspeed < 240) {
|
if (cpuspeed < 240) {
|
||||||
@@ -522,7 +524,7 @@ void send_sensor_temphum(float temp_k, float hum_perc) {
|
|||||||
unsigned char instance = 0;
|
unsigned char instance = 0;
|
||||||
tN2kTempSource temp_src = N2kts_OutsideTemperature; // 1=outside, 2=inside
|
tN2kTempSource temp_src = N2kts_OutsideTemperature; // 1=outside, 2=inside
|
||||||
tN2kHumiditySource hum_src = N2khs_OutsideHumidity; // 0=inside, 1=outside
|
tN2kHumiditySource hum_src = N2khs_OutsideHumidity; // 0=inside, 1=outside
|
||||||
ESP_LOGI(TAG, "Sending temp=%f K, hum=%f %%", temp_k, hum_perc);
|
LOGI(TAG, "Sending temp=%f K, hum=%f %%", temp_k, hum_perc);
|
||||||
SetN2kPGN130312(N2kMsg, SID, instance, temp_src, temp_k);
|
SetN2kPGN130312(N2kMsg, SID, instance, temp_src, temp_k);
|
||||||
NMEA2000.SendMsg(N2kMsg);
|
NMEA2000.SendMsg(N2kMsg);
|
||||||
SetN2kPGN130313(N2kMsg, SID, instance, hum_src, hum_perc);
|
SetN2kPGN130313(N2kMsg, SID, instance, hum_src, hum_perc);
|
||||||
@@ -552,7 +554,7 @@ void loop() {
|
|||||||
ledcWrite(LEDC_LED_C, 0);
|
ledcWrite(LEDC_LED_C, 0);
|
||||||
ledcWrite(LEDC_LED_A, led_brightness);
|
ledcWrite(LEDC_LED_A, led_brightness);
|
||||||
}
|
}
|
||||||
ESP_LOGI(TAG, "New destination=%s", destination);
|
LOGI(TAG, "New destination=%s", destination);
|
||||||
}
|
}
|
||||||
} else if (event.pressType == ButtonPressType::LONG) {
|
} else if (event.pressType == ButtonPressType::LONG) {
|
||||||
shortBeep();
|
shortBeep();
|
||||||
@@ -560,11 +562,11 @@ void loop() {
|
|||||||
if (mode == 'N') {
|
if (mode == 'N') {
|
||||||
mode = 'C';
|
mode = 'C';
|
||||||
ledcWrite(LEDC_RGBLED_B, rgb_brightness); // blue status indicator
|
ledcWrite(LEDC_RGBLED_B, rgb_brightness); // blue status indicator
|
||||||
ESP_LOGI(TAG, "Entering config mode");
|
LOGI(TAG, "Entering config mode");
|
||||||
} else {
|
} else {
|
||||||
mode = 'N';
|
mode = 'N';
|
||||||
ledcWrite(LEDC_RGBLED_B, 0);
|
ledcWrite(LEDC_RGBLED_B, 0);
|
||||||
ESP_LOGI(TAG, "Leaving config mode");
|
LOGI(TAG, "Leaving config mode");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -588,19 +590,19 @@ void loop() {
|
|||||||
switch (event.buttonId) {
|
switch (event.buttonId) {
|
||||||
case BUTTON_1: // switch day/night mode
|
case BUTTON_1: // switch day/night mode
|
||||||
if (ledmode == 'D') {
|
if (ledmode == 'D') {
|
||||||
ESP_LOGI(TAG, "Night mode enabled");
|
LOGI(TAG, "Night mode enabled");
|
||||||
ledmode = 'N';
|
ledmode = 'N';
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGI(TAG, "Day mode enabled");
|
LOGI(TAG, "Day mode enabled");
|
||||||
ledmode = 'D';
|
ledmode = 'D';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BUTTON_2: // switch audio on/off
|
case BUTTON_2: // switch audio on/off
|
||||||
if (audiomode == 'E') {
|
if (audiomode == 'E') {
|
||||||
ESP_LOGI(TAG, "Disabled audio");
|
LOGI(TAG, "Disabled audio");
|
||||||
audiomode = 'D';
|
audiomode = 'D';
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGI(TAG, "Enabled audio");
|
LOGI(TAG, "Enabled audio");
|
||||||
audiomode = 'E';
|
audiomode = 'E';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -618,13 +620,13 @@ void loop() {
|
|||||||
case BUTTON_4: // reserved
|
case BUTTON_4: // reserved
|
||||||
break;
|
break;
|
||||||
case BUTTON_5: // reset
|
case BUTTON_5: // reset
|
||||||
ESP_LOGI(TAG, "Device reset");
|
LOGI(TAG, "Device reset");
|
||||||
esp_rom_uart_tx_wait_idle(0);
|
esp_rom_uart_tx_wait_idle(0);
|
||||||
led_blink(LEDC_RGBLED_G, 3, 4095, 500);
|
led_blink(LEDC_RGBLED_G, 3, 4095, 500);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
break;
|
break;
|
||||||
case BUTTON_6: // deep sleep
|
case BUTTON_6: // deep sleep
|
||||||
ESP_LOGI(TAG, "Going into deep sleep");
|
LOGI(TAG, "Going into deep sleep");
|
||||||
esp_rom_uart_tx_wait_idle(0);
|
esp_rom_uart_tx_wait_idle(0);
|
||||||
led_blink(LEDC_RGBLED_B, 3, 4095, 500);
|
led_blink(LEDC_RGBLED_B, 3, 4095, 500);
|
||||||
rtc_gpio_pullup_en(KEY_DST);
|
rtc_gpio_pullup_en(KEY_DST);
|
||||||
|
|||||||
@@ -7,6 +7,9 @@
|
|||||||
#include <esp32/clk.h> // for cpu frequency
|
#include <esp32/clk.h> // for cpu frequency
|
||||||
#include <Update.h>
|
#include <Update.h>
|
||||||
|
|
||||||
|
// Logging
|
||||||
|
static const char* TAG = "WEB";
|
||||||
|
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
|
|
||||||
class EmbeddedFile;
|
class EmbeddedFile;
|
||||||
@@ -79,7 +82,7 @@ void webserver_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// API fast hack
|
// API fast hack
|
||||||
server.on("/api/capabilities", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/api/capabilities", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
StaticJsonDocument<100> doc;
|
StaticJsonDocument<100> doc;
|
||||||
doc["apPwChange"] = "true";
|
doc["apPwChange"] = "true";
|
||||||
String out;
|
String out;
|
||||||
@@ -87,7 +90,7 @@ void webserver_init() {
|
|||||||
request->send(200, "application/json", out);
|
request->send(200, "application/json", out);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/api/checkpass", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/api/checkpass", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
StaticJsonDocument<100> doc;
|
StaticJsonDocument<100> doc;
|
||||||
doc["status"] = "FAILED";
|
doc["status"] = "FAILED";
|
||||||
String out;
|
String out;
|
||||||
@@ -95,11 +98,11 @@ void webserver_init() {
|
|||||||
request->send(200, "application/json", out);
|
request->send(200, "application/json", out);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/api/config", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/api/config", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
StaticJsonDocument<512> doc;
|
StaticJsonDocument<512> doc;
|
||||||
doc["systemName"] = config.getString("systemName");
|
doc["systemName"] = config.getString("systemName");
|
||||||
doc["systemMode"] = String(config.getChar("systemMode"));
|
doc["systemMode"] = String(config.getChar("systemMode"));
|
||||||
doc["logLevel"] = 0;
|
doc["logLevel"] = loglevel;
|
||||||
doc["version"] = VERSION;
|
doc["version"] = VERSION;
|
||||||
doc["fwtype"] = "unknown"; // TODO ?
|
doc["fwtype"] = "unknown"; // TODO ?
|
||||||
doc["salt"] = "secret";
|
doc["salt"] = "secret";
|
||||||
@@ -127,13 +130,13 @@ void webserver_init() {
|
|||||||
doc["key4long"] = longcode[BUTTON_4];
|
doc["key4long"] = longcode[BUTTON_4];
|
||||||
doc["key5long"] = longcode[BUTTON_5];
|
doc["key5long"] = longcode[BUTTON_5];
|
||||||
doc["key6long"] = longcode[BUTTON_6];
|
doc["key6long"] = longcode[BUTTON_6];
|
||||||
doc["envInterval"] = 5; // config.getShort("envInterval");
|
doc["envInterval"] = config.getShort("envInterval");
|
||||||
String out;
|
String out;
|
||||||
serializeJson(doc, out);
|
serializeJson(doc, out);
|
||||||
request->send(200, "application/json", out);
|
request->send(200, "application/json", out);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/api/resetconfig", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/api/resetconfig", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
StaticJsonDocument<100> doc;
|
StaticJsonDocument<100> doc;
|
||||||
doc["status"] = "FAILED";
|
doc["status"] = "FAILED";
|
||||||
String out;
|
String out;
|
||||||
@@ -141,7 +144,7 @@ void webserver_init() {
|
|||||||
request->send(200, "application/json", out);
|
request->send(200, "application/json", out);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/api/status", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/api/status", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
StaticJsonDocument<200> doc;
|
StaticJsonDocument<200> doc;
|
||||||
doc["version"] = VERSION;
|
doc["version"] = VERSION;
|
||||||
int cpu_freq = esp_clk_cpu_freq() / 1000000;
|
int cpu_freq = esp_clk_cpu_freq() / 1000000;
|
||||||
@@ -153,23 +156,38 @@ void webserver_init() {
|
|||||||
doc["heap"]=(long)xPortGetFreeHeapSize();
|
doc["heap"]=(long)xPortGetFreeHeapSize();
|
||||||
doc["temp"] = String(temp, 1);
|
doc["temp"] = String(temp, 1);
|
||||||
doc["hum"] = String(hum, 1);
|
doc["hum"] = String(hum, 1);
|
||||||
|
switch (globalmode) {
|
||||||
|
case 'K':
|
||||||
|
doc["mode"] = "Keyboard";
|
||||||
|
break;
|
||||||
|
case 'A':
|
||||||
|
doc["mode"] = "Autopilot";
|
||||||
|
break;
|
||||||
|
case 'L':
|
||||||
|
doc["mode"] = "Logbook";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
doc["mode"] = "*unknown*";
|
||||||
|
}
|
||||||
doc["status"] = "OK";
|
doc["status"] = "OK";
|
||||||
String out;
|
String out;
|
||||||
serializeJson(doc, out);
|
serializeJson(doc, out);
|
||||||
request->send(200, "application/json", out);
|
request->send(200, "application/json", out);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/api/fwinfo", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/api/fwinfo", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
StaticJsonDocument<200> doc;
|
StaticJsonDocument<200> doc;
|
||||||
doc["version"] = VERSION;
|
doc["version"] = VERSION;
|
||||||
doc["build_date"] = BUILD_DATE;
|
doc["build_date"] = BUILD_DATE;
|
||||||
doc["build_time"] = BUILD_TIME;
|
doc["build_time"] = BUILD_TIME;
|
||||||
|
doc["idf"] = IDF_VERSION;
|
||||||
String out;
|
String out;
|
||||||
serializeJson(doc, out);
|
serializeJson(doc, out);
|
||||||
request->send(200, "application/json", out);
|
request->send(200, "application/json", out);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/api/setconfig", HTTP_POST, [](AsyncWebServerRequest *request){
|
server.on("/api/setconfig", HTTP_POST, [](AsyncWebServerRequest *request) {
|
||||||
|
LOGD(TAG, "API setconfig called");
|
||||||
StaticJsonDocument<100> doc;
|
StaticJsonDocument<100> doc;
|
||||||
doc["status"] = "FAILED";
|
doc["status"] = "FAILED";
|
||||||
String out;
|
String out;
|
||||||
@@ -177,7 +195,7 @@ void webserver_init() {
|
|||||||
request->send(200, "application/json", out);
|
request->send(200, "application/json", out);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/api/update", HTTP_POST, [](AsyncWebServerRequest *request){
|
server.on("/api/update", HTTP_POST, [](AsyncWebServerRequest *request) {
|
||||||
// the request handler is triggered after the upload has finished...
|
// the request handler is triggered after the upload has finished...
|
||||||
// create the response, add header, and send response
|
// create the response, add header, and send response
|
||||||
|
|
||||||
@@ -207,7 +225,7 @@ void webserver_init() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/api/devicelist", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/api/devicelist", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
// NMEA2000 device list
|
// NMEA2000 device list
|
||||||
AsyncResponseStream *response = request->beginResponseStream("application/json");
|
AsyncResponseStream *response = request->beginResponseStream("application/json");
|
||||||
response->print("[");
|
response->print("[");
|
||||||
|
|||||||
@@ -39,45 +39,49 @@ if (!window.isSecureContext) {
|
|||||||
<button class="infoButton" id="firmwareInfo">?</button>
|
<button class="infoButton" id="firmwareInfo">?</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="row even">
|
<div class="row even">
|
||||||
|
<span class="label">Mode</span>
|
||||||
|
<span class="value" id="mode">---</span>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
<span class="label">MCU-ID</span>
|
<span class="label">MCU-ID</span>
|
||||||
<span class="value" id="chipid">---</span>
|
<span class="value" id="chipid">---</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row even">
|
||||||
<span class="label">CPU speed</span>
|
<span class="label">CPU speed</span>
|
||||||
<span class="value" id="cpuspeed">---</span>
|
<span class="value" id="cpuspeed">---</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="row even">
|
<div class="row">
|
||||||
<span class="label">Free heap</span>
|
<span class="label">Free heap</span>
|
||||||
<span class="value" id="heap">---</span>
|
<span class="value" id="heap">---</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row even">
|
||||||
<span class="label">Uptime</span>
|
<span class="label">Uptime</span>
|
||||||
<span class="value" id="uptime">---</span>
|
<span class="value" id="uptime">---</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="row even">
|
<div class="row">
|
||||||
<span class="label">NMEA2000 State</span>
|
<span class="label">NMEA2000 State</span>
|
||||||
[<span class="value" id="n2knode">---</span>]
|
[<span class="value" id="n2knode">---</span>]
|
||||||
<span class="value" id="n2kstate">UNKNOWN</span>
|
<span class="value" id="n2kstate">UNKNOWN</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row even">
|
||||||
<span class="label">Dest A</span>
|
<span class="label">Dest A</span>
|
||||||
<span class="value" id="destA">---</span>
|
<span class="value" id="destA">---</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="row even">
|
<div class="row">
|
||||||
<span class="label">Dest B</span>
|
<span class="label">Dest B</span>
|
||||||
<span class="value" id="destB">---</span>
|
<span class="value" id="destB">---</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row even">
|
||||||
<span class="label">Dest C</span>
|
<span class="label">Dest C</span>
|
||||||
<span class="value" id="destC">---</span>
|
<span class="value" id="destC">---</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row even">
|
<div class="row">
|
||||||
<span class="label">Sensor: Temperature</span>
|
<span class="label">Sensor: Temperature</span>
|
||||||
<span class="value" id="temp">---</span>°C
|
<span class="value" id="temp">---</span>°C
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row even">
|
||||||
<span class="label">Sensor: Humidity</span>
|
<span class="label">Sensor: Humidity</span>
|
||||||
<span class="value" id="hum">---</span>%
|
<span class="value" id="hum">---</span>%
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1090,7 +1090,8 @@
|
|||||||
let text = "<h3>Firmware details</h3>";
|
let text = "<h3>Firmware details</h3>";
|
||||||
text += "<p><b>Version:</b> " + json.version + "</p>";
|
text += "<p><b>Version:</b> " + json.version + "</p>";
|
||||||
text += "<p><b>Build date:</b> " + json.build_date + "</p>";
|
text += "<p><b>Build date:</b> " + json.build_date + "</p>";
|
||||||
text += "<p><b>Build time:</b> " + json.build_time + "</p>";
|
text += "<p><b>Build time:</b> " + json.build_time + " UTC</p>";
|
||||||
|
text += "<p><b>IDF version:</b> " + json.idf + "</p>";
|
||||||
text += "</p>";
|
text += "</p>";
|
||||||
showOverlay(text, true);
|
showOverlay(text, true);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user