From f86eef66c8163bdafb305ad4055aad0c7645274b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 18 Jan 2023 21:35:51 +0100 Subject: [PATCH 01/54] Simple UDP calls, if wired up a fair bit of this can go again. this is preliminary work --- src/DebugConfiguration.cpp | 241 +++++++++++++++++++++++++++++++++ src/DebugConfiguration.h | 104 +++++++++++++- src/mesh/eth/ethClient.cpp | 27 ++++ src/mesh/http/WiFiAPClient.cpp | 26 ++++ 4 files changed, 395 insertions(+), 3 deletions(-) create mode 100644 src/DebugConfiguration.cpp diff --git a/src/DebugConfiguration.cpp b/src/DebugConfiguration.cpp new file mode 100644 index 000000000..8387170f8 --- /dev/null +++ b/src/DebugConfiguration.cpp @@ -0,0 +1,241 @@ +/* based on https://github.com/arcao/Syslog + +MIT License + +Copyright (c) 2016 Martin Sloup + +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.*/ + +#include "DebugConfiguration.h" + +Syslog::Syslog(UDP &client) { + this->_client = &client; + this->_server = NULL; + this->_port = 0; + this->_deviceHostname = SYSLOG_NILVALUE; + this->_appName = SYSLOG_NILVALUE; + this->_priDefault = LOGLEVEL_KERN; +} + +Syslog &Syslog::server(const char* server, uint16_t port) { + this->_server = server; + this->_port = port; + return *this; +} + +Syslog &Syslog::server(IPAddress ip, uint16_t port) { + this->_ip = ip; + this->_server = NULL; + this->_port = port; + return *this; +} + +Syslog &Syslog::deviceHostname(const char* deviceHostname) { + this->_deviceHostname = (deviceHostname == NULL) ? SYSLOG_NILVALUE : deviceHostname; + return *this; +} + +Syslog &Syslog::appName(const char* appName) { + this->_appName = (appName == NULL) ? SYSLOG_NILVALUE : appName; + return *this; +} + +Syslog &Syslog::defaultPriority(uint16_t pri) { + this->_priDefault = pri; + return *this; +} + +Syslog &Syslog::logMask(uint8_t priMask) { + this->_priMask = priMask; + return *this; +} + +void Syslog::enable() { + this->_enabled = true; +} + +void Syslog::disable() { + this->_enabled = false; +} + +bool Syslog::isEnabled() +{ + return this->_enabled; +} + +bool Syslog::log(uint16_t pri, const __FlashStringHelper *message) { + return this->_sendLog(pri, message); +} + +bool Syslog::log(uint16_t pri, const String &message) { + return this->_sendLog(pri, message.c_str()); +} + +bool Syslog::log(uint16_t pri, const char *message) { + return this->_sendLog(pri, message); +} + +bool Syslog::vlogf(uint16_t pri, const char *fmt, va_list args) { + char *message; + size_t initialLen; + size_t len; + bool result; + + initialLen = strlen(fmt); + + message = new char[initialLen + 1]; + + len = vsnprintf(message, initialLen + 1, fmt, args); + if (len > initialLen) { + delete[] message; + message = new char[len + 1]; + + vsnprintf(message, len + 1, fmt, args); + } + + result = this->_sendLog(pri, message); + + delete[] message; + return result; +} + +bool Syslog::vlogf_P(uint16_t pri, PGM_P fmt_P, va_list args) { + char *message; + size_t initialLen; + size_t len; + bool result; + + initialLen = strlen_P(fmt_P); + + message = new char[initialLen + 1]; + + len = vsnprintf_P(message, initialLen + 1, fmt_P, args); + if (len > initialLen) { + delete[] message; + message = new char[len + 1]; + + vsnprintf(message, len + 1, fmt_P, args); + } + + result = this->_sendLog(pri, message); + + delete[] message; + return result; +} + + +bool Syslog::logf(uint16_t pri, const char *fmt, ...) { + va_list args; + bool result; + + va_start(args, fmt); + result = this->vlogf(pri, fmt, args); + va_end(args); + return result; +} + +bool Syslog::logf_P(uint16_t pri, PGM_P fmt_P, ...) { + va_list args; + bool result; + + va_start(args, fmt_P); + result = this->vlogf_P(pri, fmt_P, args); + va_end(args); + return result; +} + +inline bool Syslog::_sendLog(uint16_t pri, const char *message) { + int result; + + if (!this->_enabled) + return false; + + if ((this->_server == NULL && this->_ip == INADDR_NONE) || this->_port == 0) + return false; + + // Check priority against priMask values. + if ((LOG_MASK(LOG_PRI(pri)) & this->_priMask) == 0) + return true; + + // Set default facility if none specified. + if ((pri & LOG_FACMASK) == 0) + pri = LOG_MAKEPRI(LOG_FAC(this->_priDefault), pri); + + if (this->_server != NULL) { + result = this->_client->beginPacket(this->_server, this->_port); + } else { + result = this->_client->beginPacket(this->_ip, this->_port); + } + + if (result != 1) + return false; + + this->_client->print('<'); + this->_client->print(pri); + this->_client->print(F(">1 - ")); + this->_client->print(this->_deviceHostname); + this->_client->print(' '); + this->_client->print(this->_appName); + this->_client->print(F(" - - - \xEF\xBB\xBF")); + this->_client->print(F("[0]: ")); + this->_client->print(message); + this->_client->endPacket(); + + return true; +} + +inline bool Syslog::_sendLog(uint16_t pri, const __FlashStringHelper *message) { + int result; + + if (!this->_enabled) + return false; + + if ((this->_server == NULL && this->_ip == INADDR_NONE) || this->_port == 0) + return false; + + // Check priority against priMask values. + if ((LOG_MASK(LOG_PRI(pri)) & this->_priMask) == 0) + return true; + + // Set default facility if none specified. + if ((pri & LOG_FACMASK) == 0) + pri = LOG_MAKEPRI(LOG_FAC(this->_priDefault), pri); + + if (this->_server != NULL) { + result = this->_client->beginPacket(this->_server, this->_port); + } else { + result = this->_client->beginPacket(this->_ip, this->_port); + } + + if (result != 1) + return false; + + this->_client->print('<'); + this->_client->print(pri); + this->_client->print(F(">1 - ")); + this->_client->print(this->_deviceHostname); + this->_client->print(' '); + this->_client->print(this->_appName); + this->_client->print(F(" - - - \xEF\xBB\xBF")); + this->_client->print(message); + this->_client->endPacket(); + + + return true; +} \ No newline at end of file diff --git a/src/DebugConfiguration.h b/src/DebugConfiguration.h index 389a35d81..05fb1fdbb 100644 --- a/src/DebugConfiguration.h +++ b/src/DebugConfiguration.h @@ -1,3 +1,6 @@ +#ifndef SYSLOG_H +#define SYSLOG_H + // DEBUG LED #ifndef LED_INVERTED #define LED_INVERTED 0 // define as 1 if LED is active low (on) @@ -14,9 +17,10 @@ #endif #define MESHTASTIC_LOG_LEVEL_DEBUG "DEBUG" -#define MESHTASTIC_LOG_LEVEL_INFO "INFO " -#define MESHTASTIC_LOG_LEVEL_WARN "WARN " +#define MESHTASTIC_LOG_LEVEL_INFO "INFO " +#define MESHTASTIC_LOG_LEVEL_WARN "WARN " #define MESHTASTIC_LOG_LEVEL_ERROR "ERROR" +#define MESHTASTIC_LOG_LEVEL_CRIT "CRIT " #define MESHTASTIC_LOG_LEVEL_TRACE "TRACE" #include "SerialConsole.h" @@ -28,21 +32,72 @@ #define LOG_INFO(...) SEGGER_RTT_printf(0, __VA_ARGS__) #define LOG_WARN(...) SEGGER_RTT_printf(0, __VA_ARGS__) #define LOG_ERROR(...) SEGGER_RTT_printf(0, __VA_ARGS__) +#define LOG_CRIT(...) SEGGER_RTT_printf(0, __VA_ARGS__) +#define LOG_TRACE(...) SEGGER_RTT_printf(0, __VA_ARGS__) #else #ifdef DEBUG_PORT #define LOG_DEBUG(...) DEBUG_PORT.log(MESHTASTIC_LOG_LEVEL_DEBUG, __VA_ARGS__) #define LOG_INFO(...) DEBUG_PORT.log(MESHTASTIC_LOG_LEVEL_INFO, __VA_ARGS__) #define LOG_WARN(...) DEBUG_PORT.log(MESHTASTIC_LOG_LEVEL_WARN, __VA_ARGS__) #define LOG_ERROR(...) DEBUG_PORT.log(MESHTASTIC_LOG_LEVEL_ERROR, __VA_ARGS__) -#define LOG_TRACE(...) DEBUG_PORT.log(MESHTASTIC_LOG_TRACE, __VA_ARGS__) +#define LOG_CRIT(...) DEBUG_PORT.log(MESHTASTIC_LOG_LEVEL_CRIT, __VA_ARGS__) +#define LOG_TRACE(...) DEBUG_PORT.log(MESHTASTIC_LOG_LEVEL_TRACE, __VA_ARGS__) #else #define LOG_DEBUG(...) #define LOG_INFO(...) #define LOG_WARN(...) #define LOG_ERROR(...) +#define LOG_CRIT(...) +#define LOG_TRACE(...) #endif #endif +#define SYSLOG_NILVALUE "-" + +#define SYSLOG_CRIT 2 /* critical conditions */ +#define SYSLOG_ERR 3 /* error conditions */ +#define SYSLOG_WARN 4 /* warning conditions */ +#define SYSLOG_INFO 6 /* informational */ +#define SYSLOG_DEBUG 7 /* debug-level messages */ +// trace does not go out to syslog (yet?) + +#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ + /* extract priority */ +#define LOG_PRI(p) ((p) & LOG_PRIMASK) +#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri)) + +/* facility codes */ +#define LOGLEVEL_KERN (0<<3) /* kernel messages */ +#define LOGLEVEL_USER (1<<3) /* random user-level messages */ +#define LOGLEVEL_MAIL (2<<3) /* mail system */ +#define LOGLEVEL_DAEMON (3<<3) /* system daemons */ +#define LOGLEVEL_AUTH (4<<3) /* security/authorization messages */ +#define LOGLEVEL_SYSLOG (5<<3) /* messages generated internally by syslogd */ +#define LOGLEVEL_LPR (6<<3) /* line printer subsystem */ +#define LOGLEVEL_NEWS (7<<3) /* network news subsystem */ +#define LOGLEVEL_UUCP (8<<3) /* UUCP subsystem */ +#define LOGLEVEL_CRON (9<<3) /* clock daemon */ +#define LOGLEVEL_AUTHPRIV (10<<3) /* security/authorization messages (private) */ +#define LOGLEVEL_FTP (11<<3) /* ftp daemon */ + +/* other codes through 15 reserved for system use */ +#define LOGLEVEL_LOCAL0 (16<<3) /* reserved for local use */ +#define LOGLEVEL_LOCAL1 (17<<3) /* reserved for local use */ +#define LOGLEVEL_LOCAL2 (18<<3) /* reserved for local use */ +#define LOGLEVEL_LOCAL3 (19<<3) /* reserved for local use */ +#define LOGLEVEL_LOCAL4 (20<<3) /* reserved for local use */ +#define LOGLEVEL_LOCAL5 (21<<3) /* reserved for local use */ +#define LOGLEVEL_LOCAL6 (22<<3) /* reserved for local use */ +#define LOGLEVEL_LOCAL7 (23<<3) /* reserved for local use */ + +#define LOG_NFACILITIES 24 /* current number of facilities */ +#define LOG_FACMASK 0x03f8 /* mask to extract facility part */ + /* facility of pri */ +#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) + +#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ +#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ + // ----------------------------------------------------------------------------- // AXP192 (Rev1-specific options) // ----------------------------------------------------------------------------- @@ -52,3 +107,46 @@ // Default Bluetooth PIN #define defaultBLEPin 123456 + +class Syslog { + private: + UDP* _client; + IPAddress _ip; + const char* _server; + uint16_t _port; + const char* _deviceHostname; + const char* _appName; + uint16_t _priDefault; + uint8_t _priMask = 0xff; + bool _enabled = false; + + bool _sendLog(uint16_t pri, const char *message); + bool _sendLog(uint16_t pri, const __FlashStringHelper *message); + + public: + Syslog(UDP &client); + + Syslog &server(const char* server, uint16_t port); + Syslog &server(IPAddress ip, uint16_t port); + Syslog &deviceHostname(const char* deviceHostname); + Syslog &appName(const char* appName); + Syslog &defaultPriority(uint16_t pri = LOGLEVEL_KERN); + Syslog &logMask(uint8_t priMask); + + void enable(); + void disable(); + bool isEnabled(); + + bool log(uint16_t pri, const __FlashStringHelper *message); + bool log(uint16_t pri, const String &message); + bool log(uint16_t pri, const char *message); + + bool vlogf(uint16_t pri, const char *fmt, va_list args) __attribute__((format(printf, 3, 0))); + bool vlogf_P(uint16_t pri, PGM_P fmt_P, va_list args) __attribute__((format(printf, 3, 0))); + + bool logf(uint16_t pri, const char *fmt, ...) __attribute__((format(printf, 3, 4))); + + bool logf_P(uint16_t pri, PGM_P fmt_P, ...) __attribute__((format(printf, 3, 4))); +}; + +#endif \ No newline at end of file diff --git a/src/mesh/eth/ethClient.cpp b/src/mesh/eth/ethClient.cpp index dce04b191..a80265b03 100644 --- a/src/mesh/eth/ethClient.cpp +++ b/src/mesh/eth/ethClient.cpp @@ -17,6 +17,9 @@ NTPClient timeClient(ntpUDP, config.network.ntp_server); uint32_t ntp_renew = 0; #endif +EthernetUDP syslogClient; +Syslog syslog(syslogClient); + bool ethStartupComplete = 0; using namespace concurrency; @@ -36,6 +39,27 @@ static int32_t reconnectETH() timeClient.begin(); timeClient.setUpdateInterval(60 * 60); // Update once an hour #endif + + if(config.network.rsyslog_server[0]) { + LOG_INFO("Starting Syslog client\n"); + // Defaults + int serverPort = 514; + const char *serverAddr = moduleConfig.mqtt.address; + String server = String(serverAddr); + int delimIndex = server.indexOf(':'); + if (delimIndex > 0) { + String port = server.substring(delimIndex + 1, server.length()); + server[delimIndex] = 0; + serverPort = port.toInt(); + serverAddr = server.c_str(); + } + syslog.server(serverAddr, serverPort); + syslog.deviceHostname(WiFi.getHostname()); + syslog.appName("Meshtastic"); + syslog.defaultPriority(LOGLEVEL_USER); + syslog.enable(); + } + // initWebServer(); initApiServer(); @@ -138,10 +162,13 @@ bool initEthernet() bool isEthernetAvailable() { if (!config.network.eth_enabled) { + syslog.disable(); return false; } else if (Ethernet.hardwareStatus() == EthernetNoHardware) { + syslog.disable(); return false; } else if (Ethernet.linkStatus() == LinkOFF) { + syslog.disable(); return false; } else { return true; diff --git a/src/mesh/http/WiFiAPClient.cpp b/src/mesh/http/WiFiAPClient.cpp index 1139c305e..e488ecb77 100644 --- a/src/mesh/http/WiFiAPClient.cpp +++ b/src/mesh/http/WiFiAPClient.cpp @@ -39,6 +39,9 @@ unsigned long lastrun_ntp = 0; bool needReconnect = true; // If we create our reconnector, run it once at the beginning +WiFiUDP syslogClient; +Syslog syslog(syslogClient); + Periodic *wifiReconnect; static int32_t reconnectWiFi() @@ -135,6 +138,26 @@ static void onNetworkConnected() timeClient.setUpdateInterval(60 * 60); // Update once an hour #endif + if(config.network.rsyslog_server[0]) { + LOG_INFO("Starting Syslog client\n"); + // Defaults + int serverPort = 514; + const char *serverAddr = moduleConfig.mqtt.address; + String server = String(serverAddr); + int delimIndex = server.indexOf(':'); + if (delimIndex > 0) { + String port = server.substring(delimIndex + 1, server.length()); + server[delimIndex] = 0; + serverPort = port.toInt(); + serverAddr = server.c_str(); + } + syslog.server(serverAddr, serverPort); + syslog.deviceHostname(WiFi.getHostname()); + syslog.appName("Meshtastic"); + syslog.defaultPriority(LOGLEVEL_USER); + syslog.enable(); + } + initWebServer(); initApiServer(); @@ -225,6 +248,7 @@ static void WiFiEvent(WiFiEvent_t event) break; case ARDUINO_EVENT_WIFI_STA_STOP: LOG_INFO("WiFi station stopped\n"); + syslog.disable(); break; case ARDUINO_EVENT_WIFI_STA_CONNECTED: LOG_INFO("Connected to access point\n"); @@ -232,6 +256,7 @@ static void WiFiEvent(WiFiEvent_t event) case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: LOG_INFO("Disconnected from WiFi access point\n"); WiFi.disconnect(false, true); + syslog.disable(); needReconnect = true; wifiReconnect->setIntervalFromNow(1000); break; @@ -248,6 +273,7 @@ static void WiFiEvent(WiFiEvent_t event) case ARDUINO_EVENT_WIFI_STA_LOST_IP: LOG_INFO("Lost IP address and IP address is reset to 0\n"); WiFi.disconnect(false, true); + syslog.disable(); needReconnect = true; wifiReconnect->setIntervalFromNow(1000); break; From ff029ad752b10a26264da5d052796816c64d27d5 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 18 Jan 2023 15:37:23 -0600 Subject: [PATCH 02/54] Formatting --- src/DebugConfiguration.cpp | 332 +++++++++++++++++---------------- src/DebugConfiguration.h | 93 ++++----- src/mesh/eth/ethClient.cpp | 37 ++-- src/mesh/http/WiFiAPClient.cpp | 21 +-- 4 files changed, 251 insertions(+), 232 deletions(-) diff --git a/src/DebugConfiguration.cpp b/src/DebugConfiguration.cpp index 8387170f8..47cb21c98 100644 --- a/src/DebugConfiguration.cpp +++ b/src/DebugConfiguration.cpp @@ -24,218 +24,234 @@ SOFTWARE.*/ #include "DebugConfiguration.h" -Syslog::Syslog(UDP &client) { - this->_client = &client; - this->_server = NULL; - this->_port = 0; - this->_deviceHostname = SYSLOG_NILVALUE; - this->_appName = SYSLOG_NILVALUE; - this->_priDefault = LOGLEVEL_KERN; +Syslog::Syslog(UDP &client) +{ + this->_client = &client; + this->_server = NULL; + this->_port = 0; + this->_deviceHostname = SYSLOG_NILVALUE; + this->_appName = SYSLOG_NILVALUE; + this->_priDefault = LOGLEVEL_KERN; } -Syslog &Syslog::server(const char* server, uint16_t port) { - this->_server = server; - this->_port = port; - return *this; +Syslog &Syslog::server(const char *server, uint16_t port) +{ + this->_server = server; + this->_port = port; + return *this; } -Syslog &Syslog::server(IPAddress ip, uint16_t port) { - this->_ip = ip; - this->_server = NULL; - this->_port = port; - return *this; +Syslog &Syslog::server(IPAddress ip, uint16_t port) +{ + this->_ip = ip; + this->_server = NULL; + this->_port = port; + return *this; } -Syslog &Syslog::deviceHostname(const char* deviceHostname) { - this->_deviceHostname = (deviceHostname == NULL) ? SYSLOG_NILVALUE : deviceHostname; - return *this; +Syslog &Syslog::deviceHostname(const char *deviceHostname) +{ + this->_deviceHostname = (deviceHostname == NULL) ? SYSLOG_NILVALUE : deviceHostname; + return *this; } -Syslog &Syslog::appName(const char* appName) { - this->_appName = (appName == NULL) ? SYSLOG_NILVALUE : appName; - return *this; +Syslog &Syslog::appName(const char *appName) +{ + this->_appName = (appName == NULL) ? SYSLOG_NILVALUE : appName; + return *this; } -Syslog &Syslog::defaultPriority(uint16_t pri) { - this->_priDefault = pri; - return *this; +Syslog &Syslog::defaultPriority(uint16_t pri) +{ + this->_priDefault = pri; + return *this; } -Syslog &Syslog::logMask(uint8_t priMask) { - this->_priMask = priMask; - return *this; +Syslog &Syslog::logMask(uint8_t priMask) +{ + this->_priMask = priMask; + return *this; } -void Syslog::enable() { - this->_enabled = true; +void Syslog::enable() +{ + this->_enabled = true; } -void Syslog::disable() { - this->_enabled = false; +void Syslog::disable() +{ + this->_enabled = false; } bool Syslog::isEnabled() { - return this->_enabled; + return this->_enabled; } -bool Syslog::log(uint16_t pri, const __FlashStringHelper *message) { - return this->_sendLog(pri, message); +bool Syslog::log(uint16_t pri, const __FlashStringHelper *message) +{ + return this->_sendLog(pri, message); } -bool Syslog::log(uint16_t pri, const String &message) { - return this->_sendLog(pri, message.c_str()); +bool Syslog::log(uint16_t pri, const String &message) +{ + return this->_sendLog(pri, message.c_str()); } -bool Syslog::log(uint16_t pri, const char *message) { - return this->_sendLog(pri, message); +bool Syslog::log(uint16_t pri, const char *message) +{ + return this->_sendLog(pri, message); } -bool Syslog::vlogf(uint16_t pri, const char *fmt, va_list args) { - char *message; - size_t initialLen; - size_t len; - bool result; +bool Syslog::vlogf(uint16_t pri, const char *fmt, va_list args) +{ + char *message; + size_t initialLen; + size_t len; + bool result; - initialLen = strlen(fmt); + initialLen = strlen(fmt); - message = new char[initialLen + 1]; + message = new char[initialLen + 1]; + + len = vsnprintf(message, initialLen + 1, fmt, args); + if (len > initialLen) { + delete[] message; + message = new char[len + 1]; + + vsnprintf(message, len + 1, fmt, args); + } + + result = this->_sendLog(pri, message); - len = vsnprintf(message, initialLen + 1, fmt, args); - if (len > initialLen) { delete[] message; - message = new char[len + 1]; - - vsnprintf(message, len + 1, fmt, args); - } - - result = this->_sendLog(pri, message); - - delete[] message; - return result; + return result; } -bool Syslog::vlogf_P(uint16_t pri, PGM_P fmt_P, va_list args) { - char *message; - size_t initialLen; - size_t len; - bool result; +bool Syslog::vlogf_P(uint16_t pri, PGM_P fmt_P, va_list args) +{ + char *message; + size_t initialLen; + size_t len; + bool result; - initialLen = strlen_P(fmt_P); + initialLen = strlen_P(fmt_P); - message = new char[initialLen + 1]; + message = new char[initialLen + 1]; + + len = vsnprintf_P(message, initialLen + 1, fmt_P, args); + if (len > initialLen) { + delete[] message; + message = new char[len + 1]; + + vsnprintf(message, len + 1, fmt_P, args); + } + + result = this->_sendLog(pri, message); - len = vsnprintf_P(message, initialLen + 1, fmt_P, args); - if (len > initialLen) { delete[] message; - message = new char[len + 1]; - - vsnprintf(message, len + 1, fmt_P, args); - } - - result = this->_sendLog(pri, message); - - delete[] message; - return result; + return result; } +bool Syslog::logf(uint16_t pri, const char *fmt, ...) +{ + va_list args; + bool result; -bool Syslog::logf(uint16_t pri, const char *fmt, ...) { - va_list args; - bool result; - - va_start(args, fmt); - result = this->vlogf(pri, fmt, args); - va_end(args); - return result; + va_start(args, fmt); + result = this->vlogf(pri, fmt, args); + va_end(args); + return result; } -bool Syslog::logf_P(uint16_t pri, PGM_P fmt_P, ...) { - va_list args; - bool result; +bool Syslog::logf_P(uint16_t pri, PGM_P fmt_P, ...) +{ + va_list args; + bool result; - va_start(args, fmt_P); - result = this->vlogf_P(pri, fmt_P, args); - va_end(args); - return result; + va_start(args, fmt_P); + result = this->vlogf_P(pri, fmt_P, args); + va_end(args); + return result; } -inline bool Syslog::_sendLog(uint16_t pri, const char *message) { - int result; +inline bool Syslog::_sendLog(uint16_t pri, const char *message) +{ + int result; - if (!this->_enabled) - return false; + if (!this->_enabled) + return false; - if ((this->_server == NULL && this->_ip == INADDR_NONE) || this->_port == 0) - return false; + if ((this->_server == NULL && this->_ip == INADDR_NONE) || this->_port == 0) + return false; + + // Check priority against priMask values. + if ((LOG_MASK(LOG_PRI(pri)) & this->_priMask) == 0) + return true; + + // Set default facility if none specified. + if ((pri & LOG_FACMASK) == 0) + pri = LOG_MAKEPRI(LOG_FAC(this->_priDefault), pri); + + if (this->_server != NULL) { + result = this->_client->beginPacket(this->_server, this->_port); + } else { + result = this->_client->beginPacket(this->_ip, this->_port); + } + + if (result != 1) + return false; + + this->_client->print('<'); + this->_client->print(pri); + this->_client->print(F(">1 - ")); + this->_client->print(this->_deviceHostname); + this->_client->print(' '); + this->_client->print(this->_appName); + this->_client->print(F(" - - - \xEF\xBB\xBF")); + this->_client->print(F("[0]: ")); + this->_client->print(message); + this->_client->endPacket(); - // Check priority against priMask values. - if ((LOG_MASK(LOG_PRI(pri)) & this->_priMask) == 0) return true; - - // Set default facility if none specified. - if ((pri & LOG_FACMASK) == 0) - pri = LOG_MAKEPRI(LOG_FAC(this->_priDefault), pri); - - if (this->_server != NULL) { - result = this->_client->beginPacket(this->_server, this->_port); - } else { - result = this->_client->beginPacket(this->_ip, this->_port); - } - - if (result != 1) - return false; - - this->_client->print('<'); - this->_client->print(pri); - this->_client->print(F(">1 - ")); - this->_client->print(this->_deviceHostname); - this->_client->print(' '); - this->_client->print(this->_appName); - this->_client->print(F(" - - - \xEF\xBB\xBF")); - this->_client->print(F("[0]: ")); - this->_client->print(message); - this->_client->endPacket(); - - return true; } -inline bool Syslog::_sendLog(uint16_t pri, const __FlashStringHelper *message) { - int result; +inline bool Syslog::_sendLog(uint16_t pri, const __FlashStringHelper *message) +{ + int result; - if (!this->_enabled) - return false; + if (!this->_enabled) + return false; - if ((this->_server == NULL && this->_ip == INADDR_NONE) || this->_port == 0) - return false; + if ((this->_server == NULL && this->_ip == INADDR_NONE) || this->_port == 0) + return false; + + // Check priority against priMask values. + if ((LOG_MASK(LOG_PRI(pri)) & this->_priMask) == 0) + return true; + + // Set default facility if none specified. + if ((pri & LOG_FACMASK) == 0) + pri = LOG_MAKEPRI(LOG_FAC(this->_priDefault), pri); + + if (this->_server != NULL) { + result = this->_client->beginPacket(this->_server, this->_port); + } else { + result = this->_client->beginPacket(this->_ip, this->_port); + } + + if (result != 1) + return false; + + this->_client->print('<'); + this->_client->print(pri); + this->_client->print(F(">1 - ")); + this->_client->print(this->_deviceHostname); + this->_client->print(' '); + this->_client->print(this->_appName); + this->_client->print(F(" - - - \xEF\xBB\xBF")); + this->_client->print(message); + this->_client->endPacket(); - // Check priority against priMask values. - if ((LOG_MASK(LOG_PRI(pri)) & this->_priMask) == 0) return true; - - // Set default facility if none specified. - if ((pri & LOG_FACMASK) == 0) - pri = LOG_MAKEPRI(LOG_FAC(this->_priDefault), pri); - - if (this->_server != NULL) { - result = this->_client->beginPacket(this->_server, this->_port); - } else { - result = this->_client->beginPacket(this->_ip, this->_port); - } - - if (result != 1) - return false; - - this->_client->print('<'); - this->_client->print(pri); - this->_client->print(F(">1 - ")); - this->_client->print(this->_deviceHostname); - this->_client->print(' '); - this->_client->print(this->_appName); - this->_client->print(F(" - - - \xEF\xBB\xBF")); - this->_client->print(message); - this->_client->endPacket(); - - - return true; } \ No newline at end of file diff --git a/src/DebugConfiguration.h b/src/DebugConfiguration.h index 05fb1fdbb..0e113813a 100644 --- a/src/DebugConfiguration.h +++ b/src/DebugConfiguration.h @@ -1,5 +1,5 @@ #ifndef SYSLOG_H -#define SYSLOG_H +#define SYSLOG_H // DEBUG LED #ifndef LED_INVERTED @@ -17,10 +17,10 @@ #endif #define MESHTASTIC_LOG_LEVEL_DEBUG "DEBUG" -#define MESHTASTIC_LOG_LEVEL_INFO "INFO " -#define MESHTASTIC_LOG_LEVEL_WARN "WARN " +#define MESHTASTIC_LOG_LEVEL_INFO "INFO " +#define MESHTASTIC_LOG_LEVEL_WARN "WARN " #define MESHTASTIC_LOG_LEVEL_ERROR "ERROR" -#define MESHTASTIC_LOG_LEVEL_CRIT "CRIT " +#define MESHTASTIC_LOG_LEVEL_CRIT "CRIT " #define MESHTASTIC_LOG_LEVEL_TRACE "TRACE" #include "SerialConsole.h" @@ -54,49 +54,49 @@ #define SYSLOG_NILVALUE "-" -#define SYSLOG_CRIT 2 /* critical conditions */ -#define SYSLOG_ERR 3 /* error conditions */ -#define SYSLOG_WARN 4 /* warning conditions */ -#define SYSLOG_INFO 6 /* informational */ +#define SYSLOG_CRIT 2 /* critical conditions */ +#define SYSLOG_ERR 3 /* error conditions */ +#define SYSLOG_WARN 4 /* warning conditions */ +#define SYSLOG_INFO 6 /* informational */ #define SYSLOG_DEBUG 7 /* debug-level messages */ // trace does not go out to syslog (yet?) -#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ - /* extract priority */ -#define LOG_PRI(p) ((p) & LOG_PRIMASK) +#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ + /* extract priority */ +#define LOG_PRI(p) ((p)&LOG_PRIMASK) #define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri)) /* facility codes */ -#define LOGLEVEL_KERN (0<<3) /* kernel messages */ -#define LOGLEVEL_USER (1<<3) /* random user-level messages */ -#define LOGLEVEL_MAIL (2<<3) /* mail system */ -#define LOGLEVEL_DAEMON (3<<3) /* system daemons */ -#define LOGLEVEL_AUTH (4<<3) /* security/authorization messages */ -#define LOGLEVEL_SYSLOG (5<<3) /* messages generated internally by syslogd */ -#define LOGLEVEL_LPR (6<<3) /* line printer subsystem */ -#define LOGLEVEL_NEWS (7<<3) /* network news subsystem */ -#define LOGLEVEL_UUCP (8<<3) /* UUCP subsystem */ -#define LOGLEVEL_CRON (9<<3) /* clock daemon */ -#define LOGLEVEL_AUTHPRIV (10<<3) /* security/authorization messages (private) */ -#define LOGLEVEL_FTP (11<<3) /* ftp daemon */ +#define LOGLEVEL_KERN (0 << 3) /* kernel messages */ +#define LOGLEVEL_USER (1 << 3) /* random user-level messages */ +#define LOGLEVEL_MAIL (2 << 3) /* mail system */ +#define LOGLEVEL_DAEMON (3 << 3) /* system daemons */ +#define LOGLEVEL_AUTH (4 << 3) /* security/authorization messages */ +#define LOGLEVEL_SYSLOG (5 << 3) /* messages generated internally by syslogd */ +#define LOGLEVEL_LPR (6 << 3) /* line printer subsystem */ +#define LOGLEVEL_NEWS (7 << 3) /* network news subsystem */ +#define LOGLEVEL_UUCP (8 << 3) /* UUCP subsystem */ +#define LOGLEVEL_CRON (9 << 3) /* clock daemon */ +#define LOGLEVEL_AUTHPRIV (10 << 3) /* security/authorization messages (private) */ +#define LOGLEVEL_FTP (11 << 3) /* ftp daemon */ /* other codes through 15 reserved for system use */ -#define LOGLEVEL_LOCAL0 (16<<3) /* reserved for local use */ -#define LOGLEVEL_LOCAL1 (17<<3) /* reserved for local use */ -#define LOGLEVEL_LOCAL2 (18<<3) /* reserved for local use */ -#define LOGLEVEL_LOCAL3 (19<<3) /* reserved for local use */ -#define LOGLEVEL_LOCAL4 (20<<3) /* reserved for local use */ -#define LOGLEVEL_LOCAL5 (21<<3) /* reserved for local use */ -#define LOGLEVEL_LOCAL6 (22<<3) /* reserved for local use */ -#define LOGLEVEL_LOCAL7 (23<<3) /* reserved for local use */ +#define LOGLEVEL_LOCAL0 (16 << 3) /* reserved for local use */ +#define LOGLEVEL_LOCAL1 (17 << 3) /* reserved for local use */ +#define LOGLEVEL_LOCAL2 (18 << 3) /* reserved for local use */ +#define LOGLEVEL_LOCAL3 (19 << 3) /* reserved for local use */ +#define LOGLEVEL_LOCAL4 (20 << 3) /* reserved for local use */ +#define LOGLEVEL_LOCAL5 (21 << 3) /* reserved for local use */ +#define LOGLEVEL_LOCAL6 (22 << 3) /* reserved for local use */ +#define LOGLEVEL_LOCAL7 (23 << 3) /* reserved for local use */ -#define LOG_NFACILITIES 24 /* current number of facilities */ -#define LOG_FACMASK 0x03f8 /* mask to extract facility part */ - /* facility of pri */ -#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) +#define LOG_NFACILITIES 24 /* current number of facilities */ +#define LOG_FACMASK 0x03f8 /* mask to extract facility part */ + /* facility of pri */ +#define LOG_FAC(p) (((p)&LOG_FACMASK) >> 3) -#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ -#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ +#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ +#define LOG_UPTO(pri) ((1 << ((pri) + 1)) - 1) /* all priorities through pri */ // ----------------------------------------------------------------------------- // AXP192 (Rev1-specific options) @@ -108,14 +108,15 @@ // Default Bluetooth PIN #define defaultBLEPin 123456 -class Syslog { +class Syslog +{ private: - UDP* _client; + UDP *_client; IPAddress _ip; - const char* _server; + const char *_server; uint16_t _port; - const char* _deviceHostname; - const char* _appName; + const char *_deviceHostname; + const char *_appName; uint16_t _priDefault; uint8_t _priMask = 0xff; bool _enabled = false; @@ -126,10 +127,10 @@ class Syslog { public: Syslog(UDP &client); - Syslog &server(const char* server, uint16_t port); + Syslog &server(const char *server, uint16_t port); Syslog &server(IPAddress ip, uint16_t port); - Syslog &deviceHostname(const char* deviceHostname); - Syslog &appName(const char* appName); + Syslog &deviceHostname(const char *deviceHostname); + Syslog &appName(const char *appName); Syslog &defaultPriority(uint16_t pri = LOGLEVEL_KERN); Syslog &logMask(uint8_t priMask); @@ -143,7 +144,7 @@ class Syslog { bool vlogf(uint16_t pri, const char *fmt, va_list args) __attribute__((format(printf, 3, 0))); bool vlogf_P(uint16_t pri, PGM_P fmt_P, va_list args) __attribute__((format(printf, 3, 0))); - + bool logf(uint16_t pri, const char *fmt, ...) __attribute__((format(printf, 3, 4))); bool logf_P(uint16_t pri, PGM_P fmt_P, ...) __attribute__((format(printf, 3, 4))); diff --git a/src/mesh/eth/ethClient.cpp b/src/mesh/eth/ethClient.cpp index a80265b03..1aad323f9 100644 --- a/src/mesh/eth/ethClient.cpp +++ b/src/mesh/eth/ethClient.cpp @@ -2,11 +2,11 @@ #include "NodeDB.h" #include "RTC.h" #include "concurrency/Periodic.h" -#include -#include -#include "target_specific.h" #include "mesh/api/ethServerAPI.h" #include "mqtt/MQTT.h" +#include "target_specific.h" +#include +#include #ifndef DISABLE_NTP #include @@ -38,9 +38,9 @@ static int32_t reconnectETH() LOG_INFO("Starting NTP time client\n"); timeClient.begin(); timeClient.setUpdateInterval(60 * 60); // Update once an hour -#endif +#endif - if(config.network.rsyslog_server[0]) { + if (config.network.rsyslog_server[0]) { LOG_INFO("Starting Syslog client\n"); // Defaults int serverPort = 514; @@ -74,7 +74,7 @@ static int32_t reconnectETH() #ifndef DISABLE_NTP if (isEthernetAvailable() && (ntp_renew < millis())) { - + LOG_INFO("Updating NTP time from %s\n", config.network.ntp_server); if (timeClient.update()) { LOG_DEBUG("NTP Request Success - Setting RTCQualityNTP if needed\n"); @@ -104,12 +104,12 @@ bool initEthernet() #ifdef PIN_ETHERNET_RESET pinMode(PIN_ETHERNET_RESET, OUTPUT); - digitalWrite(PIN_ETHERNET_RESET, LOW); // Reset Time. + digitalWrite(PIN_ETHERNET_RESET, LOW); // Reset Time. delay(100); - digitalWrite(PIN_ETHERNET_RESET, HIGH); // Reset Time. + digitalWrite(PIN_ETHERNET_RESET, HIGH); // Reset Time. #endif - Ethernet.init( ETH_SPI_PORT, PIN_ETHERNET_SS ); + Ethernet.init(ETH_SPI_PORT, PIN_ETHERNET_SS); uint8_t mac[6]; @@ -118,7 +118,7 @@ bool initEthernet() // createSSLCert(); getMacAddr(mac); // FIXME use the BLE MAC for now... - mac[0] &= 0xfe; // Make sure this is not a multicast MAC + mac[0] &= 0xfe; // Make sure this is not a multicast MAC if (config.network.address_mode == Config_NetworkConfig_AddressMode_DHCP) { LOG_INFO("starting Ethernet DHCP\n"); @@ -138,15 +138,19 @@ bool initEthernet() } else if (Ethernet.linkStatus() == LinkOFF) { LOG_ERROR("Ethernet cable is not connected.\n"); return false; - } else{ + } else { LOG_ERROR("Unknown Ethernet error.\n"); return false; } } else { - LOG_INFO("Local IP %u.%u.%u.%u\n",Ethernet.localIP()[0], Ethernet.localIP()[1], Ethernet.localIP()[2], Ethernet.localIP()[3]); - LOG_INFO("Subnet Mask %u.%u.%u.%u\n",Ethernet.subnetMask()[0], Ethernet.subnetMask()[1], Ethernet.subnetMask()[2], Ethernet.subnetMask()[3]); - LOG_INFO("Gateway IP %u.%u.%u.%u\n",Ethernet.gatewayIP()[0], Ethernet.gatewayIP()[1], Ethernet.gatewayIP()[2], Ethernet.gatewayIP()[3]); - LOG_INFO("DNS Server IP %u.%u.%u.%u\n",Ethernet.dnsServerIP()[0], Ethernet.dnsServerIP()[1], Ethernet.dnsServerIP()[2], Ethernet.dnsServerIP()[3]); + LOG_INFO("Local IP %u.%u.%u.%u\n", Ethernet.localIP()[0], Ethernet.localIP()[1], Ethernet.localIP()[2], + Ethernet.localIP()[3]); + LOG_INFO("Subnet Mask %u.%u.%u.%u\n", Ethernet.subnetMask()[0], Ethernet.subnetMask()[1], Ethernet.subnetMask()[2], + Ethernet.subnetMask()[3]); + LOG_INFO("Gateway IP %u.%u.%u.%u\n", Ethernet.gatewayIP()[0], Ethernet.gatewayIP()[1], Ethernet.gatewayIP()[2], + Ethernet.gatewayIP()[3]); + LOG_INFO("DNS Server IP %u.%u.%u.%u\n", Ethernet.dnsServerIP()[0], Ethernet.dnsServerIP()[1], + Ethernet.dnsServerIP()[2], Ethernet.dnsServerIP()[3]); } ethEvent = new Periodic("ethConnect", reconnectETH); @@ -159,7 +163,8 @@ bool initEthernet() } } -bool isEthernetAvailable() { +bool isEthernetAvailable() +{ if (!config.network.eth_enabled) { syslog.disable(); diff --git a/src/mesh/http/WiFiAPClient.cpp b/src/mesh/http/WiFiAPClient.cpp index e488ecb77..148c8efcf 100644 --- a/src/mesh/http/WiFiAPClient.cpp +++ b/src/mesh/http/WiFiAPClient.cpp @@ -1,17 +1,17 @@ +#include "mesh/http/WiFiAPClient.h" #include "NodeDB.h" #include "RTC.h" #include "concurrency/Periodic.h" -#include "mesh/http/WiFiAPClient.h" #include "configuration.h" #include "main.h" -#include "mesh/http/WebServer.h" #include "mesh/api/WiFiServerAPI.h" +#include "mesh/http/WebServer.h" #include "mqtt/MQTT.h" #include "target_specific.h" #include -#include #include #include +#include #ifndef DISABLE_NTP #include @@ -50,7 +50,7 @@ static int32_t reconnectWiFi() const char *wifiPsw = config.network.wifi_psk; if (config.network.wifi_enabled && needReconnect) { - + if (!*wifiPsw) // Treat empty password as no password wifiPsw = NULL; @@ -58,7 +58,7 @@ static int32_t reconnectWiFi() // Make sure we clear old connection credentials WiFi.disconnect(false, true); - LOG_INFO("Reconnecting to WiFi access point %s\n",wifiName); + LOG_INFO("Reconnecting to WiFi access point %s\n", wifiName); delay(5000); @@ -69,7 +69,7 @@ static int32_t reconnectWiFi() #ifndef DISABLE_NTP if (WiFi.isConnected() && (((millis() - lastrun_ntp) > 43200000) || (lastrun_ntp == 0))) { // every 12 hours - LOG_DEBUG("Updating NTP time from %s\n",config.network.ntp_server); + LOG_DEBUG("Updating NTP time from %s\n", config.network.ntp_server); if (timeClient.update()) { LOG_DEBUG("NTP Request Success - Setting RTCQualityNTP if needed\n"); @@ -138,7 +138,7 @@ static void onNetworkConnected() timeClient.setUpdateInterval(60 * 60); // Update once an hour #endif - if(config.network.rsyslog_server[0]) { + if (config.network.rsyslog_server[0]) { LOG_INFO("Starting Syslog client\n"); // Defaults int serverPort = 514; @@ -195,10 +195,8 @@ bool initWifi() WiFi.setAutoReconnect(true); WiFi.setSleep(false); if (config.network.address_mode == Config_NetworkConfig_AddressMode_STATIC && config.network.ipv4_config.ip != 0) { - WiFi.config(config.network.ipv4_config.ip, - config.network.ipv4_config.gateway, - config.network.ipv4_config.subnet, - config.network.ipv4_config.dns, + WiFi.config(config.network.ipv4_config.ip, config.network.ipv4_config.gateway, config.network.ipv4_config.subnet, + config.network.ipv4_config.dns, config.network.ipv4_config.dns); // Wifi wants two DNS servers... set both to the same value } @@ -207,7 +205,6 @@ bool initWifi() WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) { - LOG_WARN("WiFi lost connection. Reason: %d\n", info.wifi_sta_disconnected.reason); /* From 661894f9f91db98a9b16897216d3f13aa8b3ecea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 31 Jan 2023 14:20:04 +0100 Subject: [PATCH 03/54] fix nRF52 and linter errors. --- src/DebugConfiguration.cpp | 36 ---------------------------------- src/DebugConfiguration.h | 9 +++++---- src/mesh/eth/ethClient.cpp | 3 ++- src/mesh/http/WiFiAPClient.cpp | 2 +- 4 files changed, 8 insertions(+), 42 deletions(-) diff --git a/src/DebugConfiguration.cpp b/src/DebugConfiguration.cpp index 47cb21c98..bac67c591 100644 --- a/src/DebugConfiguration.cpp +++ b/src/DebugConfiguration.cpp @@ -128,31 +128,6 @@ bool Syslog::vlogf(uint16_t pri, const char *fmt, va_list args) return result; } -bool Syslog::vlogf_P(uint16_t pri, PGM_P fmt_P, va_list args) -{ - char *message; - size_t initialLen; - size_t len; - bool result; - - initialLen = strlen_P(fmt_P); - - message = new char[initialLen + 1]; - - len = vsnprintf_P(message, initialLen + 1, fmt_P, args); - if (len > initialLen) { - delete[] message; - message = new char[len + 1]; - - vsnprintf(message, len + 1, fmt_P, args); - } - - result = this->_sendLog(pri, message); - - delete[] message; - return result; -} - bool Syslog::logf(uint16_t pri, const char *fmt, ...) { va_list args; @@ -164,17 +139,6 @@ bool Syslog::logf(uint16_t pri, const char *fmt, ...) return result; } -bool Syslog::logf_P(uint16_t pri, PGM_P fmt_P, ...) -{ - va_list args; - bool result; - - va_start(args, fmt_P); - result = this->vlogf_P(pri, fmt_P, args); - va_end(args); - return result; -} - inline bool Syslog::_sendLog(uint16_t pri, const char *message) { int result; diff --git a/src/DebugConfiguration.h b/src/DebugConfiguration.h index 0e113813a..19f36e200 100644 --- a/src/DebugConfiguration.h +++ b/src/DebugConfiguration.h @@ -108,6 +108,10 @@ // Default Bluetooth PIN #define defaultBLEPin 123456 +#if HAS_ETHERNET +#include +#endif + class Syslog { private: @@ -125,7 +129,7 @@ class Syslog bool _sendLog(uint16_t pri, const __FlashStringHelper *message); public: - Syslog(UDP &client); + explicit Syslog(UDP &client); Syslog &server(const char *server, uint16_t port); Syslog &server(IPAddress ip, uint16_t port); @@ -143,11 +147,8 @@ class Syslog bool log(uint16_t pri, const char *message); bool vlogf(uint16_t pri, const char *fmt, va_list args) __attribute__((format(printf, 3, 0))); - bool vlogf_P(uint16_t pri, PGM_P fmt_P, va_list args) __attribute__((format(printf, 3, 0))); bool logf(uint16_t pri, const char *fmt, ...) __attribute__((format(printf, 3, 4))); - - bool logf_P(uint16_t pri, PGM_P fmt_P, ...) __attribute__((format(printf, 3, 4))); }; #endif \ No newline at end of file diff --git a/src/mesh/eth/ethClient.cpp b/src/mesh/eth/ethClient.cpp index b31751e83..22365c647 100644 --- a/src/mesh/eth/ethClient.cpp +++ b/src/mesh/eth/ethClient.cpp @@ -2,6 +2,7 @@ #include "NodeDB.h" #include "RTC.h" #include "concurrency/Periodic.h" +#include "main.h" #include "mesh/api/ethServerAPI.h" #include "mqtt/MQTT.h" #include "target_specific.h" @@ -54,7 +55,7 @@ static int32_t reconnectETH() serverAddr = server.c_str(); } syslog.server(serverAddr, serverPort); - syslog.deviceHostname(WiFi.getHostname()); + syslog.deviceHostname(getDeviceName()); syslog.appName("Meshtastic"); syslog.defaultPriority(LOGLEVEL_USER); syslog.enable(); diff --git a/src/mesh/http/WiFiAPClient.cpp b/src/mesh/http/WiFiAPClient.cpp index 11f05f583..a1cf98bb3 100644 --- a/src/mesh/http/WiFiAPClient.cpp +++ b/src/mesh/http/WiFiAPClient.cpp @@ -152,7 +152,7 @@ static void onNetworkConnected() serverAddr = server.c_str(); } syslog.server(serverAddr, serverPort); - syslog.deviceHostname(WiFi.getHostname()); + syslog.deviceHostname(getDeviceName()); syslog.appName("Meshtastic"); syslog.defaultPriority(LOGLEVEL_USER); syslog.enable(); From e1914dd4645df9fd21676366a4e2e382846eb332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 31 Jan 2023 17:25:18 +0100 Subject: [PATCH 04/54] Fix build errors for other platforms --- src/DebugConfiguration.cpp | 7 ++++++- src/DebugConfiguration.h | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/DebugConfiguration.cpp b/src/DebugConfiguration.cpp index bac67c591..815414bc2 100644 --- a/src/DebugConfiguration.cpp +++ b/src/DebugConfiguration.cpp @@ -22,8 +22,11 @@ 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 "configuration.h" #include "DebugConfiguration.h" +#if HAS_WIFI || HAS_ETHERNET + Syslog::Syslog(UDP &client) { this->_client = &client; @@ -218,4 +221,6 @@ inline bool Syslog::_sendLog(uint16_t pri, const __FlashStringHelper *message) this->_client->endPacket(); return true; -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/DebugConfiguration.h b/src/DebugConfiguration.h index 19f36e200..2d250f420 100644 --- a/src/DebugConfiguration.h +++ b/src/DebugConfiguration.h @@ -110,7 +110,13 @@ #if HAS_ETHERNET #include -#endif +#endif // HAS_ETHERNET + +#if HAS_WIFI +#include +#endif // HAS_WIFI + +#if HAS_WIFI || HAS_ETHERNET class Syslog { @@ -151,4 +157,6 @@ class Syslog bool logf(uint16_t pri, const char *fmt, ...) __attribute__((format(printf, 3, 4))); }; -#endif \ No newline at end of file +#endif // HAS_ETHERNET || HAS_WIFI + +#endif // SYSLOG_H \ No newline at end of file From d34f6d0f685b5211d9a91d1c5132c7ee340de8b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 31 Jan 2023 18:34:40 +0100 Subject: [PATCH 05/54] the cake is a lie --- src/DebugConfiguration.cpp | 1 + src/DebugConfiguration.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DebugConfiguration.cpp b/src/DebugConfiguration.cpp index 815414bc2..49cdc0cd0 100644 --- a/src/DebugConfiguration.cpp +++ b/src/DebugConfiguration.cpp @@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "configuration.h" + #include "DebugConfiguration.h" #if HAS_WIFI || HAS_ETHERNET diff --git a/src/DebugConfiguration.h b/src/DebugConfiguration.h index 2d250f420..847a8e20f 100644 --- a/src/DebugConfiguration.h +++ b/src/DebugConfiguration.h @@ -113,7 +113,7 @@ #endif // HAS_ETHERNET #if HAS_WIFI -#include +#include #endif // HAS_WIFI #if HAS_WIFI || HAS_ETHERNET From 090d399843c67a7b6be58a4fa95f626d0b4aca3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 1 Feb 2023 15:09:07 +0100 Subject: [PATCH 06/54] hook up additional rsyslog output if debug printing is active --- src/DebugConfiguration.cpp | 66 -------------------------------------- src/DebugConfiguration.h | 7 ---- src/RedirectablePrint.cpp | 28 ++++++++++++++++ src/mqtt/MQTT.cpp | 10 +++--- 4 files changed, 33 insertions(+), 78 deletions(-) diff --git a/src/DebugConfiguration.cpp b/src/DebugConfiguration.cpp index 49cdc0cd0..875d4d129 100644 --- a/src/DebugConfiguration.cpp +++ b/src/DebugConfiguration.cpp @@ -92,21 +92,6 @@ bool Syslog::isEnabled() return this->_enabled; } -bool Syslog::log(uint16_t pri, const __FlashStringHelper *message) -{ - return this->_sendLog(pri, message); -} - -bool Syslog::log(uint16_t pri, const String &message) -{ - return this->_sendLog(pri, message.c_str()); -} - -bool Syslog::log(uint16_t pri, const char *message) -{ - return this->_sendLog(pri, message); -} - bool Syslog::vlogf(uint16_t pri, const char *fmt, va_list args) { char *message; @@ -132,17 +117,6 @@ bool Syslog::vlogf(uint16_t pri, const char *fmt, va_list args) return result; } -bool Syslog::logf(uint16_t pri, const char *fmt, ...) -{ - va_list args; - bool result; - - va_start(args, fmt); - result = this->vlogf(pri, fmt, args); - va_end(args); - return result; -} - inline bool Syslog::_sendLog(uint16_t pri, const char *message) { int result; @@ -184,44 +158,4 @@ inline bool Syslog::_sendLog(uint16_t pri, const char *message) return true; } -inline bool Syslog::_sendLog(uint16_t pri, const __FlashStringHelper *message) -{ - int result; - - if (!this->_enabled) - return false; - - if ((this->_server == NULL && this->_ip == INADDR_NONE) || this->_port == 0) - return false; - - // Check priority against priMask values. - if ((LOG_MASK(LOG_PRI(pri)) & this->_priMask) == 0) - return true; - - // Set default facility if none specified. - if ((pri & LOG_FACMASK) == 0) - pri = LOG_MAKEPRI(LOG_FAC(this->_priDefault), pri); - - if (this->_server != NULL) { - result = this->_client->beginPacket(this->_server, this->_port); - } else { - result = this->_client->beginPacket(this->_ip, this->_port); - } - - if (result != 1) - return false; - - this->_client->print('<'); - this->_client->print(pri); - this->_client->print(F(">1 - ")); - this->_client->print(this->_deviceHostname); - this->_client->print(' '); - this->_client->print(this->_appName); - this->_client->print(F(" - - - \xEF\xBB\xBF")); - this->_client->print(message); - this->_client->endPacket(); - - return true; -} - #endif \ No newline at end of file diff --git a/src/DebugConfiguration.h b/src/DebugConfiguration.h index 847a8e20f..3bf476f72 100644 --- a/src/DebugConfiguration.h +++ b/src/DebugConfiguration.h @@ -132,7 +132,6 @@ class Syslog bool _enabled = false; bool _sendLog(uint16_t pri, const char *message); - bool _sendLog(uint16_t pri, const __FlashStringHelper *message); public: explicit Syslog(UDP &client); @@ -148,13 +147,7 @@ class Syslog void disable(); bool isEnabled(); - bool log(uint16_t pri, const __FlashStringHelper *message); - bool log(uint16_t pri, const String &message); - bool log(uint16_t pri, const char *message); - bool vlogf(uint16_t pri, const char *fmt, va_list args) __attribute__((format(printf, 3, 0))); - - bool logf(uint16_t pri, const char *fmt, ...) __attribute__((format(printf, 3, 4))); }; #endif // HAS_ETHERNET || HAS_WIFI diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index f316785f0..a3c68f80a 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -13,6 +13,8 @@ */ NoopPrint noopPrint; +extern Syslog syslog; + void RedirectablePrint::setDestination(Print *_dest) { assert(_dest); @@ -96,6 +98,32 @@ size_t RedirectablePrint::log(const char *logLevel, const char *format, ...) } } r += vprintf(format, arg); + + // if syslog is in use, collect the log messages and send them to syslog + if (syslog.isEnabled()) { + int ll = 0; + switch (logLevel[0]) { + case 'D': + ll = SYSLOG_DEBUG; + break; + case 'I': + ll = SYSLOG_INFO; + break; + case 'W': + ll = SYSLOG_WARN; + break; + case 'E': + ll = SYSLOG_ERR; + break; + case 'C': + ll = SYSLOG_CRIT; + break; + default: + ll = 0; + } + syslog.vlogf(ll, format, arg); + } + va_end(arg); isContinuationMessage = !hasNewline; diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 5e32050ad..221c69957 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -15,6 +15,8 @@ #include "mqtt/JSON.h" #include +const int reconnectMax = 5; + MQTT *mqtt; String statusTopic = "msh/2/stat/"; @@ -218,15 +220,13 @@ void MQTT::reconnect() sendSubscriptions(); } else { #if HAS_WIFI && !defined(ARCH_PORTDUINO) - LOG_ERROR("Failed to contact MQTT server (%d/5)...\n", reconnectCount + 1); - if (reconnectCount >= 4) { + reconnectCount++; + LOG_ERROR("Failed to contact MQTT server (%d/%d)...\n", reconnectCount, reconnectMax); + if (reconnectCount >= reconnectMax) { needReconnect = true; wifiReconnect->setIntervalFromNow(0); reconnectCount = 0; - } else { - reconnectCount++; } - #endif } } From 5b75abc6f788bec929de63e503ad3495bd822926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 1 Feb 2023 15:25:25 +0100 Subject: [PATCH 07/54] guard-clause use of syslog object --- src/RedirectablePrint.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index a3c68f80a..c7f60f980 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -13,7 +13,9 @@ */ NoopPrint noopPrint; +#if HAS_WIFI || HAS_ETHERNET extern Syslog syslog; +#endif void RedirectablePrint::setDestination(Print *_dest) { @@ -99,6 +101,7 @@ size_t RedirectablePrint::log(const char *logLevel, const char *format, ...) } r += vprintf(format, arg); +#if HAS_WIFI || HAS_ETHERNET // if syslog is in use, collect the log messages and send them to syslog if (syslog.isEnabled()) { int ll = 0; @@ -123,6 +126,7 @@ size_t RedirectablePrint::log(const char *logLevel, const char *format, ...) } syslog.vlogf(ll, format, arg); } +#endif va_end(arg); From a13adfb59865b82ea91563d114e1d3d75f163927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 2 Feb 2023 09:57:46 +0100 Subject: [PATCH 08/54] fixes #2239 --- src/modules/Telemetry/DeviceTelemetry.cpp | 7 ++----- src/modules/Telemetry/DeviceTelemetry.h | 2 -- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/modules/Telemetry/DeviceTelemetry.cpp b/src/modules/Telemetry/DeviceTelemetry.cpp index 630de2933..43c25b6a7 100644 --- a/src/modules/Telemetry/DeviceTelemetry.cpp +++ b/src/modules/Telemetry/DeviceTelemetry.cpp @@ -13,8 +13,8 @@ int32_t DeviceTelemetryModule::runOnce() { uint32_t now = millis(); - if ((lastSentToMesh == 0 || - (now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.device_update_interval)) && + if (((lastSentToMesh == 0) || + ((now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.device_update_interval))) && airTime->isTxAllowedChannelUtil() && airTime->isTxAllowedAirUtil()) { sendTelemetry(); lastSentToMesh = now; @@ -35,8 +35,6 @@ bool DeviceTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket & t->variant.device_metrics.air_util_tx, t->variant.device_metrics.channel_utilization, t->variant.device_metrics.battery_level, t->variant.device_metrics.voltage); - lastMeasurementPacket = packetPool.allocCopy(mp); - nodeDB.updateTelemetry(getFrom(&mp), *t, RX_SRC_RADIO); } return false; // Let others look at this message also if they want @@ -63,7 +61,6 @@ bool DeviceTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) p->decoded.want_response = false; p->priority = meshtastic_MeshPacket_Priority_MIN; - lastMeasurementPacket = packetPool.allocCopy(*p); nodeDB.updateTelemetry(nodeDB.getNodeNum(), t, RX_SRC_LOCAL); if (phoneOnly) { LOG_INFO("Sending packet to phone\n"); diff --git a/src/modules/Telemetry/DeviceTelemetry.h b/src/modules/Telemetry/DeviceTelemetry.h index 94641f04e..ba16e095a 100644 --- a/src/modules/Telemetry/DeviceTelemetry.h +++ b/src/modules/Telemetry/DeviceTelemetry.h @@ -12,7 +12,6 @@ class DeviceTelemetryModule : private concurrency::OSThread, public ProtobufModu : concurrency::OSThread("DeviceTelemetryModule"), ProtobufModule("DeviceTelemetry", meshtastic_PortNum_TELEMETRY_APP, &meshtastic_Telemetry_msg) { - lastMeasurementPacket = nullptr; setIntervalFromNow(10 * 1000); } virtual bool wantUIFrame() { return false; } @@ -31,5 +30,4 @@ class DeviceTelemetryModule : private concurrency::OSThread, public ProtobufModu private: uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute uint32_t lastSentToMesh = 0; - const meshtastic_MeshPacket *lastMeasurementPacket; }; From f6c6c2912fe932ab7b4de11538b7cdee91e4738d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 2 Feb 2023 15:26:31 +0100 Subject: [PATCH 09/54] update enviro module to not create copies --- src/modules/Telemetry/EnvironmentTelemetry.cpp | 8 ++++++++ src/modules/Telemetry/EnvironmentTelemetry.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index ae4f9e648..d54bc6162 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -193,6 +193,10 @@ bool EnvironmentTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPac t->variant.environment_metrics.gas_resistance, t->variant.environment_metrics.relative_humidity, t->variant.environment_metrics.temperature, t->variant.environment_metrics.voltage); + // release previous packet before occupying a new spot + if (lastMeasurementPacket != nullptr) + packetPool.release(lastMeasurementPacket); + lastMeasurementPacket = packetPool.allocCopy(mp); } @@ -244,6 +248,10 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) p->decoded.want_response = false; p->priority = meshtastic_MeshPacket_Priority_MIN; + // release previous packet before occupying a new spot + if (lastMeasurementPacket != nullptr) + packetPool.release(lastMeasurementPacket); + lastMeasurementPacket = packetPool.allocCopy(*p); if (phoneOnly) { LOG_INFO("Sending packet to phone\n"); diff --git a/src/modules/Telemetry/EnvironmentTelemetry.h b/src/modules/Telemetry/EnvironmentTelemetry.h index 69ef29edb..3340f8751 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.h +++ b/src/modules/Telemetry/EnvironmentTelemetry.h @@ -36,7 +36,7 @@ class EnvironmentTelemetryModule : private concurrency::OSThread, public Protobu private: float CelsiusToFahrenheit(float c); bool firstTime = 1; - const meshtastic_MeshPacket *lastMeasurementPacket; + meshtastic_MeshPacket *lastMeasurementPacket; uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute uint32_t lastSentToMesh = 0; uint32_t sensor_read_error_count = 0; From 3c6bbff4f95fa63436f262137be671bfb27532a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 2 Feb 2023 19:10:18 +0100 Subject: [PATCH 10/54] Adjust braces to match DeviceTelemetry this is to force correct order of evaluation. --- src/modules/Telemetry/EnvironmentTelemetry.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index d54bc6162..c1693a8c8 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -103,8 +103,8 @@ int32_t EnvironmentTelemetryModule::runOnce() return result; uint32_t now = millis(); - if ((lastSentToMesh == 0 || - (now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval)) && + if (((lastSentToMesh == 0) || + ((now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval))) && airTime->isTxAllowedAirUtil()) { sendTelemetry(); lastSentToMesh = now; From e8e04d23d75bff8fcb895cfcf18e31f4a7e1de1c Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Thu, 2 Feb 2023 14:05:58 -0600 Subject: [PATCH 11/54] WIP --- platformio.ini | 2 +- protobufs | 2 +- src/mesh/generated/meshtastic/admin.pb.h | 10 + .../meshtastic/connection_status.pb.c | 27 +++ .../meshtastic/connection_status.pb.h | 189 ++++++++++++++++++ .../generated/meshtastic/device_metadata.pb.h | 13 +- src/mesh/generated/meshtastic/deviceonly.pb.h | 21 +- src/modules/AdminModule.cpp | 133 ++++++++---- src/modules/AdminModule.h | 65 +++--- 9 files changed, 387 insertions(+), 75 deletions(-) create mode 100644 src/mesh/generated/meshtastic/connection_status.pb.c create mode 100644 src/mesh/generated/meshtastic/connection_status.pb.h diff --git a/platformio.ini b/platformio.ini index 1d8083f70..0f3e4cc4d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -2,7 +2,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -;default_envs = tbeam +default_envs = tbeam ;default_envs = pico ;default_envs = tbeam-s3-core ;default_envs = tbeam0.7 diff --git a/protobufs b/protobufs index b9953ff48..4ef7e46a8 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit b9953ff48b81a06e062e35ff3c2ea6de862ee144 +Subproject commit 4ef7e46a8b83d4d2147f027c7aaa7d1b481f8688 diff --git a/src/mesh/generated/meshtastic/admin.pb.h b/src/mesh/generated/meshtastic/admin.pb.h index c47fb886f..e35b79a57 100644 --- a/src/mesh/generated/meshtastic/admin.pb.h +++ b/src/mesh/generated/meshtastic/admin.pb.h @@ -9,6 +9,7 @@ #include "meshtastic/device_metadata.pb.h" #include "meshtastic/mesh.pb.h" #include "meshtastic/module_config.pb.h" +#include "meshtastic/connection_status.pb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. @@ -91,6 +92,10 @@ typedef struct _meshtastic_AdminMessage { bool get_ringtone_request; /* Get the Ringtone in the response to this message. */ char get_ringtone_response[231]; + /* Request the node to send it's connection status */ + bool get_device_connection_status_request; + /* Device connection status response */ + meshtastic_DeviceConnectionStatus get_device_connection_status_response; /* Set the owner for this node */ meshtastic_User set_owner; /* Set channels (using the new API). @@ -166,6 +171,8 @@ extern "C" { #define meshtastic_AdminMessage_get_device_metadata_response_tag 13 #define meshtastic_AdminMessage_get_ringtone_request_tag 14 #define meshtastic_AdminMessage_get_ringtone_response_tag 15 +#define meshtastic_AdminMessage_get_device_connection_status_request_tag 16 +#define meshtastic_AdminMessage_get_device_connection_status_response_tag 17 #define meshtastic_AdminMessage_set_owner_tag 32 #define meshtastic_AdminMessage_set_channel_tag 33 #define meshtastic_AdminMessage_set_config_tag 34 @@ -197,6 +204,8 @@ X(a, STATIC, ONEOF, BOOL, (payload_variant,get_device_metadata_request, X(a, STATIC, ONEOF, MESSAGE, (payload_variant,get_device_metadata_response,get_device_metadata_response), 13) \ X(a, STATIC, ONEOF, BOOL, (payload_variant,get_ringtone_request,get_ringtone_request), 14) \ X(a, STATIC, ONEOF, STRING, (payload_variant,get_ringtone_response,get_ringtone_response), 15) \ +X(a, STATIC, ONEOF, BOOL, (payload_variant,get_device_connection_status_request,get_device_connection_status_request), 16) \ +X(a, STATIC, ONEOF, MESSAGE, (payload_variant,get_device_connection_status_response,get_device_connection_status_response), 17) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_owner,set_owner), 32) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_channel,set_channel), 33) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_config,set_config), 34) \ @@ -218,6 +227,7 @@ X(a, STATIC, ONEOF, INT32, (payload_variant,nodedb_reset,nodedb_reset), #define meshtastic_AdminMessage_payload_variant_get_config_response_MSGTYPE meshtastic_Config #define meshtastic_AdminMessage_payload_variant_get_module_config_response_MSGTYPE meshtastic_ModuleConfig #define meshtastic_AdminMessage_payload_variant_get_device_metadata_response_MSGTYPE meshtastic_DeviceMetadata +#define meshtastic_AdminMessage_payload_variant_get_device_connection_status_response_MSGTYPE meshtastic_DeviceConnectionStatus #define meshtastic_AdminMessage_payload_variant_set_owner_MSGTYPE meshtastic_User #define meshtastic_AdminMessage_payload_variant_set_channel_MSGTYPE meshtastic_Channel #define meshtastic_AdminMessage_payload_variant_set_config_MSGTYPE meshtastic_Config diff --git a/src/mesh/generated/meshtastic/connection_status.pb.c b/src/mesh/generated/meshtastic/connection_status.pb.c new file mode 100644 index 000000000..0675bc815 --- /dev/null +++ b/src/mesh/generated/meshtastic/connection_status.pb.c @@ -0,0 +1,27 @@ +/* Automatically generated nanopb constant definitions */ +/* Generated by nanopb-0.4.7 */ + +#include "meshtastic/connection_status.pb.h" +#if PB_PROTO_HEADER_VERSION != 40 +#error Regenerate this file with the current version of nanopb generator. +#endif + +PB_BIND(meshtastic_DeviceConnectionStatus, meshtastic_DeviceConnectionStatus, AUTO) + + +PB_BIND(meshtastic_WifiConnectionStatus, meshtastic_WifiConnectionStatus, AUTO) + + +PB_BIND(meshtastic_EthernetConnectionStatus, meshtastic_EthernetConnectionStatus, AUTO) + + +PB_BIND(meshtastic_NetworkConnectionStatus, meshtastic_NetworkConnectionStatus, AUTO) + + +PB_BIND(meshtastic_BluetoothConnectionStatus, meshtastic_BluetoothConnectionStatus, AUTO) + + +PB_BIND(meshtastic_SerialConnectionStatus, meshtastic_SerialConnectionStatus, AUTO) + + + diff --git a/src/mesh/generated/meshtastic/connection_status.pb.h b/src/mesh/generated/meshtastic/connection_status.pb.h new file mode 100644 index 000000000..c13ec2bc6 --- /dev/null +++ b/src/mesh/generated/meshtastic/connection_status.pb.h @@ -0,0 +1,189 @@ +/* Automatically generated nanopb header */ +/* Generated by nanopb-0.4.7 */ + +#ifndef PB_MESHTASTIC_MESHTASTIC_CONNECTION_STATUS_PB_H_INCLUDED +#define PB_MESHTASTIC_MESHTASTIC_CONNECTION_STATUS_PB_H_INCLUDED +#include + +#if PB_PROTO_HEADER_VERSION != 40 +#error Regenerate this file with the current version of nanopb generator. +#endif + +/* Struct definitions */ +/* Ethernet or WiFi connection status */ +typedef struct _meshtastic_NetworkConnectionStatus { + /* IP address of device */ + uint32_t ip_address; + /* Whether the device has an active connection or not */ + bool is_connected; + /* Whether the device has an active connection to an MQTT broker or not */ + bool is_mqtt_connected; + /* Whether the device is actively remote syslogging or not */ + bool is_syslog_connected; +} meshtastic_NetworkConnectionStatus; + +/* Ethernet connection status */ +typedef struct _meshtastic_EthernetConnectionStatus { + /* Connection status */ + bool has_status; + meshtastic_NetworkConnectionStatus status; +} meshtastic_EthernetConnectionStatus; + +/* WiFi connection status */ +typedef struct _meshtastic_WifiConnectionStatus { + /* Connection status */ + bool has_status; + meshtastic_EthernetConnectionStatus status; + /* WiFi access point ssid */ + char ssid[33]; + /* Rssi of wireless connection */ + int32_t rssi; +} meshtastic_WifiConnectionStatus; + +/* Bluetooth connection status */ +typedef struct _meshtastic_BluetoothConnectionStatus { + /* The pairing pin for bluetooth */ + uint32_t pin; + /* Rssi of bluetooth connection */ + int32_t rssi; + /* Whether the device has an active connection or not */ + bool is_connected; +} meshtastic_BluetoothConnectionStatus; + +/* Serial connection status */ +typedef struct _meshtastic_SerialConnectionStatus { + /* The serial baud rate */ + uint32_t baud; + /* Whether the device has an active connection or not */ + bool is_connected; +} meshtastic_SerialConnectionStatus; + +typedef struct _meshtastic_DeviceConnectionStatus { + /* WiFi Status */ + bool has_wifi; + meshtastic_WifiConnectionStatus wifi; + /* WiFi Status */ + bool has_ethernet; + meshtastic_EthernetConnectionStatus ethernet; + /* Bluetooth Status */ + bool has_bluetooth; + meshtastic_BluetoothConnectionStatus bluetooth; + /* Serial Status */ + bool has_serial; + meshtastic_SerialConnectionStatus serial; +} meshtastic_DeviceConnectionStatus; + + +#ifdef __cplusplus +extern "C" { +#endif + +/* Initializer values for message structs */ +#define meshtastic_DeviceConnectionStatus_init_default {false, meshtastic_WifiConnectionStatus_init_default, false, meshtastic_EthernetConnectionStatus_init_default, false, meshtastic_BluetoothConnectionStatus_init_default, false, meshtastic_SerialConnectionStatus_init_default} +#define meshtastic_WifiConnectionStatus_init_default {false, meshtastic_EthernetConnectionStatus_init_default, "", 0} +#define meshtastic_EthernetConnectionStatus_init_default {false, meshtastic_NetworkConnectionStatus_init_default} +#define meshtastic_NetworkConnectionStatus_init_default {0, 0, 0, 0} +#define meshtastic_BluetoothConnectionStatus_init_default {0, 0, 0} +#define meshtastic_SerialConnectionStatus_init_default {0, 0} +#define meshtastic_DeviceConnectionStatus_init_zero {false, meshtastic_WifiConnectionStatus_init_zero, false, meshtastic_EthernetConnectionStatus_init_zero, false, meshtastic_BluetoothConnectionStatus_init_zero, false, meshtastic_SerialConnectionStatus_init_zero} +#define meshtastic_WifiConnectionStatus_init_zero {false, meshtastic_EthernetConnectionStatus_init_zero, "", 0} +#define meshtastic_EthernetConnectionStatus_init_zero {false, meshtastic_NetworkConnectionStatus_init_zero} +#define meshtastic_NetworkConnectionStatus_init_zero {0, 0, 0, 0} +#define meshtastic_BluetoothConnectionStatus_init_zero {0, 0, 0} +#define meshtastic_SerialConnectionStatus_init_zero {0, 0} + +/* Field tags (for use in manual encoding/decoding) */ +#define meshtastic_NetworkConnectionStatus_ip_address_tag 1 +#define meshtastic_NetworkConnectionStatus_is_connected_tag 2 +#define meshtastic_NetworkConnectionStatus_is_mqtt_connected_tag 3 +#define meshtastic_NetworkConnectionStatus_is_syslog_connected_tag 4 +#define meshtastic_EthernetConnectionStatus_status_tag 1 +#define meshtastic_WifiConnectionStatus_status_tag 1 +#define meshtastic_WifiConnectionStatus_ssid_tag 2 +#define meshtastic_WifiConnectionStatus_rssi_tag 3 +#define meshtastic_BluetoothConnectionStatus_pin_tag 1 +#define meshtastic_BluetoothConnectionStatus_rssi_tag 2 +#define meshtastic_BluetoothConnectionStatus_is_connected_tag 3 +#define meshtastic_SerialConnectionStatus_baud_tag 1 +#define meshtastic_SerialConnectionStatus_is_connected_tag 2 +#define meshtastic_DeviceConnectionStatus_wifi_tag 1 +#define meshtastic_DeviceConnectionStatus_ethernet_tag 2 +#define meshtastic_DeviceConnectionStatus_bluetooth_tag 3 +#define meshtastic_DeviceConnectionStatus_serial_tag 4 + +/* Struct field encoding specification for nanopb */ +#define meshtastic_DeviceConnectionStatus_FIELDLIST(X, a) \ +X(a, STATIC, OPTIONAL, MESSAGE, wifi, 1) \ +X(a, STATIC, OPTIONAL, MESSAGE, ethernet, 2) \ +X(a, STATIC, OPTIONAL, MESSAGE, bluetooth, 3) \ +X(a, STATIC, OPTIONAL, MESSAGE, serial, 4) +#define meshtastic_DeviceConnectionStatus_CALLBACK NULL +#define meshtastic_DeviceConnectionStatus_DEFAULT NULL +#define meshtastic_DeviceConnectionStatus_wifi_MSGTYPE meshtastic_WifiConnectionStatus +#define meshtastic_DeviceConnectionStatus_ethernet_MSGTYPE meshtastic_EthernetConnectionStatus +#define meshtastic_DeviceConnectionStatus_bluetooth_MSGTYPE meshtastic_BluetoothConnectionStatus +#define meshtastic_DeviceConnectionStatus_serial_MSGTYPE meshtastic_SerialConnectionStatus + +#define meshtastic_WifiConnectionStatus_FIELDLIST(X, a) \ +X(a, STATIC, OPTIONAL, MESSAGE, status, 1) \ +X(a, STATIC, SINGULAR, STRING, ssid, 2) \ +X(a, STATIC, SINGULAR, INT32, rssi, 3) +#define meshtastic_WifiConnectionStatus_CALLBACK NULL +#define meshtastic_WifiConnectionStatus_DEFAULT NULL +#define meshtastic_WifiConnectionStatus_status_MSGTYPE meshtastic_EthernetConnectionStatus + +#define meshtastic_EthernetConnectionStatus_FIELDLIST(X, a) \ +X(a, STATIC, OPTIONAL, MESSAGE, status, 1) +#define meshtastic_EthernetConnectionStatus_CALLBACK NULL +#define meshtastic_EthernetConnectionStatus_DEFAULT NULL +#define meshtastic_EthernetConnectionStatus_status_MSGTYPE meshtastic_NetworkConnectionStatus + +#define meshtastic_NetworkConnectionStatus_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, FIXED32, ip_address, 1) \ +X(a, STATIC, SINGULAR, BOOL, is_connected, 2) \ +X(a, STATIC, SINGULAR, BOOL, is_mqtt_connected, 3) \ +X(a, STATIC, SINGULAR, BOOL, is_syslog_connected, 4) +#define meshtastic_NetworkConnectionStatus_CALLBACK NULL +#define meshtastic_NetworkConnectionStatus_DEFAULT NULL + +#define meshtastic_BluetoothConnectionStatus_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, UINT32, pin, 1) \ +X(a, STATIC, SINGULAR, INT32, rssi, 2) \ +X(a, STATIC, SINGULAR, BOOL, is_connected, 3) +#define meshtastic_BluetoothConnectionStatus_CALLBACK NULL +#define meshtastic_BluetoothConnectionStatus_DEFAULT NULL + +#define meshtastic_SerialConnectionStatus_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, UINT32, baud, 1) \ +X(a, STATIC, SINGULAR, BOOL, is_connected, 2) +#define meshtastic_SerialConnectionStatus_CALLBACK NULL +#define meshtastic_SerialConnectionStatus_DEFAULT NULL + +extern const pb_msgdesc_t meshtastic_DeviceConnectionStatus_msg; +extern const pb_msgdesc_t meshtastic_WifiConnectionStatus_msg; +extern const pb_msgdesc_t meshtastic_EthernetConnectionStatus_msg; +extern const pb_msgdesc_t meshtastic_NetworkConnectionStatus_msg; +extern const pb_msgdesc_t meshtastic_BluetoothConnectionStatus_msg; +extern const pb_msgdesc_t meshtastic_SerialConnectionStatus_msg; + +/* Defines for backwards compatibility with code written before nanopb-0.4.0 */ +#define meshtastic_DeviceConnectionStatus_fields &meshtastic_DeviceConnectionStatus_msg +#define meshtastic_WifiConnectionStatus_fields &meshtastic_WifiConnectionStatus_msg +#define meshtastic_EthernetConnectionStatus_fields &meshtastic_EthernetConnectionStatus_msg +#define meshtastic_NetworkConnectionStatus_fields &meshtastic_NetworkConnectionStatus_msg +#define meshtastic_BluetoothConnectionStatus_fields &meshtastic_BluetoothConnectionStatus_msg +#define meshtastic_SerialConnectionStatus_fields &meshtastic_SerialConnectionStatus_msg + +/* Maximum encoded size of messages (where known) */ +#define meshtastic_BluetoothConnectionStatus_size 19 +#define meshtastic_DeviceConnectionStatus_size 108 +#define meshtastic_EthernetConnectionStatus_size 13 +#define meshtastic_NetworkConnectionStatus_size 11 +#define meshtastic_SerialConnectionStatus_size 8 +#define meshtastic_WifiConnectionStatus_size 60 + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/src/mesh/generated/meshtastic/device_metadata.pb.h b/src/mesh/generated/meshtastic/device_metadata.pb.h index 384863601..44cf29079 100644 --- a/src/mesh/generated/meshtastic/device_metadata.pb.h +++ b/src/mesh/generated/meshtastic/device_metadata.pb.h @@ -5,6 +5,7 @@ #define PB_MESHTASTIC_MESHTASTIC_DEVICE_METADATA_PB_H_INCLUDED #include #include "meshtastic/config.pb.h" +#include "meshtastic/mesh.pb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. @@ -29,6 +30,8 @@ typedef struct _meshtastic_DeviceMetadata { meshtastic_Config_DeviceConfig_Role role; /* Indicates the device's current enabled position flags */ uint32_t position_flags; + /* Device hardware model */ + meshtastic_HardwareModel hw_model; } meshtastic_DeviceMetadata; @@ -37,8 +40,8 @@ extern "C" { #endif /* Initializer values for message structs */ -#define meshtastic_DeviceMetadata_init_default {"", 0, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_Role_MIN, 0} -#define meshtastic_DeviceMetadata_init_zero {"", 0, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_Role_MIN, 0} +#define meshtastic_DeviceMetadata_init_default {"", 0, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_Role_MIN, 0, _meshtastic_HardwareModel_MIN} +#define meshtastic_DeviceMetadata_init_zero {"", 0, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_Role_MIN, 0, _meshtastic_HardwareModel_MIN} /* Field tags (for use in manual encoding/decoding) */ #define meshtastic_DeviceMetadata_firmware_version_tag 1 @@ -49,6 +52,7 @@ extern "C" { #define meshtastic_DeviceMetadata_hasEthernet_tag 6 #define meshtastic_DeviceMetadata_role_tag 7 #define meshtastic_DeviceMetadata_position_flags_tag 8 +#define meshtastic_DeviceMetadata_hw_model_tag 9 /* Struct field encoding specification for nanopb */ #define meshtastic_DeviceMetadata_FIELDLIST(X, a) \ @@ -59,7 +63,8 @@ X(a, STATIC, SINGULAR, BOOL, hasWifi, 4) \ X(a, STATIC, SINGULAR, BOOL, hasBluetooth, 5) \ X(a, STATIC, SINGULAR, BOOL, hasEthernet, 6) \ X(a, STATIC, SINGULAR, UENUM, role, 7) \ -X(a, STATIC, SINGULAR, UINT32, position_flags, 8) +X(a, STATIC, SINGULAR, UINT32, position_flags, 8) \ +X(a, STATIC, SINGULAR, UENUM, hw_model, 9) #define meshtastic_DeviceMetadata_CALLBACK NULL #define meshtastic_DeviceMetadata_DEFAULT NULL @@ -69,7 +74,7 @@ extern const pb_msgdesc_t meshtastic_DeviceMetadata_msg; #define meshtastic_DeviceMetadata_fields &meshtastic_DeviceMetadata_msg /* Maximum encoded size of messages (where known) */ -#define meshtastic_DeviceMetadata_size 41 +#define meshtastic_DeviceMetadata_size 44 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/meshtastic/deviceonly.pb.h b/src/mesh/generated/meshtastic/deviceonly.pb.h index 842431b28..aef8ee8be 100644 --- a/src/mesh/generated/meshtastic/deviceonly.pb.h +++ b/src/mesh/generated/meshtastic/deviceonly.pb.h @@ -5,6 +5,7 @@ #define PB_MESHTASTIC_MESHTASTIC_DEVICEONLY_PB_H_INCLUDED #include #include "meshtastic/channel.pb.h" +#include "meshtastic/localonly.pb.h" #include "meshtastic/mesh.pb.h" #if PB_PROTO_HEADER_VERSION != 40 @@ -85,6 +86,12 @@ typedef struct _meshtastic_OEMStore { char oem_text[40]; /* The default device encryption key, 16 or 32 byte */ meshtastic_OEMStore_oem_aes_key_t oem_aes_key; + /* A Preset LocalConfig to apply during factory reset */ + bool has_oem_local_config; + meshtastic_LocalConfig oem_local_config; + /* A Preset LocalModuleConfig to apply during factory reset */ + bool has_oem_local_module_config; + meshtastic_LocalModuleConfig oem_local_module_config; } meshtastic_OEMStore; @@ -105,10 +112,10 @@ extern "C" { /* Initializer values for message structs */ #define meshtastic_DeviceState_init_default {false, meshtastic_MyNodeInfo_init_default, false, meshtastic_User_init_default, 0, {meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default}, 0, {meshtastic_MeshPacket_init_default}, false, meshtastic_MeshPacket_init_default, 0, 0, 0} #define meshtastic_ChannelFile_init_default {0, {meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default}, 0} -#define meshtastic_OEMStore_init_default {0, 0, {0, {0}}, _meshtastic_ScreenFonts_MIN, "", {0, {0}}} +#define meshtastic_OEMStore_init_default {0, 0, {0, {0}}, _meshtastic_ScreenFonts_MIN, "", {0, {0}}, false, meshtastic_LocalConfig_init_default, false, meshtastic_LocalModuleConfig_init_default} #define meshtastic_DeviceState_init_zero {false, meshtastic_MyNodeInfo_init_zero, false, meshtastic_User_init_zero, 0, {meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero}, 0, {meshtastic_MeshPacket_init_zero}, false, meshtastic_MeshPacket_init_zero, 0, 0, 0} #define meshtastic_ChannelFile_init_zero {0, {meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero}, 0} -#define meshtastic_OEMStore_init_zero {0, 0, {0, {0}}, _meshtastic_ScreenFonts_MIN, "", {0, {0}}} +#define meshtastic_OEMStore_init_zero {0, 0, {0, {0}}, _meshtastic_ScreenFonts_MIN, "", {0, {0}}, false, meshtastic_LocalConfig_init_zero, false, meshtastic_LocalModuleConfig_init_zero} /* Field tags (for use in manual encoding/decoding) */ #define meshtastic_DeviceState_my_node_tag 2 @@ -127,6 +134,8 @@ extern "C" { #define meshtastic_OEMStore_oem_font_tag 4 #define meshtastic_OEMStore_oem_text_tag 5 #define meshtastic_OEMStore_oem_aes_key_tag 6 +#define meshtastic_OEMStore_oem_local_config_tag 7 +#define meshtastic_OEMStore_oem_local_module_config_tag 8 /* Struct field encoding specification for nanopb */ #define meshtastic_DeviceState_FIELDLIST(X, a) \ @@ -159,9 +168,13 @@ X(a, STATIC, SINGULAR, UINT32, oem_icon_height, 2) \ X(a, STATIC, SINGULAR, BYTES, oem_icon_bits, 3) \ X(a, STATIC, SINGULAR, UENUM, oem_font, 4) \ X(a, STATIC, SINGULAR, STRING, oem_text, 5) \ -X(a, STATIC, SINGULAR, BYTES, oem_aes_key, 6) +X(a, STATIC, SINGULAR, BYTES, oem_aes_key, 6) \ +X(a, STATIC, OPTIONAL, MESSAGE, oem_local_config, 7) \ +X(a, STATIC, OPTIONAL, MESSAGE, oem_local_module_config, 8) #define meshtastic_OEMStore_CALLBACK NULL #define meshtastic_OEMStore_DEFAULT NULL +#define meshtastic_OEMStore_oem_local_config_MSGTYPE meshtastic_LocalConfig +#define meshtastic_OEMStore_oem_local_module_config_MSGTYPE meshtastic_LocalModuleConfig extern const pb_msgdesc_t meshtastic_DeviceState_msg; extern const pb_msgdesc_t meshtastic_ChannelFile_msg; @@ -175,7 +188,7 @@ extern const pb_msgdesc_t meshtastic_OEMStore_msg; /* Maximum encoded size of messages (where known) */ #define meshtastic_ChannelFile_size 638 #define meshtastic_DeviceState_size 21800 -#define meshtastic_OEMStore_size 2140 +#define meshtastic_OEMStore_size 2992 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 18557f0b3..4495e397f 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -26,7 +26,8 @@ static const char *secretReserved = "sekrit"; /// If buf is the reserved secret word, replace the buffer with currentVal static void writeSecret(char *buf, size_t bufsz, const char *currentVal) { - if (strcmp(buf, secretReserved) == 0) { + if (strcmp(buf, secretReserved) == 0) + { strncpy(buf, currentVal, bufsz); } } @@ -44,7 +45,8 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta bool handled = false; assert(r); - switch (r->which_payload_variant) { + switch (r->which_payload_variant) + { /** * Getters @@ -64,7 +66,8 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta handleGetModuleConfig(mp, r->get_module_config_request); break; - case meshtastic_AdminMessage_get_channel_request_tag: { + case meshtastic_AdminMessage_get_channel_request_tag: + { uint32_t i = r->get_channel_request - 1; LOG_INFO("Client is getting channel %u\n", i); if (i >= MAX_NUM_CHANNELS) @@ -103,17 +106,22 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta /** * Other */ - case meshtastic_AdminMessage_reboot_seconds_tag: { + case meshtastic_AdminMessage_reboot_seconds_tag: + { reboot(r->reboot_seconds); break; } - case meshtastic_AdminMessage_reboot_ota_seconds_tag: { + case meshtastic_AdminMessage_reboot_ota_seconds_tag: + { int32_t s = r->reboot_ota_seconds; #ifdef ARCH_ESP32 - if (BleOta::getOtaAppVersion().isEmpty()) { + if (BleOta::getOtaAppVersion().isEmpty()) + { LOG_INFO("No OTA firmware available, scheduling regular reboot in %d seconds\n", s); screen->startRebootScreen(); - } else { + } + else + { screen->startFirmwareUpdateScreen(); BleOta::switchToOtaApp(); LOG_INFO("Rebooting to OTA in %d seconds\n", s); @@ -125,35 +133,41 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta rebootAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } - case meshtastic_AdminMessage_shutdown_seconds_tag: { + case meshtastic_AdminMessage_shutdown_seconds_tag: + { int32_t s = r->shutdown_seconds; LOG_INFO("Shutdown in %d seconds\n", s); shutdownAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } - case meshtastic_AdminMessage_get_device_metadata_request_tag: { + case meshtastic_AdminMessage_get_device_metadata_request_tag: + { LOG_INFO("Client is getting device metadata\n"); handleGetDeviceMetadata(mp); break; } - case meshtastic_AdminMessage_factory_reset_tag: { + case meshtastic_AdminMessage_factory_reset_tag: + { LOG_INFO("Initiating factory reset\n"); nodeDB.factoryReset(); reboot(DEFAULT_REBOOT_SECONDS); break; } - case meshtastic_AdminMessage_nodedb_reset_tag: { + case meshtastic_AdminMessage_nodedb_reset_tag: + { LOG_INFO("Initiating node-db reset\n"); nodeDB.resetNodes(); reboot(DEFAULT_REBOOT_SECONDS); break; } - case meshtastic_AdminMessage_begin_edit_settings_tag: { + case meshtastic_AdminMessage_begin_edit_settings_tag: + { LOG_INFO("Beginning transaction for editing settings\n"); hasOpenEditTransaction = true; break; } - case meshtastic_AdminMessage_commit_edit_settings_tag: { + case meshtastic_AdminMessage_commit_edit_settings_tag: + { LOG_INFO("Committing transaction for edited settings\n"); hasOpenEditTransaction = false; saveChanges(SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS); @@ -170,11 +184,16 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; AdminMessageHandleResult handleResult = MeshModule::handleAdminMessageForAllPlugins(mp, r, &res); - if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) { + if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) + { myReply = allocDataProtobuf(res); - } else if (mp.decoded.want_response) { + } + else if (mp.decoded.want_response) + { LOG_DEBUG("We did not responded to a request that wanted a respond. req.variant=%d\n", r->which_payload_variant); - } else if (handleResult != AdminMessageHandleResult::HANDLED) { + } + else if (handleResult != AdminMessageHandleResult::HANDLED) + { // Probably a message sent by us or sent to our local node. FIXME, we should avoid scanning these messages LOG_INFO("Ignoring nonrelevant admin %d\n", r->which_payload_variant); } @@ -182,7 +201,8 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta } // If asked for a response and it is not yet set, generate an 'ACK' response - if (mp.decoded.want_response && !myReply) { + if (mp.decoded.want_response && !myReply) + { myReply = allocErrorResponse(meshtastic_Routing_Error_NONE, &mp); } @@ -198,26 +218,31 @@ void AdminModule::handleSetOwner(const meshtastic_User &o) int changed = 0; bool licensed_changed = false; - if (*o.long_name) { + if (*o.long_name) + { changed |= strcmp(owner.long_name, o.long_name); strncpy(owner.long_name, o.long_name, sizeof(owner.long_name)); } - if (*o.short_name) { + if (*o.short_name) + { changed |= strcmp(owner.short_name, o.short_name); strncpy(owner.short_name, o.short_name, sizeof(owner.short_name)); } - if (*o.id) { + if (*o.id) + { changed |= strcmp(owner.id, o.id); strncpy(owner.id, o.id, sizeof(owner.id)); } - if (owner.is_licensed != o.is_licensed) { + if (owner.is_licensed != o.is_licensed) + { changed = 1; licensed_changed = true; owner.is_licensed = o.is_licensed; config.lora.override_duty_cycle = owner.is_licensed; // override duty cycle for licensed operators } - if (changed) { // If nothing really changed, don't broadcast on the network or write to flash + if (changed) + { // If nothing really changed, don't broadcast on the network or write to flash service.reloadOwner(!hasOpenEditTransaction); licensed_changed ? saveChanges(SEGMENT_CONFIG | SEGMENT_DEVICESTATE) : saveChanges(SEGMENT_DEVICESTATE); } @@ -228,7 +253,8 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) auto existingRole = config.device.role; bool isRegionUnset = (config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_UNSET); - switch (c.which_payload_variant) { + switch (c.which_payload_variant) + { case meshtastic_Config_device_tag: LOG_INFO("Setting config: Device\n"); config.has_device = true; @@ -263,7 +289,8 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) LOG_INFO("Setting config: LoRa\n"); config.has_lora = true; config.lora = c.payload_variant.lora; - if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) { + if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) + { config.lora.tx_enabled = true; } break; @@ -279,7 +306,8 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) void AdminModule::handleSetModuleConfig(const meshtastic_ModuleConfig &c) { - switch (c.which_payload_variant) { + switch (c.which_payload_variant) + { case meshtastic_ModuleConfig_mqtt_tag: LOG_INFO("Setting module config: MQTT\n"); moduleConfig.has_mqtt = true; @@ -343,7 +371,8 @@ void AdminModule::handleSetChannel(const meshtastic_Channel &cc) void AdminModule::handleGetOwner(const meshtastic_MeshPacket &req) { - if (req.decoded.want_response) { + if (req.decoded.want_response) + { // We create the reply here meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; res.get_owner_response = owner; @@ -357,8 +386,10 @@ void AdminModule::handleGetConfig(const meshtastic_MeshPacket &req, const uint32 { meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; - if (req.decoded.want_response) { - switch (configType) { + if (req.decoded.want_response) + { + switch (configType) + { case meshtastic_AdminMessage_ConfigType_DEVICE_CONFIG: LOG_INFO("Getting config: Device\n"); res.get_config_response.which_payload_variant = meshtastic_Config_device_tag; @@ -413,8 +444,10 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const { meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; - if (req.decoded.want_response) { - switch (configType) { + if (req.decoded.want_response) + { + switch (configType) + { case meshtastic_AdminMessage_ModuleConfigType_MQTT_CONFIG: LOG_INFO("Getting module config: MQTT\n"); res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_mqtt_tag; @@ -487,15 +520,43 @@ void AdminModule::handleGetDeviceMetadata(const meshtastic_MeshPacket &req) deviceMetadata.hasEthernet = HAS_ETHERNET; deviceMetadata.role = config.device.role; deviceMetadata.position_flags = config.position.position_flags; + deviceMetadata.hw_model = HW_VENDOR; r.get_device_metadata_response = deviceMetadata; r.which_payload_variant = meshtastic_AdminMessage_get_device_metadata_response_tag; myReply = allocDataProtobuf(r); } +void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &req) +{ + meshtastic_AdminMessage r = meshtastic_AdminMessage_init_default; + + meshtastic_DeviceConnectionStatus connectionStatus; + + connectionStatus.has_wifi = HAS_WIFI; +#if HAS_WIFI + connectionStatus.wifi.status.status.is_connected = WiFi.status() != WL_CONNECTED; + strncpy(connectionStatus.wifi.ssid, config.network.wifi_ssid, 33); + connectionStatus.wifi.status.status.is_syslog_connected = false; // FIXME wire this up +#endif + + connectionStatus.has_bluetooth = HAS_BLUETOOTH; +#if HAS_BLUETOOTH + +#endif + connectionStatus.has_ethernet = HAS_ETHERNET; + + connectionStatus.has_serial = true; // No serial-less devices + + r.get_device_connection_status_response = connectionStatus; + r.which_payload_variant = meshtastic_AdminMessage_get_device_connection_status_response_tag; + myReply = allocDataProtobuf(r); +} + void AdminModule::handleGetChannel(const meshtastic_MeshPacket &req, uint32_t channelIndex) { - if (req.decoded.want_response) { + if (req.decoded.want_response) + { // We create the reply here meshtastic_AdminMessage r = meshtastic_AdminMessage_init_default; r.get_channel_response = channels.getByIndex(channelIndex); @@ -513,13 +574,17 @@ void AdminModule::reboot(int32_t seconds) void AdminModule::saveChanges(int saveWhat, bool shouldReboot) { - if (!hasOpenEditTransaction) { + if (!hasOpenEditTransaction) + { LOG_INFO("Saving changes to disk\n"); service.reloadConfig(saveWhat); // Calls saveToDisk among other things - } else { + } + else + { LOG_INFO("Delaying save of changes to disk until the open transaction is committed\n"); } - if (shouldReboot) { + if (shouldReboot) + { reboot(DEFAULT_REBOOT_SECONDS); } } diff --git a/src/modules/AdminModule.h b/src/modules/AdminModule.h index a0602b140..6924bfd7e 100644 --- a/src/modules/AdminModule.h +++ b/src/modules/AdminModule.h @@ -1,46 +1,49 @@ #pragma once #include "ProtobufModule.h" +#ifdef ARCH_ESP32 +#include "mesh/http/WiFiAPClient.h" +#endif /** * Admin module for admin messages */ class AdminModule : public ProtobufModule { - public: - /** Constructor - * name is for debugging output - */ - AdminModule(); +public: + /** Constructor + * name is for debugging output + */ + AdminModule(); - protected: - /** Called to handle a particular incoming message +protected: + /** Called to handle a particular incoming message - @return true if you've guaranteed you've handled this message and no other handlers should be considered for it - */ - virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_AdminMessage *p) override; + @return true if you've guaranteed you've handled this message and no other handlers should be considered for it + */ + virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_AdminMessage *p) override; - private: - bool hasOpenEditTransaction = false; +private: + bool hasOpenEditTransaction = false; - void saveChanges(int saveWhat, bool shouldReboot = true); - /** - * Getters - */ - void handleGetOwner(const meshtastic_MeshPacket &req); - void handleGetConfig(const meshtastic_MeshPacket &req, uint32_t configType); - void handleGetModuleConfig(const meshtastic_MeshPacket &req, uint32_t configType); - void handleGetChannel(const meshtastic_MeshPacket &req, uint32_t channelIndex); - void handleGetDeviceMetadata(const meshtastic_MeshPacket &req); - - /** - * Setters - */ - void handleSetOwner(const meshtastic_User &o); - void handleSetChannel(const meshtastic_Channel &cc); - void handleSetConfig(const meshtastic_Config &c); - void handleSetModuleConfig(const meshtastic_ModuleConfig &c); - void handleSetChannel(); - void reboot(int32_t seconds); + void saveChanges(int saveWhat, bool shouldReboot = true); + /** + * Getters + */ + void handleGetOwner(const meshtastic_MeshPacket &req); + void handleGetConfig(const meshtastic_MeshPacket &req, uint32_t configType); + void handleGetModuleConfig(const meshtastic_MeshPacket &req, uint32_t configType); + void handleGetChannel(const meshtastic_MeshPacket &req, uint32_t channelIndex); + void handleGetDeviceMetadata(const meshtastic_MeshPacket &req); + void handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &req); + /** + * Setters + */ + void handleSetOwner(const meshtastic_User &o); + void handleSetChannel(const meshtastic_Channel &cc); + void handleSetConfig(const meshtastic_Config &c); + void handleSetModuleConfig(const meshtastic_ModuleConfig &c); + void handleSetChannel(); + void reboot(int32_t seconds); }; extern AdminModule *adminModule; From 971ecd117c66b400ab914aa461d662861f9aa421 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Thu, 2 Feb 2023 14:11:48 -0600 Subject: [PATCH 12/54] Whoooosh before my battery dies --- src/modules/AdminModule.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 4495e397f..1df8d5ff4 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -13,6 +13,10 @@ #include "unistd.h" #endif +#if HAS_WIFI || HAS_ETHERNET +#include "mqtt/MQTT.h" +#endif + #define DEFAULT_REBOOT_SECONDS 5 AdminModule *adminModule; @@ -531,24 +535,29 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r { meshtastic_AdminMessage r = meshtastic_AdminMessage_init_default; - meshtastic_DeviceConnectionStatus connectionStatus; + meshtastic_DeviceConnectionStatus conn; - connectionStatus.has_wifi = HAS_WIFI; + conn.has_wifi = HAS_WIFI; #if HAS_WIFI - connectionStatus.wifi.status.status.is_connected = WiFi.status() != WL_CONNECTED; - strncpy(connectionStatus.wifi.ssid, config.network.wifi_ssid, 33); - connectionStatus.wifi.status.status.is_syslog_connected = false; // FIXME wire this up + conn.wifi.status.status.is_connected = WiFi.status() != WL_CONNECTED; + strncpy(conn.wifi.ssid, config.network.wifi_ssid, 33); + if (conn.wifi.status.status.is_connected) + { + conn.wifi.status.status.ip_address = WiFi.localIP(); + conn.wifi.status.status.is_mqtt_connected = mqtt && mqtt->connected(); + conn.wifi.status.status.is_syslog_connected = false; // FIXME wire this up + } #endif - connectionStatus.has_bluetooth = HAS_BLUETOOTH; + conn.has_bluetooth = HAS_BLUETOOTH; #if HAS_BLUETOOTH #endif - connectionStatus.has_ethernet = HAS_ETHERNET; + conn.has_ethernet = HAS_ETHERNET; - connectionStatus.has_serial = true; // No serial-less devices + conn.has_serial = true; // No serial-less devices - r.get_device_connection_status_response = connectionStatus; + r.get_device_connection_status_response = conn; r.which_payload_variant = meshtastic_AdminMessage_get_device_connection_status_response_tag; myReply = allocDataProtobuf(r); } From a8dd497575a567fda9db3ee9ad368eccb636dae2 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Thu, 2 Feb 2023 14:40:18 -0600 Subject: [PATCH 13/54] Contain it --- src/modules/AdminModule.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 1df8d5ff4..16dee49a9 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -537,23 +537,31 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r meshtastic_DeviceConnectionStatus conn; - conn.has_wifi = HAS_WIFI; #if HAS_WIFI + conn.has_wifi = true; conn.wifi.status.status.is_connected = WiFi.status() != WL_CONNECTED; strncpy(conn.wifi.ssid, config.network.wifi_ssid, 33); if (conn.wifi.status.status.is_connected) { + conn.wifi.rssi = WiFi.RSSI(); conn.wifi.status.status.ip_address = WiFi.localIP(); conn.wifi.status.status.is_mqtt_connected = mqtt && mqtt->connected(); conn.wifi.status.status.is_syslog_connected = false; // FIXME wire this up } #endif - conn.has_bluetooth = HAS_BLUETOOTH; -#if HAS_BLUETOOTH - +#if HAS_ETHERNET + conn.has_ethernet = true; + // conn.ethernet. +#endif + +#if HAS_BLUETOOTH + conn.has_bluetooth = HAS_BLUETOOTH; + // nimbleBluetooth-> + // #if ARCH_ESP32 + + // #elif #endif - conn.has_ethernet = HAS_ETHERNET; conn.has_serial = true; // No serial-less devices From d9031610ab00d35757f080eaeed8b1164595585a Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 08:50:10 -0600 Subject: [PATCH 14/54] Connection status admin message --- src/BluetoothCommon.h | 12 ++- src/main.cpp | 6 ++ src/main.h | 8 ++ src/modules/AdminModule.cpp | 140 +++++++++++--------------- src/modules/AdminModule.h | 62 ++++++------ src/nimble/NimbleBluetooth.cpp | 17 +++- src/nimble/NimbleBluetooth.h | 5 +- src/platform/esp32/main-esp32.cpp | 2 - src/platform/nrf52/NRF52Bluetooth.cpp | 10 ++ src/platform/nrf52/NRF52Bluetooth.h | 5 +- src/platform/nrf52/main-nrf52.cpp | 5 +- 11 files changed, 149 insertions(+), 123 deletions(-) diff --git a/src/BluetoothCommon.h b/src/BluetoothCommon.h index 4352eba13..586ffaa3c 100644 --- a/src/BluetoothCommon.h +++ b/src/BluetoothCommon.h @@ -17,4 +17,14 @@ extern const uint8_t MESH_SERVICE_UUID_16[], TORADIO_UUID_16[16u], FROMRADIO_UUID_16[], FROMNUM_UUID_16[]; /// Given a level between 0-100, update the BLE attribute -void updateBatteryLevel(uint8_t level); \ No newline at end of file +void updateBatteryLevel(uint8_t level); + +class BluetoothApi +{ + public: + virtual void setup(); + virtual void shutdown(); + virtual void clearBonds(); + virtual bool isConnected(); + virtual int getRssi() = 0; +}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 4f65ff51b..49963a415 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,6 +33,12 @@ #ifdef ARCH_ESP32 #include "mesh/http/WebServer.h" #include "nimble/NimbleBluetooth.h" +NimbleBluetooth *nimbleBluetooth; +#endif + +#ifdef ARCH_NRF52 +#include "NRF52Bluetooth.h" +NRF52Bluetooth *nrf52Bluetooth; #endif #if HAS_WIFI diff --git a/src/main.h b/src/main.h index 9d965b0fc..b1bee1b06 100644 --- a/src/main.h +++ b/src/main.h @@ -9,6 +9,14 @@ #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) #include #endif +#if defined(ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32S2) +#include "nimble/NimbleBluetooth.h" +extern NimbleBluetooth *nimbleBluetooth; +#endif +#ifdef ARCH_NRF52 +#include "NRF52Bluetooth.h" +extern NRF52Bluetooth *nrf52Bluetooth; +#endif extern uint8_t screen_found; extern uint8_t screen_model; diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 16dee49a9..7beea8804 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -2,13 +2,16 @@ #include "Channels.h" #include "MeshService.h" #include "NodeDB.h" +#include "PowerFSM.h" #ifdef ARCH_ESP32 #include "BleOta.h" #endif #include "Router.h" #include "configuration.h" #include "main.h" - +#ifdef ARCH_NRF52 +#include "main.h" +#endif #ifdef ARCH_PORTDUINO #include "unistd.h" #endif @@ -30,8 +33,7 @@ static const char *secretReserved = "sekrit"; /// If buf is the reserved secret word, replace the buffer with currentVal static void writeSecret(char *buf, size_t bufsz, const char *currentVal) { - if (strcmp(buf, secretReserved) == 0) - { + if (strcmp(buf, secretReserved) == 0) { strncpy(buf, currentVal, bufsz); } } @@ -49,8 +51,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta bool handled = false; assert(r); - switch (r->which_payload_variant) - { + switch (r->which_payload_variant) { /** * Getters @@ -70,8 +71,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta handleGetModuleConfig(mp, r->get_module_config_request); break; - case meshtastic_AdminMessage_get_channel_request_tag: - { + case meshtastic_AdminMessage_get_channel_request_tag: { uint32_t i = r->get_channel_request - 1; LOG_INFO("Client is getting channel %u\n", i); if (i >= MAX_NUM_CHANNELS) @@ -110,22 +110,17 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta /** * Other */ - case meshtastic_AdminMessage_reboot_seconds_tag: - { + case meshtastic_AdminMessage_reboot_seconds_tag: { reboot(r->reboot_seconds); break; } - case meshtastic_AdminMessage_reboot_ota_seconds_tag: - { + case meshtastic_AdminMessage_reboot_ota_seconds_tag: { int32_t s = r->reboot_ota_seconds; #ifdef ARCH_ESP32 - if (BleOta::getOtaAppVersion().isEmpty()) - { + if (BleOta::getOtaAppVersion().isEmpty()) { LOG_INFO("No OTA firmware available, scheduling regular reboot in %d seconds\n", s); screen->startRebootScreen(); - } - else - { + } else { screen->startFirmwareUpdateScreen(); BleOta::switchToOtaApp(); LOG_INFO("Rebooting to OTA in %d seconds\n", s); @@ -137,46 +132,45 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta rebootAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } - case meshtastic_AdminMessage_shutdown_seconds_tag: - { + case meshtastic_AdminMessage_shutdown_seconds_tag: { int32_t s = r->shutdown_seconds; LOG_INFO("Shutdown in %d seconds\n", s); shutdownAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } - case meshtastic_AdminMessage_get_device_metadata_request_tag: - { + case meshtastic_AdminMessage_get_device_metadata_request_tag: { LOG_INFO("Client is getting device metadata\n"); handleGetDeviceMetadata(mp); break; } - case meshtastic_AdminMessage_factory_reset_tag: - { + case meshtastic_AdminMessage_factory_reset_tag: { LOG_INFO("Initiating factory reset\n"); nodeDB.factoryReset(); reboot(DEFAULT_REBOOT_SECONDS); break; } - case meshtastic_AdminMessage_nodedb_reset_tag: - { + case meshtastic_AdminMessage_nodedb_reset_tag: { LOG_INFO("Initiating node-db reset\n"); nodeDB.resetNodes(); reboot(DEFAULT_REBOOT_SECONDS); break; } - case meshtastic_AdminMessage_begin_edit_settings_tag: - { + case meshtastic_AdminMessage_begin_edit_settings_tag: { LOG_INFO("Beginning transaction for editing settings\n"); hasOpenEditTransaction = true; break; } - case meshtastic_AdminMessage_commit_edit_settings_tag: - { + case meshtastic_AdminMessage_commit_edit_settings_tag: { LOG_INFO("Committing transaction for edited settings\n"); hasOpenEditTransaction = false; saveChanges(SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS); break; } + case meshtastic_AdminMessage_get_device_connection_status_request_tag: { + LOG_INFO("Client is getting device connection status\n"); + handleGetDeviceConnectionStatus(mp); + break; + } #ifdef ARCH_PORTDUINO case meshtastic_AdminMessage_exit_simulator_tag: LOG_INFO("Exiting simulator\n"); @@ -188,16 +182,11 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; AdminMessageHandleResult handleResult = MeshModule::handleAdminMessageForAllPlugins(mp, r, &res); - if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) - { + if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) { myReply = allocDataProtobuf(res); - } - else if (mp.decoded.want_response) - { + } else if (mp.decoded.want_response) { LOG_DEBUG("We did not responded to a request that wanted a respond. req.variant=%d\n", r->which_payload_variant); - } - else if (handleResult != AdminMessageHandleResult::HANDLED) - { + } else if (handleResult != AdminMessageHandleResult::HANDLED) { // Probably a message sent by us or sent to our local node. FIXME, we should avoid scanning these messages LOG_INFO("Ignoring nonrelevant admin %d\n", r->which_payload_variant); } @@ -205,8 +194,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta } // If asked for a response and it is not yet set, generate an 'ACK' response - if (mp.decoded.want_response && !myReply) - { + if (mp.decoded.want_response && !myReply) { myReply = allocErrorResponse(meshtastic_Routing_Error_NONE, &mp); } @@ -222,31 +210,26 @@ void AdminModule::handleSetOwner(const meshtastic_User &o) int changed = 0; bool licensed_changed = false; - if (*o.long_name) - { + if (*o.long_name) { changed |= strcmp(owner.long_name, o.long_name); strncpy(owner.long_name, o.long_name, sizeof(owner.long_name)); } - if (*o.short_name) - { + if (*o.short_name) { changed |= strcmp(owner.short_name, o.short_name); strncpy(owner.short_name, o.short_name, sizeof(owner.short_name)); } - if (*o.id) - { + if (*o.id) { changed |= strcmp(owner.id, o.id); strncpy(owner.id, o.id, sizeof(owner.id)); } - if (owner.is_licensed != o.is_licensed) - { + if (owner.is_licensed != o.is_licensed) { changed = 1; licensed_changed = true; owner.is_licensed = o.is_licensed; config.lora.override_duty_cycle = owner.is_licensed; // override duty cycle for licensed operators } - if (changed) - { // If nothing really changed, don't broadcast on the network or write to flash + if (changed) { // If nothing really changed, don't broadcast on the network or write to flash service.reloadOwner(!hasOpenEditTransaction); licensed_changed ? saveChanges(SEGMENT_CONFIG | SEGMENT_DEVICESTATE) : saveChanges(SEGMENT_DEVICESTATE); } @@ -257,8 +240,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) auto existingRole = config.device.role; bool isRegionUnset = (config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_UNSET); - switch (c.which_payload_variant) - { + switch (c.which_payload_variant) { case meshtastic_Config_device_tag: LOG_INFO("Setting config: Device\n"); config.has_device = true; @@ -293,8 +275,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) LOG_INFO("Setting config: LoRa\n"); config.has_lora = true; config.lora = c.payload_variant.lora; - if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) - { + if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) { config.lora.tx_enabled = true; } break; @@ -310,8 +291,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) void AdminModule::handleSetModuleConfig(const meshtastic_ModuleConfig &c) { - switch (c.which_payload_variant) - { + switch (c.which_payload_variant) { case meshtastic_ModuleConfig_mqtt_tag: LOG_INFO("Setting module config: MQTT\n"); moduleConfig.has_mqtt = true; @@ -375,8 +355,7 @@ void AdminModule::handleSetChannel(const meshtastic_Channel &cc) void AdminModule::handleGetOwner(const meshtastic_MeshPacket &req) { - if (req.decoded.want_response) - { + if (req.decoded.want_response) { // We create the reply here meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; res.get_owner_response = owner; @@ -390,10 +369,8 @@ void AdminModule::handleGetConfig(const meshtastic_MeshPacket &req, const uint32 { meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; - if (req.decoded.want_response) - { - switch (configType) - { + if (req.decoded.want_response) { + switch (configType) { case meshtastic_AdminMessage_ConfigType_DEVICE_CONFIG: LOG_INFO("Getting config: Device\n"); res.get_config_response.which_payload_variant = meshtastic_Config_device_tag; @@ -448,10 +425,8 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const { meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; - if (req.decoded.want_response) - { - switch (configType) - { + if (req.decoded.want_response) { + switch (configType) { case meshtastic_AdminMessage_ModuleConfigType_MQTT_CONFIG: LOG_INFO("Getting module config: MQTT\n"); res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_mqtt_tag; @@ -541,8 +516,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r conn.has_wifi = true; conn.wifi.status.status.is_connected = WiFi.status() != WL_CONNECTED; strncpy(conn.wifi.ssid, config.network.wifi_ssid, 33); - if (conn.wifi.status.status.is_connected) - { + if (conn.wifi.status.status.is_connected) { conn.wifi.rssi = WiFi.RSSI(); conn.wifi.status.status.ip_address = WiFi.localIP(); conn.wifi.status.status.is_mqtt_connected = mqtt && mqtt->connected(); @@ -552,18 +526,27 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r #if HAS_ETHERNET conn.has_ethernet = true; - // conn.ethernet. + if (Ethernet.linkStatus() == LinkON) { + conn.conn.ethernet.status.is_connected = true; + conn.conn.ethernet.status.ip_address = Ethernet.localIP(); + conn.wifi.status.status.is_mqtt_connected = mqtt && mqtt->connected(); + conn.wifi.status.status.is_syslog_connected = false; // FIXME wire this up + } + conn.conn.ethernet.status.is_connected = false; #endif #if HAS_BLUETOOTH conn.has_bluetooth = HAS_BLUETOOTH; - // nimbleBluetooth-> - // #if ARCH_ESP32 - - // #elif + conn.bluetooth.pin = config.bluetooth.fixed_pin; +#endif +#ifdef ARCH_ESP32 + conn.bluetooth.is_connected = nimbleBluetooth->isConnected(); +#elif defined(ARCH_NRF52) + conn.bluetooth.is_connected = nrf52Bluetooth->isConnected(); #endif - conn.has_serial = true; // No serial-less devices + conn.serial.is_connected = powerFSM.getState() == &stateSERIAL; + conn.serial.baud = SERIAL_BAUD; r.get_device_connection_status_response = conn; r.which_payload_variant = meshtastic_AdminMessage_get_device_connection_status_response_tag; @@ -572,8 +555,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r void AdminModule::handleGetChannel(const meshtastic_MeshPacket &req, uint32_t channelIndex) { - if (req.decoded.want_response) - { + if (req.decoded.want_response) { // We create the reply here meshtastic_AdminMessage r = meshtastic_AdminMessage_init_default; r.get_channel_response = channels.getByIndex(channelIndex); @@ -591,17 +573,13 @@ void AdminModule::reboot(int32_t seconds) void AdminModule::saveChanges(int saveWhat, bool shouldReboot) { - if (!hasOpenEditTransaction) - { + if (!hasOpenEditTransaction) { LOG_INFO("Saving changes to disk\n"); service.reloadConfig(saveWhat); // Calls saveToDisk among other things - } - else - { + } else { LOG_INFO("Delaying save of changes to disk until the open transaction is committed\n"); } - if (shouldReboot) - { + if (shouldReboot) { reboot(DEFAULT_REBOOT_SECONDS); } } diff --git a/src/modules/AdminModule.h b/src/modules/AdminModule.h index 6924bfd7e..76f6f8033 100644 --- a/src/modules/AdminModule.h +++ b/src/modules/AdminModule.h @@ -9,41 +9,41 @@ */ class AdminModule : public ProtobufModule { -public: - /** Constructor - * name is for debugging output - */ - AdminModule(); + public: + /** Constructor + * name is for debugging output + */ + AdminModule(); -protected: - /** Called to handle a particular incoming message + protected: + /** Called to handle a particular incoming message - @return true if you've guaranteed you've handled this message and no other handlers should be considered for it - */ - virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_AdminMessage *p) override; + @return true if you've guaranteed you've handled this message and no other handlers should be considered for it + */ + virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_AdminMessage *p) override; -private: - bool hasOpenEditTransaction = false; + private: + bool hasOpenEditTransaction = false; - void saveChanges(int saveWhat, bool shouldReboot = true); - /** - * Getters - */ - void handleGetOwner(const meshtastic_MeshPacket &req); - void handleGetConfig(const meshtastic_MeshPacket &req, uint32_t configType); - void handleGetModuleConfig(const meshtastic_MeshPacket &req, uint32_t configType); - void handleGetChannel(const meshtastic_MeshPacket &req, uint32_t channelIndex); - void handleGetDeviceMetadata(const meshtastic_MeshPacket &req); - void handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &req); - /** - * Setters - */ - void handleSetOwner(const meshtastic_User &o); - void handleSetChannel(const meshtastic_Channel &cc); - void handleSetConfig(const meshtastic_Config &c); - void handleSetModuleConfig(const meshtastic_ModuleConfig &c); - void handleSetChannel(); - void reboot(int32_t seconds); + void saveChanges(int saveWhat, bool shouldReboot = true); + /** + * Getters + */ + void handleGetOwner(const meshtastic_MeshPacket &req); + void handleGetConfig(const meshtastic_MeshPacket &req, uint32_t configType); + void handleGetModuleConfig(const meshtastic_MeshPacket &req, uint32_t configType); + void handleGetChannel(const meshtastic_MeshPacket &req, uint32_t channelIndex); + void handleGetDeviceMetadata(const meshtastic_MeshPacket &req); + void handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &req); + /** + * Setters + */ + void handleSetOwner(const meshtastic_User &o); + void handleSetChannel(const meshtastic_Channel &cc); + void handleSetConfig(const meshtastic_Config &c); + void handleSetModuleConfig(const meshtastic_ModuleConfig &c); + void handleSetChannel(); + void reboot(int32_t seconds); }; extern AdminModule *adminModule; diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp index 79be9a35b..1f06b25f2 100644 --- a/src/nimble/NimbleBluetooth.cpp +++ b/src/nimble/NimbleBluetooth.cpp @@ -93,7 +93,6 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks passkeyShowing = false; screen->stopBluetoothPinScreen(); } - // bluetoothPhoneAPI->setInitialState(); } virtual void onDisconnect(NimBLEServer *pServer, ble_gap_conn_desc *desc) { LOG_INFO("BLE disconnect\n"); } @@ -117,6 +116,21 @@ bool NimbleBluetooth::isActive() return bleServer; } +bool NimbleBluetooth::isConnected() +{ + return bleServer->getConnectedCount() > 0; +} + +int NimbleBluetooth::getRssi() +{ + if (bleServer && isConnected()) { + auto service = bleServer->getServiceByUUID(MESH_SERVICE_UUID); + uint16_t handle = service->getHandle(); + return NimBLEDevice::getClientByID(handle)->getRssi(); + } + return 0; // FIXME figure out where to source this +} + void NimbleBluetooth::setup() { // Uncomment for testing @@ -135,7 +149,6 @@ void NimbleBluetooth::setup() NimbleBluetoothServerCallback *serverCallbacks = new NimbleBluetoothServerCallback(); bleServer->setCallbacks(serverCallbacks, true); - setupService(); startAdvertising(); } diff --git a/src/nimble/NimbleBluetooth.h b/src/nimble/NimbleBluetooth.h index ec0fe0841..4080a7cbc 100644 --- a/src/nimble/NimbleBluetooth.h +++ b/src/nimble/NimbleBluetooth.h @@ -1,12 +1,15 @@ #pragma once +#include "BluetoothCommon.h" -class NimbleBluetooth +class NimbleBluetooth : BluetoothApi { public: void setup(); void shutdown(); void clearBonds(); bool isActive(); + bool isConnected(); + int getRssi(); private: void setupService(); diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index ca757a6e5..f6bd4f50e 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -19,11 +19,9 @@ #include #if !defined(CONFIG_IDF_TARGET_ESP32S2) -NimbleBluetooth *nimbleBluetooth; void setBluetoothEnable(bool on) { - if (!isWifiAvailable() && config.bluetooth.enabled == true) { if (!nimbleBluetooth) { nimbleBluetooth = new NimbleBluetooth(); diff --git a/src/platform/nrf52/NRF52Bluetooth.cpp b/src/platform/nrf52/NRF52Bluetooth.cpp index 06b07f593..044b57ae6 100644 --- a/src/platform/nrf52/NRF52Bluetooth.cpp +++ b/src/platform/nrf52/NRF52Bluetooth.cpp @@ -213,6 +213,16 @@ void NRF52Bluetooth::shutdown() Bluefruit.Advertising.stop(); } +bool NRF52Bluetooth::isConnected() +{ + return Bluefruit.connected(connectionHandle); +} + +int NRF52Bluetooth::getRssi() +{ + return 0; // FIXME figure out where to source this +} + void NRF52Bluetooth::setup() { // Initialise the Bluefruit module diff --git a/src/platform/nrf52/NRF52Bluetooth.h b/src/platform/nrf52/NRF52Bluetooth.h index b4438ff39..193e86cf8 100644 --- a/src/platform/nrf52/NRF52Bluetooth.h +++ b/src/platform/nrf52/NRF52Bluetooth.h @@ -1,13 +1,16 @@ #pragma once +#include "BluetoothCommon.h" #include -class NRF52Bluetooth +class NRF52Bluetooth : BluetoothApi { public: void setup(); void shutdown(); void clearBonds(); + bool isConnected(); + int getRssi(); private: static void onConnectionSecured(uint16_t conn_handle); diff --git a/src/platform/nrf52/main-nrf52.cpp b/src/platform/nrf52/main-nrf52.cpp index 0384073a4..1cbe05631 100644 --- a/src/platform/nrf52/main-nrf52.cpp +++ b/src/platform/nrf52/main-nrf52.cpp @@ -8,9 +8,8 @@ #include // #include #include "NodeDB.h" - -#include "NRF52Bluetooth.h" #include "error.h" +#include "main.h" #ifdef BQ25703A_ADDR #include "BQ25713.h" @@ -63,8 +62,6 @@ static void initBrownout() // We don't bother with setting up brownout if soft device is disabled - because during production we always use softdevice } -NRF52Bluetooth *nrf52Bluetooth; - static bool bleOn = false; static const bool useSoftDevice = true; // Set to false for easier debugging From b97e61d8f81388c5610de161561d58ee2f4e0a1c Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 08:51:02 -0600 Subject: [PATCH 15/54] Whoops --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 0f3e4cc4d..1d8083f70 100644 --- a/platformio.ini +++ b/platformio.ini @@ -2,7 +2,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = tbeam +;default_envs = tbeam ;default_envs = pico ;default_envs = tbeam-s3-core ;default_envs = tbeam0.7 From 835e6ab85e2f0f416897292ce19e4a44a74da1fb Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 08:52:32 -0600 Subject: [PATCH 16/54] Missed RSSI --- src/modules/AdminModule.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 7beea8804..e240c05bd 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -541,6 +541,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r #endif #ifdef ARCH_ESP32 conn.bluetooth.is_connected = nimbleBluetooth->isConnected(); + conn.bluetooth.rssi = nimbleBluetooth->getRssi(); #elif defined(ARCH_NRF52) conn.bluetooth.is_connected = nrf52Bluetooth->isConnected(); #endif From 5794a9ae06142d73a0d180a2c1413394f6ff3d89 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 09:04:22 -0600 Subject: [PATCH 17/54] Bad copy pasta --- src/modules/AdminModule.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index e240c05bd..b9b75a224 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -527,10 +527,10 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r #if HAS_ETHERNET conn.has_ethernet = true; if (Ethernet.linkStatus() == LinkON) { - conn.conn.ethernet.status.is_connected = true; - conn.conn.ethernet.status.ip_address = Ethernet.localIP(); - conn.wifi.status.status.is_mqtt_connected = mqtt && mqtt->connected(); - conn.wifi.status.status.is_syslog_connected = false; // FIXME wire this up + conn.ethernet.status.is_connected = true; + conn.ethernet.status.ip_address = Ethernet.localIP(); + conn.ethernet.status.status.is_mqtt_connected = mqtt && mqtt->connected(); + conn.ethernet.status.status.is_syslog_connected = false; // FIXME wire this up } conn.conn.ethernet.status.is_connected = false; #endif From 4aaf16270002202a79993c56e494ff5a77059d3e Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 09:17:28 -0600 Subject: [PATCH 18/54] Getting tired of looking at code --- src/modules/AdminModule.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index b9b75a224..cecb4655c 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -529,8 +529,8 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r if (Ethernet.linkStatus() == LinkON) { conn.ethernet.status.is_connected = true; conn.ethernet.status.ip_address = Ethernet.localIP(); - conn.ethernet.status.status.is_mqtt_connected = mqtt && mqtt->connected(); - conn.ethernet.status.status.is_syslog_connected = false; // FIXME wire this up + conn.ethernet.status.is_mqtt_connected = mqtt && mqtt->connected(); + conn.ethernet.status.is_syslog_connected = false; // FIXME wire this up } conn.conn.ethernet.status.is_connected = false; #endif From 51521462c4fa2cd35a80c0439421374176059d24 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 09:18:53 -0600 Subject: [PATCH 19/54] Eh --- src/modules/AdminModule.cpp | 117 ++++++++++++++++++++++++------------ 1 file changed, 79 insertions(+), 38 deletions(-) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index cecb4655c..2688a2959 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -33,7 +33,8 @@ static const char *secretReserved = "sekrit"; /// If buf is the reserved secret word, replace the buffer with currentVal static void writeSecret(char *buf, size_t bufsz, const char *currentVal) { - if (strcmp(buf, secretReserved) == 0) { + if (strcmp(buf, secretReserved) == 0) + { strncpy(buf, currentVal, bufsz); } } @@ -51,7 +52,8 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta bool handled = false; assert(r); - switch (r->which_payload_variant) { + switch (r->which_payload_variant) + { /** * Getters @@ -71,7 +73,8 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta handleGetModuleConfig(mp, r->get_module_config_request); break; - case meshtastic_AdminMessage_get_channel_request_tag: { + case meshtastic_AdminMessage_get_channel_request_tag: + { uint32_t i = r->get_channel_request - 1; LOG_INFO("Client is getting channel %u\n", i); if (i >= MAX_NUM_CHANNELS) @@ -110,17 +113,22 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta /** * Other */ - case meshtastic_AdminMessage_reboot_seconds_tag: { + case meshtastic_AdminMessage_reboot_seconds_tag: + { reboot(r->reboot_seconds); break; } - case meshtastic_AdminMessage_reboot_ota_seconds_tag: { + case meshtastic_AdminMessage_reboot_ota_seconds_tag: + { int32_t s = r->reboot_ota_seconds; #ifdef ARCH_ESP32 - if (BleOta::getOtaAppVersion().isEmpty()) { + if (BleOta::getOtaAppVersion().isEmpty()) + { LOG_INFO("No OTA firmware available, scheduling regular reboot in %d seconds\n", s); screen->startRebootScreen(); - } else { + } + else + { screen->startFirmwareUpdateScreen(); BleOta::switchToOtaApp(); LOG_INFO("Rebooting to OTA in %d seconds\n", s); @@ -132,41 +140,48 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta rebootAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } - case meshtastic_AdminMessage_shutdown_seconds_tag: { + case meshtastic_AdminMessage_shutdown_seconds_tag: + { int32_t s = r->shutdown_seconds; LOG_INFO("Shutdown in %d seconds\n", s); shutdownAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } - case meshtastic_AdminMessage_get_device_metadata_request_tag: { + case meshtastic_AdminMessage_get_device_metadata_request_tag: + { LOG_INFO("Client is getting device metadata\n"); handleGetDeviceMetadata(mp); break; } - case meshtastic_AdminMessage_factory_reset_tag: { + case meshtastic_AdminMessage_factory_reset_tag: + { LOG_INFO("Initiating factory reset\n"); nodeDB.factoryReset(); reboot(DEFAULT_REBOOT_SECONDS); break; } - case meshtastic_AdminMessage_nodedb_reset_tag: { + case meshtastic_AdminMessage_nodedb_reset_tag: + { LOG_INFO("Initiating node-db reset\n"); nodeDB.resetNodes(); reboot(DEFAULT_REBOOT_SECONDS); break; } - case meshtastic_AdminMessage_begin_edit_settings_tag: { + case meshtastic_AdminMessage_begin_edit_settings_tag: + { LOG_INFO("Beginning transaction for editing settings\n"); hasOpenEditTransaction = true; break; } - case meshtastic_AdminMessage_commit_edit_settings_tag: { + case meshtastic_AdminMessage_commit_edit_settings_tag: + { LOG_INFO("Committing transaction for edited settings\n"); hasOpenEditTransaction = false; saveChanges(SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS); break; } - case meshtastic_AdminMessage_get_device_connection_status_request_tag: { + case meshtastic_AdminMessage_get_device_connection_status_request_tag: + { LOG_INFO("Client is getting device connection status\n"); handleGetDeviceConnectionStatus(mp); break; @@ -182,11 +197,16 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; AdminMessageHandleResult handleResult = MeshModule::handleAdminMessageForAllPlugins(mp, r, &res); - if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) { + if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) + { myReply = allocDataProtobuf(res); - } else if (mp.decoded.want_response) { + } + else if (mp.decoded.want_response) + { LOG_DEBUG("We did not responded to a request that wanted a respond. req.variant=%d\n", r->which_payload_variant); - } else if (handleResult != AdminMessageHandleResult::HANDLED) { + } + else if (handleResult != AdminMessageHandleResult::HANDLED) + { // Probably a message sent by us or sent to our local node. FIXME, we should avoid scanning these messages LOG_INFO("Ignoring nonrelevant admin %d\n", r->which_payload_variant); } @@ -194,7 +214,8 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta } // If asked for a response and it is not yet set, generate an 'ACK' response - if (mp.decoded.want_response && !myReply) { + if (mp.decoded.want_response && !myReply) + { myReply = allocErrorResponse(meshtastic_Routing_Error_NONE, &mp); } @@ -210,26 +231,31 @@ void AdminModule::handleSetOwner(const meshtastic_User &o) int changed = 0; bool licensed_changed = false; - if (*o.long_name) { + if (*o.long_name) + { changed |= strcmp(owner.long_name, o.long_name); strncpy(owner.long_name, o.long_name, sizeof(owner.long_name)); } - if (*o.short_name) { + if (*o.short_name) + { changed |= strcmp(owner.short_name, o.short_name); strncpy(owner.short_name, o.short_name, sizeof(owner.short_name)); } - if (*o.id) { + if (*o.id) + { changed |= strcmp(owner.id, o.id); strncpy(owner.id, o.id, sizeof(owner.id)); } - if (owner.is_licensed != o.is_licensed) { + if (owner.is_licensed != o.is_licensed) + { changed = 1; licensed_changed = true; owner.is_licensed = o.is_licensed; config.lora.override_duty_cycle = owner.is_licensed; // override duty cycle for licensed operators } - if (changed) { // If nothing really changed, don't broadcast on the network or write to flash + if (changed) + { // If nothing really changed, don't broadcast on the network or write to flash service.reloadOwner(!hasOpenEditTransaction); licensed_changed ? saveChanges(SEGMENT_CONFIG | SEGMENT_DEVICESTATE) : saveChanges(SEGMENT_DEVICESTATE); } @@ -240,7 +266,8 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) auto existingRole = config.device.role; bool isRegionUnset = (config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_UNSET); - switch (c.which_payload_variant) { + switch (c.which_payload_variant) + { case meshtastic_Config_device_tag: LOG_INFO("Setting config: Device\n"); config.has_device = true; @@ -275,7 +302,8 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) LOG_INFO("Setting config: LoRa\n"); config.has_lora = true; config.lora = c.payload_variant.lora; - if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) { + if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) + { config.lora.tx_enabled = true; } break; @@ -291,7 +319,8 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) void AdminModule::handleSetModuleConfig(const meshtastic_ModuleConfig &c) { - switch (c.which_payload_variant) { + switch (c.which_payload_variant) + { case meshtastic_ModuleConfig_mqtt_tag: LOG_INFO("Setting module config: MQTT\n"); moduleConfig.has_mqtt = true; @@ -355,7 +384,8 @@ void AdminModule::handleSetChannel(const meshtastic_Channel &cc) void AdminModule::handleGetOwner(const meshtastic_MeshPacket &req) { - if (req.decoded.want_response) { + if (req.decoded.want_response) + { // We create the reply here meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; res.get_owner_response = owner; @@ -369,8 +399,10 @@ void AdminModule::handleGetConfig(const meshtastic_MeshPacket &req, const uint32 { meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; - if (req.decoded.want_response) { - switch (configType) { + if (req.decoded.want_response) + { + switch (configType) + { case meshtastic_AdminMessage_ConfigType_DEVICE_CONFIG: LOG_INFO("Getting config: Device\n"); res.get_config_response.which_payload_variant = meshtastic_Config_device_tag; @@ -425,8 +457,10 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const { meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; - if (req.decoded.want_response) { - switch (configType) { + if (req.decoded.want_response) + { + switch (configType) + { case meshtastic_AdminMessage_ModuleConfigType_MQTT_CONFIG: LOG_INFO("Getting module config: MQTT\n"); res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_mqtt_tag; @@ -516,7 +550,8 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r conn.has_wifi = true; conn.wifi.status.status.is_connected = WiFi.status() != WL_CONNECTED; strncpy(conn.wifi.ssid, config.network.wifi_ssid, 33); - if (conn.wifi.status.status.is_connected) { + if (conn.wifi.status.status.is_connected) + { conn.wifi.rssi = WiFi.RSSI(); conn.wifi.status.status.ip_address = WiFi.localIP(); conn.wifi.status.status.is_mqtt_connected = mqtt && mqtt->connected(); @@ -526,13 +561,14 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r #if HAS_ETHERNET conn.has_ethernet = true; - if (Ethernet.linkStatus() == LinkON) { + if (Ethernet.linkStatus() == LinkON) + { conn.ethernet.status.is_connected = true; conn.ethernet.status.ip_address = Ethernet.localIP(); conn.ethernet.status.is_mqtt_connected = mqtt && mqtt->connected(); conn.ethernet.status.is_syslog_connected = false; // FIXME wire this up } - conn.conn.ethernet.status.is_connected = false; + conn.ethernet.status.is_connected = false; #endif #if HAS_BLUETOOTH @@ -556,7 +592,8 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r void AdminModule::handleGetChannel(const meshtastic_MeshPacket &req, uint32_t channelIndex) { - if (req.decoded.want_response) { + if (req.decoded.want_response) + { // We create the reply here meshtastic_AdminMessage r = meshtastic_AdminMessage_init_default; r.get_channel_response = channels.getByIndex(channelIndex); @@ -574,13 +611,17 @@ void AdminModule::reboot(int32_t seconds) void AdminModule::saveChanges(int saveWhat, bool shouldReboot) { - if (!hasOpenEditTransaction) { + if (!hasOpenEditTransaction) + { LOG_INFO("Saving changes to disk\n"); service.reloadConfig(saveWhat); // Calls saveToDisk among other things - } else { + } + else + { LOG_INFO("Delaying save of changes to disk until the open transaction is committed\n"); } - if (shouldReboot) { + if (shouldReboot) + { reboot(DEFAULT_REBOOT_SECONDS); } } From 1fa2ca6a14e7c97481e7069853ebfcc8e94e1397 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 09:50:49 -0600 Subject: [PATCH 20/54] Trunk it --- src/modules/AdminModule.cpp | 115 ++++++++++++------------------------ 1 file changed, 37 insertions(+), 78 deletions(-) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 2688a2959..f52aa4e0f 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -33,8 +33,7 @@ static const char *secretReserved = "sekrit"; /// If buf is the reserved secret word, replace the buffer with currentVal static void writeSecret(char *buf, size_t bufsz, const char *currentVal) { - if (strcmp(buf, secretReserved) == 0) - { + if (strcmp(buf, secretReserved) == 0) { strncpy(buf, currentVal, bufsz); } } @@ -52,8 +51,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta bool handled = false; assert(r); - switch (r->which_payload_variant) - { + switch (r->which_payload_variant) { /** * Getters @@ -73,8 +71,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta handleGetModuleConfig(mp, r->get_module_config_request); break; - case meshtastic_AdminMessage_get_channel_request_tag: - { + case meshtastic_AdminMessage_get_channel_request_tag: { uint32_t i = r->get_channel_request - 1; LOG_INFO("Client is getting channel %u\n", i); if (i >= MAX_NUM_CHANNELS) @@ -113,22 +110,17 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta /** * Other */ - case meshtastic_AdminMessage_reboot_seconds_tag: - { + case meshtastic_AdminMessage_reboot_seconds_tag: { reboot(r->reboot_seconds); break; } - case meshtastic_AdminMessage_reboot_ota_seconds_tag: - { + case meshtastic_AdminMessage_reboot_ota_seconds_tag: { int32_t s = r->reboot_ota_seconds; #ifdef ARCH_ESP32 - if (BleOta::getOtaAppVersion().isEmpty()) - { + if (BleOta::getOtaAppVersion().isEmpty()) { LOG_INFO("No OTA firmware available, scheduling regular reboot in %d seconds\n", s); screen->startRebootScreen(); - } - else - { + } else { screen->startFirmwareUpdateScreen(); BleOta::switchToOtaApp(); LOG_INFO("Rebooting to OTA in %d seconds\n", s); @@ -140,48 +132,41 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta rebootAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } - case meshtastic_AdminMessage_shutdown_seconds_tag: - { + case meshtastic_AdminMessage_shutdown_seconds_tag: { int32_t s = r->shutdown_seconds; LOG_INFO("Shutdown in %d seconds\n", s); shutdownAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } - case meshtastic_AdminMessage_get_device_metadata_request_tag: - { + case meshtastic_AdminMessage_get_device_metadata_request_tag: { LOG_INFO("Client is getting device metadata\n"); handleGetDeviceMetadata(mp); break; } - case meshtastic_AdminMessage_factory_reset_tag: - { + case meshtastic_AdminMessage_factory_reset_tag: { LOG_INFO("Initiating factory reset\n"); nodeDB.factoryReset(); reboot(DEFAULT_REBOOT_SECONDS); break; } - case meshtastic_AdminMessage_nodedb_reset_tag: - { + case meshtastic_AdminMessage_nodedb_reset_tag: { LOG_INFO("Initiating node-db reset\n"); nodeDB.resetNodes(); reboot(DEFAULT_REBOOT_SECONDS); break; } - case meshtastic_AdminMessage_begin_edit_settings_tag: - { + case meshtastic_AdminMessage_begin_edit_settings_tag: { LOG_INFO("Beginning transaction for editing settings\n"); hasOpenEditTransaction = true; break; } - case meshtastic_AdminMessage_commit_edit_settings_tag: - { + case meshtastic_AdminMessage_commit_edit_settings_tag: { LOG_INFO("Committing transaction for edited settings\n"); hasOpenEditTransaction = false; saveChanges(SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS); break; } - case meshtastic_AdminMessage_get_device_connection_status_request_tag: - { + case meshtastic_AdminMessage_get_device_connection_status_request_tag: { LOG_INFO("Client is getting device connection status\n"); handleGetDeviceConnectionStatus(mp); break; @@ -197,16 +182,11 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; AdminMessageHandleResult handleResult = MeshModule::handleAdminMessageForAllPlugins(mp, r, &res); - if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) - { + if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) { myReply = allocDataProtobuf(res); - } - else if (mp.decoded.want_response) - { + } else if (mp.decoded.want_response) { LOG_DEBUG("We did not responded to a request that wanted a respond. req.variant=%d\n", r->which_payload_variant); - } - else if (handleResult != AdminMessageHandleResult::HANDLED) - { + } else if (handleResult != AdminMessageHandleResult::HANDLED) { // Probably a message sent by us or sent to our local node. FIXME, we should avoid scanning these messages LOG_INFO("Ignoring nonrelevant admin %d\n", r->which_payload_variant); } @@ -214,8 +194,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta } // If asked for a response and it is not yet set, generate an 'ACK' response - if (mp.decoded.want_response && !myReply) - { + if (mp.decoded.want_response && !myReply) { myReply = allocErrorResponse(meshtastic_Routing_Error_NONE, &mp); } @@ -231,31 +210,26 @@ void AdminModule::handleSetOwner(const meshtastic_User &o) int changed = 0; bool licensed_changed = false; - if (*o.long_name) - { + if (*o.long_name) { changed |= strcmp(owner.long_name, o.long_name); strncpy(owner.long_name, o.long_name, sizeof(owner.long_name)); } - if (*o.short_name) - { + if (*o.short_name) { changed |= strcmp(owner.short_name, o.short_name); strncpy(owner.short_name, o.short_name, sizeof(owner.short_name)); } - if (*o.id) - { + if (*o.id) { changed |= strcmp(owner.id, o.id); strncpy(owner.id, o.id, sizeof(owner.id)); } - if (owner.is_licensed != o.is_licensed) - { + if (owner.is_licensed != o.is_licensed) { changed = 1; licensed_changed = true; owner.is_licensed = o.is_licensed; config.lora.override_duty_cycle = owner.is_licensed; // override duty cycle for licensed operators } - if (changed) - { // If nothing really changed, don't broadcast on the network or write to flash + if (changed) { // If nothing really changed, don't broadcast on the network or write to flash service.reloadOwner(!hasOpenEditTransaction); licensed_changed ? saveChanges(SEGMENT_CONFIG | SEGMENT_DEVICESTATE) : saveChanges(SEGMENT_DEVICESTATE); } @@ -266,8 +240,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) auto existingRole = config.device.role; bool isRegionUnset = (config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_UNSET); - switch (c.which_payload_variant) - { + switch (c.which_payload_variant) { case meshtastic_Config_device_tag: LOG_INFO("Setting config: Device\n"); config.has_device = true; @@ -302,8 +275,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) LOG_INFO("Setting config: LoRa\n"); config.has_lora = true; config.lora = c.payload_variant.lora; - if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) - { + if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) { config.lora.tx_enabled = true; } break; @@ -319,8 +291,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) void AdminModule::handleSetModuleConfig(const meshtastic_ModuleConfig &c) { - switch (c.which_payload_variant) - { + switch (c.which_payload_variant) { case meshtastic_ModuleConfig_mqtt_tag: LOG_INFO("Setting module config: MQTT\n"); moduleConfig.has_mqtt = true; @@ -384,8 +355,7 @@ void AdminModule::handleSetChannel(const meshtastic_Channel &cc) void AdminModule::handleGetOwner(const meshtastic_MeshPacket &req) { - if (req.decoded.want_response) - { + if (req.decoded.want_response) { // We create the reply here meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; res.get_owner_response = owner; @@ -399,10 +369,8 @@ void AdminModule::handleGetConfig(const meshtastic_MeshPacket &req, const uint32 { meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; - if (req.decoded.want_response) - { - switch (configType) - { + if (req.decoded.want_response) { + switch (configType) { case meshtastic_AdminMessage_ConfigType_DEVICE_CONFIG: LOG_INFO("Getting config: Device\n"); res.get_config_response.which_payload_variant = meshtastic_Config_device_tag; @@ -457,10 +425,8 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const { meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; - if (req.decoded.want_response) - { - switch (configType) - { + if (req.decoded.want_response) { + switch (configType) { case meshtastic_AdminMessage_ModuleConfigType_MQTT_CONFIG: LOG_INFO("Getting module config: MQTT\n"); res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_mqtt_tag; @@ -550,8 +516,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r conn.has_wifi = true; conn.wifi.status.status.is_connected = WiFi.status() != WL_CONNECTED; strncpy(conn.wifi.ssid, config.network.wifi_ssid, 33); - if (conn.wifi.status.status.is_connected) - { + if (conn.wifi.status.status.is_connected) { conn.wifi.rssi = WiFi.RSSI(); conn.wifi.status.status.ip_address = WiFi.localIP(); conn.wifi.status.status.is_mqtt_connected = mqtt && mqtt->connected(); @@ -561,8 +526,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r #if HAS_ETHERNET conn.has_ethernet = true; - if (Ethernet.linkStatus() == LinkON) - { + if (Ethernet.linkStatus() == LinkON) { conn.ethernet.status.is_connected = true; conn.ethernet.status.ip_address = Ethernet.localIP(); conn.ethernet.status.is_mqtt_connected = mqtt && mqtt->connected(); @@ -592,8 +556,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r void AdminModule::handleGetChannel(const meshtastic_MeshPacket &req, uint32_t channelIndex) { - if (req.decoded.want_response) - { + if (req.decoded.want_response) { // We create the reply here meshtastic_AdminMessage r = meshtastic_AdminMessage_init_default; r.get_channel_response = channels.getByIndex(channelIndex); @@ -611,17 +574,13 @@ void AdminModule::reboot(int32_t seconds) void AdminModule::saveChanges(int saveWhat, bool shouldReboot) { - if (!hasOpenEditTransaction) - { + if (!hasOpenEditTransaction) { LOG_INFO("Saving changes to disk\n"); service.reloadConfig(saveWhat); // Calls saveToDisk among other things - } - else - { + } else { LOG_INFO("Delaying save of changes to disk until the open transaction is committed\n"); } - if (shouldReboot) - { + if (shouldReboot) { reboot(DEFAULT_REBOOT_SECONDS); } } From 7a509341852b61ce7ba89bca949d6e9ece66c4e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Fri, 3 Feb 2023 00:40:51 +0100 Subject: [PATCH 21/54] change time display to relative for rx messages --- src/graphics/Screen.cpp | 67 ++++++++++++++--------------------------- src/graphics/Screen.h | 3 ++ src/mesh/NodeDB.cpp | 11 +++++++ src/mesh/NodeDB.h | 3 ++ 4 files changed, 39 insertions(+), 45 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index ed5e1c3a0..09cafc348 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -380,13 +380,16 @@ static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state display->setColor(BLACK); } - tm *tm = localtime(reinterpret_cast(&mp.rx_time)); + uint32_t seconds = sinceReceived(&mp); + uint32_t minutes = seconds / 60; + uint32_t hours = minutes / 60; + uint32_t days = hours / 24; if (config.display.heading_bold) { - display->drawStringf(1 + x, 0 + y, tempBuf, "[%02d:%02d:%02d] From: %s", tm->tm_hour, tm->tm_min, tm->tm_sec, + display->drawStringf(1 + x, 0 + y, tempBuf, "%s ago from %s", screen->drawTimeDelta(days, hours, minutes, seconds), (node && node->has_user) ? node->user.short_name : "???"); } - display->drawStringf(0 + x, 0 + y, tempBuf, "[%02d:%02d:%02d] From: %s", tm->tm_hour, tm->tm_min, tm->tm_sec, + display->drawStringf(0 + x, 0 + y, tempBuf, "%s ago from %s", screen->drawTimeDelta(days, hours, minutes, seconds), (node && node->has_user) ? node->user.short_name : "???"); display->setColor(WHITE); @@ -417,38 +420,6 @@ static void drawColumns(OLEDDisplay *display, int16_t x, int16_t y, const char * } } -#if 0 - /// Draw a series of fields in a row, wrapping to multiple rows if needed - /// @return the max y we ended up printing to - static uint32_t drawRows(OLEDDisplay *display, int16_t x, int16_t y, const char **fields) - { - // The coordinates define the left starting point of the text - display->setTextAlignment(TEXT_ALIGN_LEFT); - - const char **f = fields; - int xo = x, yo = y; - const int COLUMNS = 2; // hardwired for two columns per row.... - int col = 0; // track which column we are on - while (*f) { - display->drawString(xo, yo, *f); - xo += SCREEN_WIDTH / COLUMNS; - // Wrap to next row, if needed. - if (++col >= COLUMNS) { - xo = x; - yo += FONT_HEIGHT_SMALL; - col = 0; - } - f++; - } - if (col != 0) { - // Include last incomplete line in our total. - yo += FONT_HEIGHT_SMALL; - } - - return yo; - } -#endif - // Draw power bars or a charging indicator on an image of a battery, determined by battery charge voltage or percentage. static void drawBattery(OLEDDisplay *display, int16_t x, int16_t y, uint8_t *imgBuffer, const PowerStatus *powerStatus) { @@ -1365,6 +1336,20 @@ void Screen::blink() dispdev.setBrightness(brightness); } +String Screen::drawTimeDelta(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds) +{ + String uptime; + if (days >= 2) + uptime = String(days) + "d"; + else if (hours >= 2) + uptime = String(hours) + "h"; + else if (minutes >= 1) + uptime = String(minutes) + "m"; + else + uptime = String(seconds) + "s"; + return uptime; +} + void Screen::handlePrint(const char *text) { // the string passed into us probably has a newline, but that would confuse the logging system @@ -1729,15 +1714,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat display->setColor(WHITE); // Show uptime as days, hours, minutes OR seconds - String uptime; - if (days >= 2) - uptime += String(days) + "d "; - else if (hours >= 2) - uptime += String(hours) + "h "; - else if (minutes >= 1) - uptime += String(minutes) + "m "; - else - uptime += String(seconds) + "s "; + String uptime = screen->drawTimeDelta(days, hours, minutes, seconds); uint32_t rtc_sec = getValidTime(RTCQuality::RTCQualityDevice); if (rtc_sec > 0) { @@ -1753,7 +1730,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat int sec = (hms % SEC_PER_HOUR) % SEC_PER_MIN; // or hms % SEC_PER_MIN char timebuf[9]; - snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d", hour, min, sec); + snprintf(timebuf, sizeof(timebuf), " %02d:%02d:%02d", hour, min, sec); uptime += timebuf; } diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index db851e8bb..1d732ad4c 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -206,6 +206,9 @@ class Screen : public concurrency::OSThread } } + /// generates a very brief time delta display + String drawTimeDelta(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds); + /// Overrides the default utf8 character conversion, to replace empty space with question marks static char customFontTableLookup(const uint8_t ch) { diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 37697bc18..89063f550 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -599,6 +599,17 @@ uint32_t sinceLastSeen(const meshtastic_NodeInfo *n) return delta; } +uint32_t sinceReceived(const meshtastic_MeshPacket *p) +{ + uint32_t now = getTime(); + + int delta = (int)(now - p->rx_time); + if (delta < 0) // our clock must be slightly off still - not set from GPS yet + delta = 0; + + return delta; +} + #define NUM_ONLINE_SECS (60 * 60 * 2) // 2 hrs to consider someone offline size_t NodeDB::getNumOnlineNodes() diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index 106d35402..a6fbd9cb0 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -32,6 +32,9 @@ extern meshtastic_User &owner; /// Given a node, return how many seconds in the past (vs now) that we last heard from it uint32_t sinceLastSeen(const meshtastic_NodeInfo *n); +/// Given a packet, return how many seconds in the past (vs now) it was received +uint32_t sinceReceived(const meshtastic_MeshPacket *p); + class NodeDB { // NodeNum provisionalNodeNum; // if we are trying to find a node num this is our current attempt From 0414ca2dc0c1fbb518e0686775b765ffb4a48fac Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 10:49:44 -0600 Subject: [PATCH 22/54] Fixed it --- protobufs | 2 +- .../meshtastic/connection_status.pb.h | 34 ++--- src/modules/AdminModule.cpp | 132 ++++++++++++------ 3 files changed, 107 insertions(+), 61 deletions(-) diff --git a/protobufs b/protobufs index 4ef7e46a8..516074f2e 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 4ef7e46a8b83d4d2147f027c7aaa7d1b481f8688 +Subproject commit 516074f2e49743c234430abb2ea43ea3f66b0acb diff --git a/src/mesh/generated/meshtastic/connection_status.pb.h b/src/mesh/generated/meshtastic/connection_status.pb.h index c13ec2bc6..c824f8b82 100644 --- a/src/mesh/generated/meshtastic/connection_status.pb.h +++ b/src/mesh/generated/meshtastic/connection_status.pb.h @@ -22,6 +22,17 @@ typedef struct _meshtastic_NetworkConnectionStatus { bool is_syslog_connected; } meshtastic_NetworkConnectionStatus; +/* WiFi connection status */ +typedef struct _meshtastic_WifiConnectionStatus { + /* Connection status */ + bool has_status; + meshtastic_NetworkConnectionStatus status; + /* WiFi access point ssid */ + char ssid[33]; + /* Rssi of wireless connection */ + int32_t rssi; +} meshtastic_WifiConnectionStatus; + /* Ethernet connection status */ typedef struct _meshtastic_EthernetConnectionStatus { /* Connection status */ @@ -29,17 +40,6 @@ typedef struct _meshtastic_EthernetConnectionStatus { meshtastic_NetworkConnectionStatus status; } meshtastic_EthernetConnectionStatus; -/* WiFi connection status */ -typedef struct _meshtastic_WifiConnectionStatus { - /* Connection status */ - bool has_status; - meshtastic_EthernetConnectionStatus status; - /* WiFi access point ssid */ - char ssid[33]; - /* Rssi of wireless connection */ - int32_t rssi; -} meshtastic_WifiConnectionStatus; - /* Bluetooth connection status */ typedef struct _meshtastic_BluetoothConnectionStatus { /* The pairing pin for bluetooth */ @@ -80,13 +80,13 @@ extern "C" { /* Initializer values for message structs */ #define meshtastic_DeviceConnectionStatus_init_default {false, meshtastic_WifiConnectionStatus_init_default, false, meshtastic_EthernetConnectionStatus_init_default, false, meshtastic_BluetoothConnectionStatus_init_default, false, meshtastic_SerialConnectionStatus_init_default} -#define meshtastic_WifiConnectionStatus_init_default {false, meshtastic_EthernetConnectionStatus_init_default, "", 0} +#define meshtastic_WifiConnectionStatus_init_default {false, meshtastic_NetworkConnectionStatus_init_default, "", 0} #define meshtastic_EthernetConnectionStatus_init_default {false, meshtastic_NetworkConnectionStatus_init_default} #define meshtastic_NetworkConnectionStatus_init_default {0, 0, 0, 0} #define meshtastic_BluetoothConnectionStatus_init_default {0, 0, 0} #define meshtastic_SerialConnectionStatus_init_default {0, 0} #define meshtastic_DeviceConnectionStatus_init_zero {false, meshtastic_WifiConnectionStatus_init_zero, false, meshtastic_EthernetConnectionStatus_init_zero, false, meshtastic_BluetoothConnectionStatus_init_zero, false, meshtastic_SerialConnectionStatus_init_zero} -#define meshtastic_WifiConnectionStatus_init_zero {false, meshtastic_EthernetConnectionStatus_init_zero, "", 0} +#define meshtastic_WifiConnectionStatus_init_zero {false, meshtastic_NetworkConnectionStatus_init_zero, "", 0} #define meshtastic_EthernetConnectionStatus_init_zero {false, meshtastic_NetworkConnectionStatus_init_zero} #define meshtastic_NetworkConnectionStatus_init_zero {0, 0, 0, 0} #define meshtastic_BluetoothConnectionStatus_init_zero {0, 0, 0} @@ -97,10 +97,10 @@ extern "C" { #define meshtastic_NetworkConnectionStatus_is_connected_tag 2 #define meshtastic_NetworkConnectionStatus_is_mqtt_connected_tag 3 #define meshtastic_NetworkConnectionStatus_is_syslog_connected_tag 4 -#define meshtastic_EthernetConnectionStatus_status_tag 1 #define meshtastic_WifiConnectionStatus_status_tag 1 #define meshtastic_WifiConnectionStatus_ssid_tag 2 #define meshtastic_WifiConnectionStatus_rssi_tag 3 +#define meshtastic_EthernetConnectionStatus_status_tag 1 #define meshtastic_BluetoothConnectionStatus_pin_tag 1 #define meshtastic_BluetoothConnectionStatus_rssi_tag 2 #define meshtastic_BluetoothConnectionStatus_is_connected_tag 3 @@ -130,7 +130,7 @@ X(a, STATIC, SINGULAR, STRING, ssid, 2) \ X(a, STATIC, SINGULAR, INT32, rssi, 3) #define meshtastic_WifiConnectionStatus_CALLBACK NULL #define meshtastic_WifiConnectionStatus_DEFAULT NULL -#define meshtastic_WifiConnectionStatus_status_MSGTYPE meshtastic_EthernetConnectionStatus +#define meshtastic_WifiConnectionStatus_status_MSGTYPE meshtastic_NetworkConnectionStatus #define meshtastic_EthernetConnectionStatus_FIELDLIST(X, a) \ X(a, STATIC, OPTIONAL, MESSAGE, status, 1) @@ -176,11 +176,11 @@ extern const pb_msgdesc_t meshtastic_SerialConnectionStatus_msg; /* Maximum encoded size of messages (where known) */ #define meshtastic_BluetoothConnectionStatus_size 19 -#define meshtastic_DeviceConnectionStatus_size 108 +#define meshtastic_DeviceConnectionStatus_size 106 #define meshtastic_EthernetConnectionStatus_size 13 #define meshtastic_NetworkConnectionStatus_size 11 #define meshtastic_SerialConnectionStatus_size 8 -#define meshtastic_WifiConnectionStatus_size 60 +#define meshtastic_WifiConnectionStatus_size 58 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index f52aa4e0f..fecf3362c 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -33,7 +33,8 @@ static const char *secretReserved = "sekrit"; /// If buf is the reserved secret word, replace the buffer with currentVal static void writeSecret(char *buf, size_t bufsz, const char *currentVal) { - if (strcmp(buf, secretReserved) == 0) { + if (strcmp(buf, secretReserved) == 0) + { strncpy(buf, currentVal, bufsz); } } @@ -51,7 +52,8 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta bool handled = false; assert(r); - switch (r->which_payload_variant) { + switch (r->which_payload_variant) + { /** * Getters @@ -71,7 +73,8 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta handleGetModuleConfig(mp, r->get_module_config_request); break; - case meshtastic_AdminMessage_get_channel_request_tag: { + case meshtastic_AdminMessage_get_channel_request_tag: + { uint32_t i = r->get_channel_request - 1; LOG_INFO("Client is getting channel %u\n", i); if (i >= MAX_NUM_CHANNELS) @@ -110,17 +113,22 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta /** * Other */ - case meshtastic_AdminMessage_reboot_seconds_tag: { + case meshtastic_AdminMessage_reboot_seconds_tag: + { reboot(r->reboot_seconds); break; } - case meshtastic_AdminMessage_reboot_ota_seconds_tag: { + case meshtastic_AdminMessage_reboot_ota_seconds_tag: + { int32_t s = r->reboot_ota_seconds; #ifdef ARCH_ESP32 - if (BleOta::getOtaAppVersion().isEmpty()) { + if (BleOta::getOtaAppVersion().isEmpty()) + { LOG_INFO("No OTA firmware available, scheduling regular reboot in %d seconds\n", s); screen->startRebootScreen(); - } else { + } + else + { screen->startFirmwareUpdateScreen(); BleOta::switchToOtaApp(); LOG_INFO("Rebooting to OTA in %d seconds\n", s); @@ -132,41 +140,48 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta rebootAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } - case meshtastic_AdminMessage_shutdown_seconds_tag: { + case meshtastic_AdminMessage_shutdown_seconds_tag: + { int32_t s = r->shutdown_seconds; LOG_INFO("Shutdown in %d seconds\n", s); shutdownAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } - case meshtastic_AdminMessage_get_device_metadata_request_tag: { + case meshtastic_AdminMessage_get_device_metadata_request_tag: + { LOG_INFO("Client is getting device metadata\n"); handleGetDeviceMetadata(mp); break; } - case meshtastic_AdminMessage_factory_reset_tag: { + case meshtastic_AdminMessage_factory_reset_tag: + { LOG_INFO("Initiating factory reset\n"); nodeDB.factoryReset(); reboot(DEFAULT_REBOOT_SECONDS); break; } - case meshtastic_AdminMessage_nodedb_reset_tag: { + case meshtastic_AdminMessage_nodedb_reset_tag: + { LOG_INFO("Initiating node-db reset\n"); nodeDB.resetNodes(); reboot(DEFAULT_REBOOT_SECONDS); break; } - case meshtastic_AdminMessage_begin_edit_settings_tag: { + case meshtastic_AdminMessage_begin_edit_settings_tag: + { LOG_INFO("Beginning transaction for editing settings\n"); hasOpenEditTransaction = true; break; } - case meshtastic_AdminMessage_commit_edit_settings_tag: { + case meshtastic_AdminMessage_commit_edit_settings_tag: + { LOG_INFO("Committing transaction for edited settings\n"); hasOpenEditTransaction = false; saveChanges(SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS); break; } - case meshtastic_AdminMessage_get_device_connection_status_request_tag: { + case meshtastic_AdminMessage_get_device_connection_status_request_tag: + { LOG_INFO("Client is getting device connection status\n"); handleGetDeviceConnectionStatus(mp); break; @@ -182,11 +197,16 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; AdminMessageHandleResult handleResult = MeshModule::handleAdminMessageForAllPlugins(mp, r, &res); - if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) { + if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) + { myReply = allocDataProtobuf(res); - } else if (mp.decoded.want_response) { + } + else if (mp.decoded.want_response) + { LOG_DEBUG("We did not responded to a request that wanted a respond. req.variant=%d\n", r->which_payload_variant); - } else if (handleResult != AdminMessageHandleResult::HANDLED) { + } + else if (handleResult != AdminMessageHandleResult::HANDLED) + { // Probably a message sent by us or sent to our local node. FIXME, we should avoid scanning these messages LOG_INFO("Ignoring nonrelevant admin %d\n", r->which_payload_variant); } @@ -194,7 +214,8 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta } // If asked for a response and it is not yet set, generate an 'ACK' response - if (mp.decoded.want_response && !myReply) { + if (mp.decoded.want_response && !myReply) + { myReply = allocErrorResponse(meshtastic_Routing_Error_NONE, &mp); } @@ -210,26 +231,31 @@ void AdminModule::handleSetOwner(const meshtastic_User &o) int changed = 0; bool licensed_changed = false; - if (*o.long_name) { + if (*o.long_name) + { changed |= strcmp(owner.long_name, o.long_name); strncpy(owner.long_name, o.long_name, sizeof(owner.long_name)); } - if (*o.short_name) { + if (*o.short_name) + { changed |= strcmp(owner.short_name, o.short_name); strncpy(owner.short_name, o.short_name, sizeof(owner.short_name)); } - if (*o.id) { + if (*o.id) + { changed |= strcmp(owner.id, o.id); strncpy(owner.id, o.id, sizeof(owner.id)); } - if (owner.is_licensed != o.is_licensed) { + if (owner.is_licensed != o.is_licensed) + { changed = 1; licensed_changed = true; owner.is_licensed = o.is_licensed; config.lora.override_duty_cycle = owner.is_licensed; // override duty cycle for licensed operators } - if (changed) { // If nothing really changed, don't broadcast on the network or write to flash + if (changed) + { // If nothing really changed, don't broadcast on the network or write to flash service.reloadOwner(!hasOpenEditTransaction); licensed_changed ? saveChanges(SEGMENT_CONFIG | SEGMENT_DEVICESTATE) : saveChanges(SEGMENT_DEVICESTATE); } @@ -240,7 +266,8 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) auto existingRole = config.device.role; bool isRegionUnset = (config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_UNSET); - switch (c.which_payload_variant) { + switch (c.which_payload_variant) + { case meshtastic_Config_device_tag: LOG_INFO("Setting config: Device\n"); config.has_device = true; @@ -275,7 +302,8 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) LOG_INFO("Setting config: LoRa\n"); config.has_lora = true; config.lora = c.payload_variant.lora; - if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) { + if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) + { config.lora.tx_enabled = true; } break; @@ -291,7 +319,8 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) void AdminModule::handleSetModuleConfig(const meshtastic_ModuleConfig &c) { - switch (c.which_payload_variant) { + switch (c.which_payload_variant) + { case meshtastic_ModuleConfig_mqtt_tag: LOG_INFO("Setting module config: MQTT\n"); moduleConfig.has_mqtt = true; @@ -355,7 +384,8 @@ void AdminModule::handleSetChannel(const meshtastic_Channel &cc) void AdminModule::handleGetOwner(const meshtastic_MeshPacket &req) { - if (req.decoded.want_response) { + if (req.decoded.want_response) + { // We create the reply here meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; res.get_owner_response = owner; @@ -369,8 +399,10 @@ void AdminModule::handleGetConfig(const meshtastic_MeshPacket &req, const uint32 { meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; - if (req.decoded.want_response) { - switch (configType) { + if (req.decoded.want_response) + { + switch (configType) + { case meshtastic_AdminMessage_ConfigType_DEVICE_CONFIG: LOG_INFO("Getting config: Device\n"); res.get_config_response.which_payload_variant = meshtastic_Config_device_tag; @@ -425,8 +457,10 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const { meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; - if (req.decoded.want_response) { - switch (configType) { + if (req.decoded.want_response) + { + switch (configType) + { case meshtastic_AdminMessage_ModuleConfigType_MQTT_CONFIG: LOG_INFO("Getting module config: MQTT\n"); res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_mqtt_tag; @@ -514,29 +548,36 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r #if HAS_WIFI conn.has_wifi = true; - conn.wifi.status.status.is_connected = WiFi.status() != WL_CONNECTED; + conn.wifi.has_status = true; + conn.wifi.status.is_connected = WiFi.status() != WL_CONNECTED; strncpy(conn.wifi.ssid, config.network.wifi_ssid, 33); - if (conn.wifi.status.status.is_connected) { + if (conn.wifi.status.is_connected) + { conn.wifi.rssi = WiFi.RSSI(); - conn.wifi.status.status.ip_address = WiFi.localIP(); - conn.wifi.status.status.is_mqtt_connected = mqtt && mqtt->connected(); - conn.wifi.status.status.is_syslog_connected = false; // FIXME wire this up + conn.wifi.status.ip_address = WiFi.localIP(); + conn.wifi.status.is_mqtt_connected = mqtt && mqtt->connected(); + conn.wifi.status.is_syslog_connected = false; // FIXME wire this up } #endif #if HAS_ETHERNET conn.has_ethernet = true; - if (Ethernet.linkStatus() == LinkON) { + conn.ethernet.has_status = true; + if (Ethernet.linkStatus() == LinkON) + { conn.ethernet.status.is_connected = true; conn.ethernet.status.ip_address = Ethernet.localIP(); conn.ethernet.status.is_mqtt_connected = mqtt && mqtt->connected(); conn.ethernet.status.is_syslog_connected = false; // FIXME wire this up } - conn.ethernet.status.is_connected = false; + else + { + conn.ethernet.status.is_connected = false; + } #endif #if HAS_BLUETOOTH - conn.has_bluetooth = HAS_BLUETOOTH; + conn.has_bluetooth = true; conn.bluetooth.pin = config.bluetooth.fixed_pin; #endif #ifdef ARCH_ESP32 @@ -556,7 +597,8 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r void AdminModule::handleGetChannel(const meshtastic_MeshPacket &req, uint32_t channelIndex) { - if (req.decoded.want_response) { + if (req.decoded.want_response) + { // We create the reply here meshtastic_AdminMessage r = meshtastic_AdminMessage_init_default; r.get_channel_response = channels.getByIndex(channelIndex); @@ -574,13 +616,17 @@ void AdminModule::reboot(int32_t seconds) void AdminModule::saveChanges(int saveWhat, bool shouldReboot) { - if (!hasOpenEditTransaction) { + if (!hasOpenEditTransaction) + { LOG_INFO("Saving changes to disk\n"); service.reloadConfig(saveWhat); // Calls saveToDisk among other things - } else { + } + else + { LOG_INFO("Delaying save of changes to disk until the open transaction is committed\n"); } - if (shouldReboot) { + if (shouldReboot) + { reboot(DEFAULT_REBOOT_SECONDS); } } From 2b15d951cf35c606cf9b64e23841c5bf14a05207 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 10:50:03 -0600 Subject: [PATCH 23/54] Trunk --- src/modules/AdminModule.cpp | 119 ++++++++++++------------------------ 1 file changed, 38 insertions(+), 81 deletions(-) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index fecf3362c..79798b94b 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -33,8 +33,7 @@ static const char *secretReserved = "sekrit"; /// If buf is the reserved secret word, replace the buffer with currentVal static void writeSecret(char *buf, size_t bufsz, const char *currentVal) { - if (strcmp(buf, secretReserved) == 0) - { + if (strcmp(buf, secretReserved) == 0) { strncpy(buf, currentVal, bufsz); } } @@ -52,8 +51,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta bool handled = false; assert(r); - switch (r->which_payload_variant) - { + switch (r->which_payload_variant) { /** * Getters @@ -73,8 +71,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta handleGetModuleConfig(mp, r->get_module_config_request); break; - case meshtastic_AdminMessage_get_channel_request_tag: - { + case meshtastic_AdminMessage_get_channel_request_tag: { uint32_t i = r->get_channel_request - 1; LOG_INFO("Client is getting channel %u\n", i); if (i >= MAX_NUM_CHANNELS) @@ -113,22 +110,17 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta /** * Other */ - case meshtastic_AdminMessage_reboot_seconds_tag: - { + case meshtastic_AdminMessage_reboot_seconds_tag: { reboot(r->reboot_seconds); break; } - case meshtastic_AdminMessage_reboot_ota_seconds_tag: - { + case meshtastic_AdminMessage_reboot_ota_seconds_tag: { int32_t s = r->reboot_ota_seconds; #ifdef ARCH_ESP32 - if (BleOta::getOtaAppVersion().isEmpty()) - { + if (BleOta::getOtaAppVersion().isEmpty()) { LOG_INFO("No OTA firmware available, scheduling regular reboot in %d seconds\n", s); screen->startRebootScreen(); - } - else - { + } else { screen->startFirmwareUpdateScreen(); BleOta::switchToOtaApp(); LOG_INFO("Rebooting to OTA in %d seconds\n", s); @@ -140,48 +132,41 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta rebootAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } - case meshtastic_AdminMessage_shutdown_seconds_tag: - { + case meshtastic_AdminMessage_shutdown_seconds_tag: { int32_t s = r->shutdown_seconds; LOG_INFO("Shutdown in %d seconds\n", s); shutdownAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } - case meshtastic_AdminMessage_get_device_metadata_request_tag: - { + case meshtastic_AdminMessage_get_device_metadata_request_tag: { LOG_INFO("Client is getting device metadata\n"); handleGetDeviceMetadata(mp); break; } - case meshtastic_AdminMessage_factory_reset_tag: - { + case meshtastic_AdminMessage_factory_reset_tag: { LOG_INFO("Initiating factory reset\n"); nodeDB.factoryReset(); reboot(DEFAULT_REBOOT_SECONDS); break; } - case meshtastic_AdminMessage_nodedb_reset_tag: - { + case meshtastic_AdminMessage_nodedb_reset_tag: { LOG_INFO("Initiating node-db reset\n"); nodeDB.resetNodes(); reboot(DEFAULT_REBOOT_SECONDS); break; } - case meshtastic_AdminMessage_begin_edit_settings_tag: - { + case meshtastic_AdminMessage_begin_edit_settings_tag: { LOG_INFO("Beginning transaction for editing settings\n"); hasOpenEditTransaction = true; break; } - case meshtastic_AdminMessage_commit_edit_settings_tag: - { + case meshtastic_AdminMessage_commit_edit_settings_tag: { LOG_INFO("Committing transaction for edited settings\n"); hasOpenEditTransaction = false; saveChanges(SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS); break; } - case meshtastic_AdminMessage_get_device_connection_status_request_tag: - { + case meshtastic_AdminMessage_get_device_connection_status_request_tag: { LOG_INFO("Client is getting device connection status\n"); handleGetDeviceConnectionStatus(mp); break; @@ -197,16 +182,11 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; AdminMessageHandleResult handleResult = MeshModule::handleAdminMessageForAllPlugins(mp, r, &res); - if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) - { + if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) { myReply = allocDataProtobuf(res); - } - else if (mp.decoded.want_response) - { + } else if (mp.decoded.want_response) { LOG_DEBUG("We did not responded to a request that wanted a respond. req.variant=%d\n", r->which_payload_variant); - } - else if (handleResult != AdminMessageHandleResult::HANDLED) - { + } else if (handleResult != AdminMessageHandleResult::HANDLED) { // Probably a message sent by us or sent to our local node. FIXME, we should avoid scanning these messages LOG_INFO("Ignoring nonrelevant admin %d\n", r->which_payload_variant); } @@ -214,8 +194,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta } // If asked for a response and it is not yet set, generate an 'ACK' response - if (mp.decoded.want_response && !myReply) - { + if (mp.decoded.want_response && !myReply) { myReply = allocErrorResponse(meshtastic_Routing_Error_NONE, &mp); } @@ -231,31 +210,26 @@ void AdminModule::handleSetOwner(const meshtastic_User &o) int changed = 0; bool licensed_changed = false; - if (*o.long_name) - { + if (*o.long_name) { changed |= strcmp(owner.long_name, o.long_name); strncpy(owner.long_name, o.long_name, sizeof(owner.long_name)); } - if (*o.short_name) - { + if (*o.short_name) { changed |= strcmp(owner.short_name, o.short_name); strncpy(owner.short_name, o.short_name, sizeof(owner.short_name)); } - if (*o.id) - { + if (*o.id) { changed |= strcmp(owner.id, o.id); strncpy(owner.id, o.id, sizeof(owner.id)); } - if (owner.is_licensed != o.is_licensed) - { + if (owner.is_licensed != o.is_licensed) { changed = 1; licensed_changed = true; owner.is_licensed = o.is_licensed; config.lora.override_duty_cycle = owner.is_licensed; // override duty cycle for licensed operators } - if (changed) - { // If nothing really changed, don't broadcast on the network or write to flash + if (changed) { // If nothing really changed, don't broadcast on the network or write to flash service.reloadOwner(!hasOpenEditTransaction); licensed_changed ? saveChanges(SEGMENT_CONFIG | SEGMENT_DEVICESTATE) : saveChanges(SEGMENT_DEVICESTATE); } @@ -266,8 +240,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) auto existingRole = config.device.role; bool isRegionUnset = (config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_UNSET); - switch (c.which_payload_variant) - { + switch (c.which_payload_variant) { case meshtastic_Config_device_tag: LOG_INFO("Setting config: Device\n"); config.has_device = true; @@ -302,8 +275,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) LOG_INFO("Setting config: LoRa\n"); config.has_lora = true; config.lora = c.payload_variant.lora; - if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) - { + if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) { config.lora.tx_enabled = true; } break; @@ -319,8 +291,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) void AdminModule::handleSetModuleConfig(const meshtastic_ModuleConfig &c) { - switch (c.which_payload_variant) - { + switch (c.which_payload_variant) { case meshtastic_ModuleConfig_mqtt_tag: LOG_INFO("Setting module config: MQTT\n"); moduleConfig.has_mqtt = true; @@ -384,8 +355,7 @@ void AdminModule::handleSetChannel(const meshtastic_Channel &cc) void AdminModule::handleGetOwner(const meshtastic_MeshPacket &req) { - if (req.decoded.want_response) - { + if (req.decoded.want_response) { // We create the reply here meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; res.get_owner_response = owner; @@ -399,10 +369,8 @@ void AdminModule::handleGetConfig(const meshtastic_MeshPacket &req, const uint32 { meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; - if (req.decoded.want_response) - { - switch (configType) - { + if (req.decoded.want_response) { + switch (configType) { case meshtastic_AdminMessage_ConfigType_DEVICE_CONFIG: LOG_INFO("Getting config: Device\n"); res.get_config_response.which_payload_variant = meshtastic_Config_device_tag; @@ -457,10 +425,8 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const { meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; - if (req.decoded.want_response) - { - switch (configType) - { + if (req.decoded.want_response) { + switch (configType) { case meshtastic_AdminMessage_ModuleConfigType_MQTT_CONFIG: LOG_INFO("Getting module config: MQTT\n"); res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_mqtt_tag; @@ -551,8 +517,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r conn.wifi.has_status = true; conn.wifi.status.is_connected = WiFi.status() != WL_CONNECTED; strncpy(conn.wifi.ssid, config.network.wifi_ssid, 33); - if (conn.wifi.status.is_connected) - { + if (conn.wifi.status.is_connected) { conn.wifi.rssi = WiFi.RSSI(); conn.wifi.status.ip_address = WiFi.localIP(); conn.wifi.status.is_mqtt_connected = mqtt && mqtt->connected(); @@ -563,15 +528,12 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r #if HAS_ETHERNET conn.has_ethernet = true; conn.ethernet.has_status = true; - if (Ethernet.linkStatus() == LinkON) - { + if (Ethernet.linkStatus() == LinkON) { conn.ethernet.status.is_connected = true; conn.ethernet.status.ip_address = Ethernet.localIP(); conn.ethernet.status.is_mqtt_connected = mqtt && mqtt->connected(); conn.ethernet.status.is_syslog_connected = false; // FIXME wire this up - } - else - { + } else { conn.ethernet.status.is_connected = false; } #endif @@ -597,8 +559,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r void AdminModule::handleGetChannel(const meshtastic_MeshPacket &req, uint32_t channelIndex) { - if (req.decoded.want_response) - { + if (req.decoded.want_response) { // We create the reply here meshtastic_AdminMessage r = meshtastic_AdminMessage_init_default; r.get_channel_response = channels.getByIndex(channelIndex); @@ -616,17 +577,13 @@ void AdminModule::reboot(int32_t seconds) void AdminModule::saveChanges(int saveWhat, bool shouldReboot) { - if (!hasOpenEditTransaction) - { + if (!hasOpenEditTransaction) { LOG_INFO("Saving changes to disk\n"); service.reloadConfig(saveWhat); // Calls saveToDisk among other things - } - else - { + } else { LOG_INFO("Delaying save of changes to disk until the open transaction is committed\n"); } - if (shouldReboot) - { + if (shouldReboot) { reboot(DEFAULT_REBOOT_SECONDS); } } From d6de0427830420ecce9fd3f2179e4f0d5a5f2364 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 11:00:05 -0600 Subject: [PATCH 24/54] Assume portduino is always connected --- src/modules/AdminModule.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 79798b94b..d48ed83d6 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -515,7 +515,11 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r #if HAS_WIFI conn.has_wifi = true; conn.wifi.has_status = true; +#ifdef ARCH_PORTDUINO + conn.wifi.status.is_connected = true; +#elif conn.wifi.status.is_connected = WiFi.status() != WL_CONNECTED; +#endif strncpy(conn.wifi.ssid, config.network.wifi_ssid, 33); if (conn.wifi.status.is_connected) { conn.wifi.rssi = WiFi.RSSI(); From ac90c27ae87956080a30a4a33a3dac124cd3425a Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 11:03:12 -0600 Subject: [PATCH 25/54] Macros --- src/modules/AdminModule.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index d48ed83d6..536cb82af 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -527,6 +527,8 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r conn.wifi.status.is_mqtt_connected = mqtt && mqtt->connected(); conn.wifi.status.is_syslog_connected = false; // FIXME wire this up } +#else + conn.has_wifi = false; #endif #if HAS_ETHERNET @@ -540,6 +542,8 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r } else { conn.ethernet.status.is_connected = false; } +#else + conn.has_ethernet = false; #endif #if HAS_BLUETOOTH From ab77772e0ca0f64e18551e2f17b26eff2f0d2868 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 11:11:09 -0600 Subject: [PATCH 26/54] Bugger --- src/modules/AdminModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 536cb82af..3b1fdd26c 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -517,7 +517,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r conn.wifi.has_status = true; #ifdef ARCH_PORTDUINO conn.wifi.status.is_connected = true; -#elif +#else conn.wifi.status.is_connected = WiFi.status() != WL_CONNECTED; #endif strncpy(conn.wifi.ssid, config.network.wifi_ssid, 33); From 9a950afd2acd6a4a95f2cabd01b50debd07a034e Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 11:30:36 -0600 Subject: [PATCH 27/54] Trunk fmt --- src/modules/AdminModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 3b1fdd26c..9e50ad938 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -560,7 +560,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r conn.serial.is_connected = powerFSM.getState() == &stateSERIAL; conn.serial.baud = SERIAL_BAUD; - r.get_device_connection_status_response = conn; + r.get_device_connection_status_response = conn; // cppcheck-suppress uninitStructMember r.which_payload_variant = meshtastic_AdminMessage_get_device_connection_status_response_tag; myReply = allocDataProtobuf(r); } From c82d1de9cead83f2225b0ecc81f8d2c4251010c4 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 12:43:16 -0600 Subject: [PATCH 28/54] Check --- src/modules/AdminModule.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 9e50ad938..580076845 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -560,7 +560,8 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r conn.serial.is_connected = powerFSM.getState() == &stateSERIAL; conn.serial.baud = SERIAL_BAUD; - r.get_device_connection_status_response = conn; // cppcheck-suppress uninitStructMember + // cppcheck-suppress uninitStructMember + r.get_device_connection_status_response = conn; r.which_payload_variant = meshtastic_AdminMessage_get_device_connection_status_response_tag; myReply = allocDataProtobuf(r); } From 9d420f403a3d50fe10178b04d62692f498006bc3 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 13:05:25 -0600 Subject: [PATCH 29/54] Try this --- src/modules/AdminModule.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 580076845..42ae03a74 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -560,8 +560,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r conn.serial.is_connected = powerFSM.getState() == &stateSERIAL; conn.serial.baud = SERIAL_BAUD; - // cppcheck-suppress uninitStructMember - r.get_device_connection_status_response = conn; + r.get_device_connection_status_response = conn; // cppcheck-suppress [uninitStructMember,uninitvar] r.which_payload_variant = meshtastic_AdminMessage_get_device_connection_status_response_tag; myReply = allocDataProtobuf(r); } From 81d2486cf49ab3d153114fdb48baa057a044361d Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 13:17:39 -0600 Subject: [PATCH 30/54] Init defaults --- src/modules/AdminModule.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 42ae03a74..6854c5116 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -512,6 +512,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r meshtastic_DeviceConnectionStatus conn; + conn.wifi = meshtastic_WifiConnectionStatus_init_default; #if HAS_WIFI conn.has_wifi = true; conn.wifi.has_status = true; @@ -531,6 +532,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r conn.has_wifi = false; #endif + conn.ethernet = meshtastic_EthernetConnectionStatus_init_default; #if HAS_ETHERNET conn.has_ethernet = true; conn.ethernet.has_status = true; @@ -560,7 +562,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r conn.serial.is_connected = powerFSM.getState() == &stateSERIAL; conn.serial.baud = SERIAL_BAUD; - r.get_device_connection_status_response = conn; // cppcheck-suppress [uninitStructMember,uninitvar] + r.get_device_connection_status_response = conn; r.which_payload_variant = meshtastic_AdminMessage_get_device_connection_status_response_tag; myReply = allocDataProtobuf(r); } From 3a3451129aa9a8ed7e29d6e3d0b58c7e1b628115 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 13:59:54 -0600 Subject: [PATCH 31/54] Init gooder? --- src/modules/AdminModule.cpp | 123 ++++++++++++++++++++++++------------ 1 file changed, 83 insertions(+), 40 deletions(-) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 6854c5116..538e21c76 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -33,7 +33,8 @@ static const char *secretReserved = "sekrit"; /// If buf is the reserved secret word, replace the buffer with currentVal static void writeSecret(char *buf, size_t bufsz, const char *currentVal) { - if (strcmp(buf, secretReserved) == 0) { + if (strcmp(buf, secretReserved) == 0) + { strncpy(buf, currentVal, bufsz); } } @@ -51,7 +52,8 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta bool handled = false; assert(r); - switch (r->which_payload_variant) { + switch (r->which_payload_variant) + { /** * Getters @@ -71,7 +73,8 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta handleGetModuleConfig(mp, r->get_module_config_request); break; - case meshtastic_AdminMessage_get_channel_request_tag: { + case meshtastic_AdminMessage_get_channel_request_tag: + { uint32_t i = r->get_channel_request - 1; LOG_INFO("Client is getting channel %u\n", i); if (i >= MAX_NUM_CHANNELS) @@ -110,17 +113,22 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta /** * Other */ - case meshtastic_AdminMessage_reboot_seconds_tag: { + case meshtastic_AdminMessage_reboot_seconds_tag: + { reboot(r->reboot_seconds); break; } - case meshtastic_AdminMessage_reboot_ota_seconds_tag: { + case meshtastic_AdminMessage_reboot_ota_seconds_tag: + { int32_t s = r->reboot_ota_seconds; #ifdef ARCH_ESP32 - if (BleOta::getOtaAppVersion().isEmpty()) { + if (BleOta::getOtaAppVersion().isEmpty()) + { LOG_INFO("No OTA firmware available, scheduling regular reboot in %d seconds\n", s); screen->startRebootScreen(); - } else { + } + else + { screen->startFirmwareUpdateScreen(); BleOta::switchToOtaApp(); LOG_INFO("Rebooting to OTA in %d seconds\n", s); @@ -132,41 +140,48 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta rebootAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } - case meshtastic_AdminMessage_shutdown_seconds_tag: { + case meshtastic_AdminMessage_shutdown_seconds_tag: + { int32_t s = r->shutdown_seconds; LOG_INFO("Shutdown in %d seconds\n", s); shutdownAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } - case meshtastic_AdminMessage_get_device_metadata_request_tag: { + case meshtastic_AdminMessage_get_device_metadata_request_tag: + { LOG_INFO("Client is getting device metadata\n"); handleGetDeviceMetadata(mp); break; } - case meshtastic_AdminMessage_factory_reset_tag: { + case meshtastic_AdminMessage_factory_reset_tag: + { LOG_INFO("Initiating factory reset\n"); nodeDB.factoryReset(); reboot(DEFAULT_REBOOT_SECONDS); break; } - case meshtastic_AdminMessage_nodedb_reset_tag: { + case meshtastic_AdminMessage_nodedb_reset_tag: + { LOG_INFO("Initiating node-db reset\n"); nodeDB.resetNodes(); reboot(DEFAULT_REBOOT_SECONDS); break; } - case meshtastic_AdminMessage_begin_edit_settings_tag: { + case meshtastic_AdminMessage_begin_edit_settings_tag: + { LOG_INFO("Beginning transaction for editing settings\n"); hasOpenEditTransaction = true; break; } - case meshtastic_AdminMessage_commit_edit_settings_tag: { + case meshtastic_AdminMessage_commit_edit_settings_tag: + { LOG_INFO("Committing transaction for edited settings\n"); hasOpenEditTransaction = false; saveChanges(SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS); break; } - case meshtastic_AdminMessage_get_device_connection_status_request_tag: { + case meshtastic_AdminMessage_get_device_connection_status_request_tag: + { LOG_INFO("Client is getting device connection status\n"); handleGetDeviceConnectionStatus(mp); break; @@ -182,11 +197,16 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; AdminMessageHandleResult handleResult = MeshModule::handleAdminMessageForAllPlugins(mp, r, &res); - if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) { + if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) + { myReply = allocDataProtobuf(res); - } else if (mp.decoded.want_response) { + } + else if (mp.decoded.want_response) + { LOG_DEBUG("We did not responded to a request that wanted a respond. req.variant=%d\n", r->which_payload_variant); - } else if (handleResult != AdminMessageHandleResult::HANDLED) { + } + else if (handleResult != AdminMessageHandleResult::HANDLED) + { // Probably a message sent by us or sent to our local node. FIXME, we should avoid scanning these messages LOG_INFO("Ignoring nonrelevant admin %d\n", r->which_payload_variant); } @@ -194,7 +214,8 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta } // If asked for a response and it is not yet set, generate an 'ACK' response - if (mp.decoded.want_response && !myReply) { + if (mp.decoded.want_response && !myReply) + { myReply = allocErrorResponse(meshtastic_Routing_Error_NONE, &mp); } @@ -210,26 +231,31 @@ void AdminModule::handleSetOwner(const meshtastic_User &o) int changed = 0; bool licensed_changed = false; - if (*o.long_name) { + if (*o.long_name) + { changed |= strcmp(owner.long_name, o.long_name); strncpy(owner.long_name, o.long_name, sizeof(owner.long_name)); } - if (*o.short_name) { + if (*o.short_name) + { changed |= strcmp(owner.short_name, o.short_name); strncpy(owner.short_name, o.short_name, sizeof(owner.short_name)); } - if (*o.id) { + if (*o.id) + { changed |= strcmp(owner.id, o.id); strncpy(owner.id, o.id, sizeof(owner.id)); } - if (owner.is_licensed != o.is_licensed) { + if (owner.is_licensed != o.is_licensed) + { changed = 1; licensed_changed = true; owner.is_licensed = o.is_licensed; config.lora.override_duty_cycle = owner.is_licensed; // override duty cycle for licensed operators } - if (changed) { // If nothing really changed, don't broadcast on the network or write to flash + if (changed) + { // If nothing really changed, don't broadcast on the network or write to flash service.reloadOwner(!hasOpenEditTransaction); licensed_changed ? saveChanges(SEGMENT_CONFIG | SEGMENT_DEVICESTATE) : saveChanges(SEGMENT_DEVICESTATE); } @@ -240,7 +266,8 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) auto existingRole = config.device.role; bool isRegionUnset = (config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_UNSET); - switch (c.which_payload_variant) { + switch (c.which_payload_variant) + { case meshtastic_Config_device_tag: LOG_INFO("Setting config: Device\n"); config.has_device = true; @@ -275,7 +302,8 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) LOG_INFO("Setting config: LoRa\n"); config.has_lora = true; config.lora = c.payload_variant.lora; - if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) { + if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) + { config.lora.tx_enabled = true; } break; @@ -291,7 +319,8 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) void AdminModule::handleSetModuleConfig(const meshtastic_ModuleConfig &c) { - switch (c.which_payload_variant) { + switch (c.which_payload_variant) + { case meshtastic_ModuleConfig_mqtt_tag: LOG_INFO("Setting module config: MQTT\n"); moduleConfig.has_mqtt = true; @@ -355,7 +384,8 @@ void AdminModule::handleSetChannel(const meshtastic_Channel &cc) void AdminModule::handleGetOwner(const meshtastic_MeshPacket &req) { - if (req.decoded.want_response) { + if (req.decoded.want_response) + { // We create the reply here meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; res.get_owner_response = owner; @@ -369,8 +399,10 @@ void AdminModule::handleGetConfig(const meshtastic_MeshPacket &req, const uint32 { meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; - if (req.decoded.want_response) { - switch (configType) { + if (req.decoded.want_response) + { + switch (configType) + { case meshtastic_AdminMessage_ConfigType_DEVICE_CONFIG: LOG_INFO("Getting config: Device\n"); res.get_config_response.which_payload_variant = meshtastic_Config_device_tag; @@ -425,8 +457,10 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const { meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; - if (req.decoded.want_response) { - switch (configType) { + if (req.decoded.want_response) + { + switch (configType) + { case meshtastic_AdminMessage_ModuleConfigType_MQTT_CONFIG: LOG_INFO("Getting module config: MQTT\n"); res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_mqtt_tag; @@ -512,7 +546,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r meshtastic_DeviceConnectionStatus conn; - conn.wifi = meshtastic_WifiConnectionStatus_init_default; + conn.wifi = {0}; #if HAS_WIFI conn.has_wifi = true; conn.wifi.has_status = true; @@ -522,7 +556,8 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r conn.wifi.status.is_connected = WiFi.status() != WL_CONNECTED; #endif strncpy(conn.wifi.ssid, config.network.wifi_ssid, 33); - if (conn.wifi.status.is_connected) { + if (conn.wifi.status.is_connected) + { conn.wifi.rssi = WiFi.RSSI(); conn.wifi.status.ip_address = WiFi.localIP(); conn.wifi.status.is_mqtt_connected = mqtt && mqtt->connected(); @@ -532,16 +567,19 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r conn.has_wifi = false; #endif - conn.ethernet = meshtastic_EthernetConnectionStatus_init_default; + conn.ethernet = {0}; #if HAS_ETHERNET conn.has_ethernet = true; conn.ethernet.has_status = true; - if (Ethernet.linkStatus() == LinkON) { + if (Ethernet.linkStatus() == LinkON) + { conn.ethernet.status.is_connected = true; conn.ethernet.status.ip_address = Ethernet.localIP(); conn.ethernet.status.is_mqtt_connected = mqtt && mqtt->connected(); conn.ethernet.status.is_syslog_connected = false; // FIXME wire this up - } else { + } + else + { conn.ethernet.status.is_connected = false; } #else @@ -569,7 +607,8 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r void AdminModule::handleGetChannel(const meshtastic_MeshPacket &req, uint32_t channelIndex) { - if (req.decoded.want_response) { + if (req.decoded.want_response) + { // We create the reply here meshtastic_AdminMessage r = meshtastic_AdminMessage_init_default; r.get_channel_response = channels.getByIndex(channelIndex); @@ -587,13 +626,17 @@ void AdminModule::reboot(int32_t seconds) void AdminModule::saveChanges(int saveWhat, bool shouldReboot) { - if (!hasOpenEditTransaction) { + if (!hasOpenEditTransaction) + { LOG_INFO("Saving changes to disk\n"); service.reloadConfig(saveWhat); // Calls saveToDisk among other things - } else { + } + else + { LOG_INFO("Delaying save of changes to disk until the open transaction is committed\n"); } - if (shouldReboot) { + if (shouldReboot) + { reboot(DEFAULT_REBOOT_SECONDS); } } From 6a2583e8727aaf5b974446cc817c15f41bbdaa64 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 14:10:19 -0600 Subject: [PATCH 32/54] Trunk you mothertrunker --- src/modules/AdminModule.cpp | 119 ++++++++++++------------------------ 1 file changed, 38 insertions(+), 81 deletions(-) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 538e21c76..8d69289f0 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -33,8 +33,7 @@ static const char *secretReserved = "sekrit"; /// If buf is the reserved secret word, replace the buffer with currentVal static void writeSecret(char *buf, size_t bufsz, const char *currentVal) { - if (strcmp(buf, secretReserved) == 0) - { + if (strcmp(buf, secretReserved) == 0) { strncpy(buf, currentVal, bufsz); } } @@ -52,8 +51,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta bool handled = false; assert(r); - switch (r->which_payload_variant) - { + switch (r->which_payload_variant) { /** * Getters @@ -73,8 +71,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta handleGetModuleConfig(mp, r->get_module_config_request); break; - case meshtastic_AdminMessage_get_channel_request_tag: - { + case meshtastic_AdminMessage_get_channel_request_tag: { uint32_t i = r->get_channel_request - 1; LOG_INFO("Client is getting channel %u\n", i); if (i >= MAX_NUM_CHANNELS) @@ -113,22 +110,17 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta /** * Other */ - case meshtastic_AdminMessage_reboot_seconds_tag: - { + case meshtastic_AdminMessage_reboot_seconds_tag: { reboot(r->reboot_seconds); break; } - case meshtastic_AdminMessage_reboot_ota_seconds_tag: - { + case meshtastic_AdminMessage_reboot_ota_seconds_tag: { int32_t s = r->reboot_ota_seconds; #ifdef ARCH_ESP32 - if (BleOta::getOtaAppVersion().isEmpty()) - { + if (BleOta::getOtaAppVersion().isEmpty()) { LOG_INFO("No OTA firmware available, scheduling regular reboot in %d seconds\n", s); screen->startRebootScreen(); - } - else - { + } else { screen->startFirmwareUpdateScreen(); BleOta::switchToOtaApp(); LOG_INFO("Rebooting to OTA in %d seconds\n", s); @@ -140,48 +132,41 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta rebootAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } - case meshtastic_AdminMessage_shutdown_seconds_tag: - { + case meshtastic_AdminMessage_shutdown_seconds_tag: { int32_t s = r->shutdown_seconds; LOG_INFO("Shutdown in %d seconds\n", s); shutdownAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } - case meshtastic_AdminMessage_get_device_metadata_request_tag: - { + case meshtastic_AdminMessage_get_device_metadata_request_tag: { LOG_INFO("Client is getting device metadata\n"); handleGetDeviceMetadata(mp); break; } - case meshtastic_AdminMessage_factory_reset_tag: - { + case meshtastic_AdminMessage_factory_reset_tag: { LOG_INFO("Initiating factory reset\n"); nodeDB.factoryReset(); reboot(DEFAULT_REBOOT_SECONDS); break; } - case meshtastic_AdminMessage_nodedb_reset_tag: - { + case meshtastic_AdminMessage_nodedb_reset_tag: { LOG_INFO("Initiating node-db reset\n"); nodeDB.resetNodes(); reboot(DEFAULT_REBOOT_SECONDS); break; } - case meshtastic_AdminMessage_begin_edit_settings_tag: - { + case meshtastic_AdminMessage_begin_edit_settings_tag: { LOG_INFO("Beginning transaction for editing settings\n"); hasOpenEditTransaction = true; break; } - case meshtastic_AdminMessage_commit_edit_settings_tag: - { + case meshtastic_AdminMessage_commit_edit_settings_tag: { LOG_INFO("Committing transaction for edited settings\n"); hasOpenEditTransaction = false; saveChanges(SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS); break; } - case meshtastic_AdminMessage_get_device_connection_status_request_tag: - { + case meshtastic_AdminMessage_get_device_connection_status_request_tag: { LOG_INFO("Client is getting device connection status\n"); handleGetDeviceConnectionStatus(mp); break; @@ -197,16 +182,11 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; AdminMessageHandleResult handleResult = MeshModule::handleAdminMessageForAllPlugins(mp, r, &res); - if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) - { + if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) { myReply = allocDataProtobuf(res); - } - else if (mp.decoded.want_response) - { + } else if (mp.decoded.want_response) { LOG_DEBUG("We did not responded to a request that wanted a respond. req.variant=%d\n", r->which_payload_variant); - } - else if (handleResult != AdminMessageHandleResult::HANDLED) - { + } else if (handleResult != AdminMessageHandleResult::HANDLED) { // Probably a message sent by us or sent to our local node. FIXME, we should avoid scanning these messages LOG_INFO("Ignoring nonrelevant admin %d\n", r->which_payload_variant); } @@ -214,8 +194,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta } // If asked for a response and it is not yet set, generate an 'ACK' response - if (mp.decoded.want_response && !myReply) - { + if (mp.decoded.want_response && !myReply) { myReply = allocErrorResponse(meshtastic_Routing_Error_NONE, &mp); } @@ -231,31 +210,26 @@ void AdminModule::handleSetOwner(const meshtastic_User &o) int changed = 0; bool licensed_changed = false; - if (*o.long_name) - { + if (*o.long_name) { changed |= strcmp(owner.long_name, o.long_name); strncpy(owner.long_name, o.long_name, sizeof(owner.long_name)); } - if (*o.short_name) - { + if (*o.short_name) { changed |= strcmp(owner.short_name, o.short_name); strncpy(owner.short_name, o.short_name, sizeof(owner.short_name)); } - if (*o.id) - { + if (*o.id) { changed |= strcmp(owner.id, o.id); strncpy(owner.id, o.id, sizeof(owner.id)); } - if (owner.is_licensed != o.is_licensed) - { + if (owner.is_licensed != o.is_licensed) { changed = 1; licensed_changed = true; owner.is_licensed = o.is_licensed; config.lora.override_duty_cycle = owner.is_licensed; // override duty cycle for licensed operators } - if (changed) - { // If nothing really changed, don't broadcast on the network or write to flash + if (changed) { // If nothing really changed, don't broadcast on the network or write to flash service.reloadOwner(!hasOpenEditTransaction); licensed_changed ? saveChanges(SEGMENT_CONFIG | SEGMENT_DEVICESTATE) : saveChanges(SEGMENT_DEVICESTATE); } @@ -266,8 +240,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) auto existingRole = config.device.role; bool isRegionUnset = (config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_UNSET); - switch (c.which_payload_variant) - { + switch (c.which_payload_variant) { case meshtastic_Config_device_tag: LOG_INFO("Setting config: Device\n"); config.has_device = true; @@ -302,8 +275,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) LOG_INFO("Setting config: LoRa\n"); config.has_lora = true; config.lora = c.payload_variant.lora; - if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) - { + if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) { config.lora.tx_enabled = true; } break; @@ -319,8 +291,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) void AdminModule::handleSetModuleConfig(const meshtastic_ModuleConfig &c) { - switch (c.which_payload_variant) - { + switch (c.which_payload_variant) { case meshtastic_ModuleConfig_mqtt_tag: LOG_INFO("Setting module config: MQTT\n"); moduleConfig.has_mqtt = true; @@ -384,8 +355,7 @@ void AdminModule::handleSetChannel(const meshtastic_Channel &cc) void AdminModule::handleGetOwner(const meshtastic_MeshPacket &req) { - if (req.decoded.want_response) - { + if (req.decoded.want_response) { // We create the reply here meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; res.get_owner_response = owner; @@ -399,10 +369,8 @@ void AdminModule::handleGetConfig(const meshtastic_MeshPacket &req, const uint32 { meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; - if (req.decoded.want_response) - { - switch (configType) - { + if (req.decoded.want_response) { + switch (configType) { case meshtastic_AdminMessage_ConfigType_DEVICE_CONFIG: LOG_INFO("Getting config: Device\n"); res.get_config_response.which_payload_variant = meshtastic_Config_device_tag; @@ -457,10 +425,8 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const { meshtastic_AdminMessage res = meshtastic_AdminMessage_init_default; - if (req.decoded.want_response) - { - switch (configType) - { + if (req.decoded.want_response) { + switch (configType) { case meshtastic_AdminMessage_ModuleConfigType_MQTT_CONFIG: LOG_INFO("Getting module config: MQTT\n"); res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_mqtt_tag; @@ -556,8 +522,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r conn.wifi.status.is_connected = WiFi.status() != WL_CONNECTED; #endif strncpy(conn.wifi.ssid, config.network.wifi_ssid, 33); - if (conn.wifi.status.is_connected) - { + if (conn.wifi.status.is_connected) { conn.wifi.rssi = WiFi.RSSI(); conn.wifi.status.ip_address = WiFi.localIP(); conn.wifi.status.is_mqtt_connected = mqtt && mqtt->connected(); @@ -571,15 +536,12 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r #if HAS_ETHERNET conn.has_ethernet = true; conn.ethernet.has_status = true; - if (Ethernet.linkStatus() == LinkON) - { + if (Ethernet.linkStatus() == LinkON) { conn.ethernet.status.is_connected = true; conn.ethernet.status.ip_address = Ethernet.localIP(); conn.ethernet.status.is_mqtt_connected = mqtt && mqtt->connected(); conn.ethernet.status.is_syslog_connected = false; // FIXME wire this up - } - else - { + } else { conn.ethernet.status.is_connected = false; } #else @@ -607,8 +569,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r void AdminModule::handleGetChannel(const meshtastic_MeshPacket &req, uint32_t channelIndex) { - if (req.decoded.want_response) - { + if (req.decoded.want_response) { // We create the reply here meshtastic_AdminMessage r = meshtastic_AdminMessage_init_default; r.get_channel_response = channels.getByIndex(channelIndex); @@ -626,17 +587,13 @@ void AdminModule::reboot(int32_t seconds) void AdminModule::saveChanges(int saveWhat, bool shouldReboot) { - if (!hasOpenEditTransaction) - { + if (!hasOpenEditTransaction) { LOG_INFO("Saving changes to disk\n"); service.reloadConfig(saveWhat); // Calls saveToDisk among other things - } - else - { + } else { LOG_INFO("Delaying save of changes to disk until the open transaction is committed\n"); } - if (shouldReboot) - { + if (shouldReboot) { reboot(DEFAULT_REBOOT_SECONDS); } } From 1a7991c6065a025c28645e1ee0da58c98bcbe850 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 3 Feb 2023 15:08:49 -0600 Subject: [PATCH 33/54] Why would you even --- src/platform/rp2040/rp2040CryptoEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/rp2040/rp2040CryptoEngine.cpp b/src/platform/rp2040/rp2040CryptoEngine.cpp index bb1c00779..c90126cc7 100644 --- a/src/platform/rp2040/rp2040CryptoEngine.cpp +++ b/src/platform/rp2040/rp2040CryptoEngine.cpp @@ -1,6 +1,6 @@ -#include "configuration.h" #include "CryptoEngine.h" #include "aes.hpp" +#include "configuration.h" class RP2040CryptoEngine : public CryptoEngine { From bba4de3ec70b89963dbdb3da8af58fab00a82071 Mon Sep 17 00:00:00 2001 From: thebentern Date: Fri, 3 Feb 2023 21:39:01 +0000 Subject: [PATCH 34/54] [create-pull-request] automated change --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index f68474788..78d9518bf 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 0 -build = 18 +build = 19 From 22500a6c34c5b6896668bf299361e6e8855661a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Fri, 3 Feb 2023 14:36:31 +0100 Subject: [PATCH 35/54] tryfix for #2242 --- src/mqtt/MQTT.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 5e32050ad..b03ae3579 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -17,9 +17,9 @@ MQTT *mqtt; -String statusTopic = "msh/2/stat/"; -String cryptTopic = "msh/2/c/"; // msh/2/c/CHANNELID/NODEID -String jsonTopic = "msh/2/json/"; // msh/2/json/CHANNELID/NODEID +std::string statusTopic = "msh/2/stat/"; +std::string cryptTopic = "msh/2/c/"; // msh/2/c/CHANNELID/NODEID +std::string jsonTopic = "msh/2/json/"; // msh/2/json/CHANNELID/NODEID static MemoryDynamic staticMqttPool; @@ -238,11 +238,11 @@ void MQTT::sendSubscriptions() for (size_t i = 0; i < numChan; i++) { auto &ch = channels.getByIndex(i); if (ch.settings.downlink_enabled) { - String topic = cryptTopic + channels.getGlobalId(i) + "/#"; + std::string topic = cryptTopic + channels.getGlobalId(i) + "/#"; LOG_INFO("Subscribing to %s\n", topic.c_str()); pubSub.subscribe(topic.c_str(), 1); // FIXME, is QOS 1 right? if (moduleConfig.mqtt.json_enabled == true) { - String topicDecoded = jsonTopic + channels.getGlobalId(i) + "/#"; + std::string topicDecoded = jsonTopic + channels.getGlobalId(i) + "/#"; LOG_INFO("Subscribing to %s\n", topicDecoded.c_str()); pubSub.subscribe(topicDecoded.c_str(), 1); // FIXME, is QOS 1 right? } @@ -296,7 +296,7 @@ int32_t MQTT::runOnce() static uint8_t bytes[meshtastic_MeshPacket_size + 64]; size_t numBytes = pb_encode_to_bytes(bytes, sizeof(bytes), &meshtastic_ServiceEnvelope_msg, env); - String topic = cryptTopic + env->channel_id + "/" + owner.id; + std::string topic = cryptTopic + env->channel_id + "/" + owner.id; LOG_INFO("publish %s, %u bytes from queue\n", topic.c_str(), numBytes); pubSub.publish(topic.c_str(), bytes, numBytes, false); @@ -305,7 +305,7 @@ int32_t MQTT::runOnce() // handle json topic auto jsonString = this->downstreamPacketToJson(env->packet); if (jsonString.length() != 0) { - String topicJson = jsonTopic + env->channel_id + "/" + owner.id; + std::string topicJson = jsonTopic + env->channel_id + "/" + owner.id; LOG_INFO("JSON publish message to %s, %u bytes: %s\n", topicJson.c_str(), jsonString.length(), jsonString.c_str()); pubSub.publish(topicJson.c_str(), jsonString.c_str(), false); @@ -350,7 +350,7 @@ void MQTT::onSend(const meshtastic_MeshPacket &mp, ChannelIndex chIndex) static uint8_t bytes[meshtastic_MeshPacket_size + 64]; size_t numBytes = pb_encode_to_bytes(bytes, sizeof(bytes), &meshtastic_ServiceEnvelope_msg, env); - String topic = cryptTopic + channelId + "/" + owner.id; + std::string topic = cryptTopic + channelId + "/" + owner.id; LOG_DEBUG("publish %s, %u bytes\n", topic.c_str(), numBytes); pubSub.publish(topic.c_str(), bytes, numBytes, false); @@ -359,7 +359,7 @@ void MQTT::onSend(const meshtastic_MeshPacket &mp, ChannelIndex chIndex) // handle json topic auto jsonString = this->downstreamPacketToJson((meshtastic_MeshPacket *)&mp); if (jsonString.length() != 0) { - String topicJson = jsonTopic + channelId + "/" + owner.id; + std::string topicJson = jsonTopic + channelId + "/" + owner.id; LOG_INFO("JSON publish message to %s, %u bytes: %s\n", topicJson.c_str(), jsonString.length(), jsonString.c_str()); pubSub.publish(topicJson.c_str(), jsonString.c_str(), false); @@ -386,7 +386,7 @@ std::string MQTT::downstreamPacketToJson(meshtastic_MeshPacket *mp) { // the created jsonObj is immutable after creation, so // we need to do the heavy lifting before assembling it. - String msgType; + std::string msgType; JSONObject msgPayload; JSONObject jsonObj; From d97a09ba1fe042523e5c05a75c8c68d0ea2dbb96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 4 Feb 2023 14:56:04 +0100 Subject: [PATCH 36/54] add DEBUG_HEAP_MQTT flag to send stats info to mqtt. Used to graph these values over time. Turned off for regular builds --- src/Power.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Power.cpp b/src/Power.cpp index 082c05181..f84c7b71d 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -7,6 +7,12 @@ #include "sleep.h" #include "utils.h" +#ifdef DEBUG_HEAP_MQTT +#include "mqtt/MQTT.h" +#include "target_specific.h" +#include +#endif + #ifdef HAS_PMU #include "XPowersAXP192.tpp" #include "XPowersAXP2101.tpp" @@ -311,6 +317,25 @@ void Power::readPowerStatus() ESP.getFreeHeap() - lastheap, running, concurrency::mainController.size(false)); lastheap = ESP.getFreeHeap(); } +#ifdef DEBUG_HEAP_MQTT + if (mqtt) { + // send MQTT-Packet with Heap-Size + uint8_t dmac[6]; + getMacAddr(dmac); // Get our hardware ID + char mac[18]; + sprintf(mac, "!%02x%02x%02x%02x", dmac[2], dmac[3], dmac[4], dmac[5]); + auto newHeap = ESP.getFreeHeap(); + std::string heapTopic = "msh/2/heap/" + std::string(mac); + std::string heapString = std::to_string(newHeap); + mqtt->pubSub.publish(heapTopic.c_str(), heapString.c_str(), false); + // auto fragHeap = ESP.getHeapFragmentation(); + auto wifiRSSI = WiFi.RSSI(); + heapTopic = "msh/2/wifi/" + std::string(mac); + std::string wifiString = std::to_string(wifiRSSI); + mqtt->pubSub.publish(heapTopic.c_str(), wifiString.c_str(), false); + } +#endif + #endif // If we have a battery at all and it is less than 10% full, force deep sleep if we have more than 3 low readings in a row From c28d469fc6e5822a7863dcc038ca010dea7e73ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 4 Feb 2023 17:13:38 +0100 Subject: [PATCH 37/54] Change LED Blink time in light sleep to 100ms --- src/PowerFSM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index c36c65efc..d99d7c975 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -79,7 +79,7 @@ static void lsIdle() // Normal case: timer expired, we should just go back to sleep ASAP setLed(true); // briefly turn on led - wakeCause2 = doLightSleep(1); // leave led on for 1ms + wakeCause2 = doLightSleep(100); // leave led on for 1ms secsSlept += sleepTime; // LOG_INFO("sleeping, flash led!\n"); From 18442816ef4246bebec66231194d6e217c066f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 4 Feb 2023 17:15:36 +0100 Subject: [PATCH 38/54] trunk fmt --- src/PowerFSM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index d99d7c975..e96b36c11 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -78,7 +78,7 @@ static void lsIdle() case ESP_SLEEP_WAKEUP_TIMER: // Normal case: timer expired, we should just go back to sleep ASAP - setLed(true); // briefly turn on led + setLed(true); // briefly turn on led wakeCause2 = doLightSleep(100); // leave led on for 1ms secsSlept += sleepTime; From d83a0b1818016068d4a8f3f37699eb0b18f84728 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 4 Feb 2023 13:07:14 -0600 Subject: [PATCH 39/54] Initial air quality telemetry feature --- platformio.ini | 3 +- protobufs | 2 +- src/configuration.h | 1 + src/detect/i2cScan.h | 4 + src/main.cpp | 1 - src/mesh/generated/meshtastic/admin.pb.c | 3 + src/mesh/generated/meshtastic/admin.pb.h | 33 +++++ src/mesh/generated/meshtastic/telemetry.pb.c | 3 + src/mesh/generated/meshtastic/telemetry.pb.h | 81 ++++++++++- src/modules/Modules.cpp | 4 + src/modules/Telemetry/AirQualityTelemetry.cpp | 128 ++++++++++++++++++ src/modules/Telemetry/AirQualityTelemetry.h | 37 +++++ .../Telemetry/EnvironmentTelemetry.cpp | 20 +-- 13 files changed, 301 insertions(+), 19 deletions(-) create mode 100644 src/modules/Telemetry/AirQualityTelemetry.cpp create mode 100644 src/modules/Telemetry/AirQualityTelemetry.h diff --git a/platformio.ini b/platformio.ini index 1d8083f70..a833c42a5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -2,7 +2,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -;default_envs = tbeam +default_envs = tbeam ;default_envs = pico ;default_envs = tbeam-s3-core ;default_envs = tbeam0.7 @@ -109,3 +109,4 @@ lib_deps = adafruit/Adafruit SHTC3 Library@^1.0.0 adafruit/Adafruit LPS2X@^2.0.4 adafruit/Adafruit SHT31 Library@^2.2.0 + adafruit/Adafruit PM25 AQI Sensor@^1.0.6 diff --git a/protobufs b/protobufs index 516074f2e..384b664a7 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 516074f2e49743c234430abb2ea43ea3f66b0acb +Subproject commit 384b664a759592d9393642ba98835f69bb8f2fb2 diff --git a/src/configuration.h b/src/configuration.h index 6181034a5..f35fff4e0 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -116,6 +116,7 @@ along with this program. If not, see . #define LPS22HB_ADDR 0x5C #define LPS22HB_ADDR_ALT 0x5D #define SHT31_ADDR 0x44 +#define PMSA0031_ADDR 0x12 // ----------------------------------------------------------------------------- // Security diff --git a/src/detect/i2cScan.h b/src/detect/i2cScan.h index 87ca55957..a2d7b7baf 100644 --- a/src/detect/i2cScan.h +++ b/src/detect/i2cScan.h @@ -218,6 +218,10 @@ void scanI2Cdevice() LOG_INFO("QMC5883L Highrate 3-Axis magnetic sensor found\n"); nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_QMC5883L] = addr; } + if (addr == PMSA0031_ADDR) { + LOG_INFO("PMSA0031 air quality sensor found\n"); + nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_PMSA003I] = addr; + } } else if (err == 4) { LOG_ERROR("Unknow error at address 0x%x\n", addr); } diff --git a/src/main.cpp b/src/main.cpp index 49963a415..89148c22b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -276,7 +276,6 @@ void setup() LOG_INFO("PCF8563 RTC found\n"); } #endif - // We need to scan here to decide if we have a screen for nodeDB.init() scanI2Cdevice(); diff --git a/src/mesh/generated/meshtastic/admin.pb.c b/src/mesh/generated/meshtastic/admin.pb.c index 1f668dabc..c897c1760 100644 --- a/src/mesh/generated/meshtastic/admin.pb.c +++ b/src/mesh/generated/meshtastic/admin.pb.c @@ -9,6 +9,9 @@ PB_BIND(meshtastic_AdminMessage, meshtastic_AdminMessage, 2) +PB_BIND(meshtastic_HamParameters, meshtastic_HamParameters, AUTO) + + diff --git a/src/mesh/generated/meshtastic/admin.pb.h b/src/mesh/generated/meshtastic/admin.pb.h index e35b79a57..25bc77241 100644 --- a/src/mesh/generated/meshtastic/admin.pb.h +++ b/src/mesh/generated/meshtastic/admin.pb.h @@ -57,6 +57,18 @@ typedef enum _meshtastic_AdminMessage_ModuleConfigType { } meshtastic_AdminMessage_ModuleConfigType; /* Struct definitions */ +/* Parameters for setting up Meshtastic for ameteur radio usage */ +typedef struct _meshtastic_HamParameters { + /* Amateur radio call sign, eg. KD2ABC */ + char call_sign[8]; + /* Transmit power in dBm at the LoRA transceiver, not including any amplification */ + int32_t tx_power; + /* The selected frequency of LoRA operation + Please respect your local laws, regulations, and band plans. + Ensure your radio is capable of operating of the selected frequency before setting this. */ + float frequency; +} meshtastic_HamParameters; + /* This message is handled by the Admin module and is responsible for all settings/channel read/write operations. This message is used to do settings operations to both remote AND local nodes. (Prior to 1.2 these operations were done via special ToRadio operations) */ @@ -96,6 +108,8 @@ typedef struct _meshtastic_AdminMessage { bool get_device_connection_status_request; /* Device connection status response */ meshtastic_DeviceConnectionStatus get_device_connection_status_response; + /* Setup a node for licensed amateur (ham) radio operation */ + meshtastic_HamParameters set_ham_mode; /* Set the owner for this node */ meshtastic_User set_owner; /* Set channels (using the new API). @@ -152,11 +166,17 @@ extern "C" { #define meshtastic_AdminMessage_payload_variant_get_module_config_request_ENUMTYPE meshtastic_AdminMessage_ModuleConfigType + /* Initializer values for message structs */ #define meshtastic_AdminMessage_init_default {0, {0}} +#define meshtastic_HamParameters_init_default {"", 0, 0} #define meshtastic_AdminMessage_init_zero {0, {0}} +#define meshtastic_HamParameters_init_zero {"", 0, 0} /* Field tags (for use in manual encoding/decoding) */ +#define meshtastic_HamParameters_call_sign_tag 1 +#define meshtastic_HamParameters_tx_power_tag 2 +#define meshtastic_HamParameters_frequency_tag 3 #define meshtastic_AdminMessage_get_channel_request_tag 1 #define meshtastic_AdminMessage_get_channel_response_tag 2 #define meshtastic_AdminMessage_get_owner_request_tag 3 @@ -173,6 +193,7 @@ extern "C" { #define meshtastic_AdminMessage_get_ringtone_response_tag 15 #define meshtastic_AdminMessage_get_device_connection_status_request_tag 16 #define meshtastic_AdminMessage_get_device_connection_status_response_tag 17 +#define meshtastic_AdminMessage_set_ham_mode_tag 18 #define meshtastic_AdminMessage_set_owner_tag 32 #define meshtastic_AdminMessage_set_channel_tag 33 #define meshtastic_AdminMessage_set_config_tag 34 @@ -206,6 +227,7 @@ X(a, STATIC, ONEOF, BOOL, (payload_variant,get_ringtone_request,get_rin X(a, STATIC, ONEOF, STRING, (payload_variant,get_ringtone_response,get_ringtone_response), 15) \ X(a, STATIC, ONEOF, BOOL, (payload_variant,get_device_connection_status_request,get_device_connection_status_request), 16) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,get_device_connection_status_response,get_device_connection_status_response), 17) \ +X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_ham_mode,set_ham_mode), 18) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_owner,set_owner), 32) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_channel,set_channel), 33) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_config,set_config), 34) \ @@ -228,18 +250,29 @@ X(a, STATIC, ONEOF, INT32, (payload_variant,nodedb_reset,nodedb_reset), #define meshtastic_AdminMessage_payload_variant_get_module_config_response_MSGTYPE meshtastic_ModuleConfig #define meshtastic_AdminMessage_payload_variant_get_device_metadata_response_MSGTYPE meshtastic_DeviceMetadata #define meshtastic_AdminMessage_payload_variant_get_device_connection_status_response_MSGTYPE meshtastic_DeviceConnectionStatus +#define meshtastic_AdminMessage_payload_variant_set_ham_mode_MSGTYPE meshtastic_HamParameters #define meshtastic_AdminMessage_payload_variant_set_owner_MSGTYPE meshtastic_User #define meshtastic_AdminMessage_payload_variant_set_channel_MSGTYPE meshtastic_Channel #define meshtastic_AdminMessage_payload_variant_set_config_MSGTYPE meshtastic_Config #define meshtastic_AdminMessage_payload_variant_set_module_config_MSGTYPE meshtastic_ModuleConfig +#define meshtastic_HamParameters_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, STRING, call_sign, 1) \ +X(a, STATIC, SINGULAR, INT32, tx_power, 2) \ +X(a, STATIC, SINGULAR, FLOAT, frequency, 3) +#define meshtastic_HamParameters_CALLBACK NULL +#define meshtastic_HamParameters_DEFAULT NULL + extern const pb_msgdesc_t meshtastic_AdminMessage_msg; +extern const pb_msgdesc_t meshtastic_HamParameters_msg; /* Defines for backwards compatibility with code written before nanopb-0.4.0 */ #define meshtastic_AdminMessage_fields &meshtastic_AdminMessage_msg +#define meshtastic_HamParameters_fields &meshtastic_HamParameters_msg /* Maximum encoded size of messages (where known) */ #define meshtastic_AdminMessage_size 234 +#define meshtastic_HamParameters_size 25 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/meshtastic/telemetry.pb.c b/src/mesh/generated/meshtastic/telemetry.pb.c index cdc01710a..cbcac3e20 100644 --- a/src/mesh/generated/meshtastic/telemetry.pb.c +++ b/src/mesh/generated/meshtastic/telemetry.pb.c @@ -12,6 +12,9 @@ PB_BIND(meshtastic_DeviceMetrics, meshtastic_DeviceMetrics, AUTO) PB_BIND(meshtastic_EnvironmentMetrics, meshtastic_EnvironmentMetrics, AUTO) +PB_BIND(meshtastic_AirQualityMetrics, meshtastic_AirQualityMetrics, AUTO) + + PB_BIND(meshtastic_Telemetry, meshtastic_Telemetry, AUTO) diff --git a/src/mesh/generated/meshtastic/telemetry.pb.h b/src/mesh/generated/meshtastic/telemetry.pb.h index 188b27d77..6d4a5e1fc 100644 --- a/src/mesh/generated/meshtastic/telemetry.pb.h +++ b/src/mesh/generated/meshtastic/telemetry.pb.h @@ -10,7 +10,7 @@ #endif /* Enum definitions */ -/* TODO: REPLACE */ +/* Supported I2C Sensors for telemetry in Meshtastic */ typedef enum _meshtastic_TelemetrySensorType { /* No external telemetry sensor explicitly set */ meshtastic_TelemetrySensorType_SENSOR_UNSET = 0, @@ -37,7 +37,9 @@ typedef enum _meshtastic_TelemetrySensorType { /* 3-Axis magnetic sensor */ meshtastic_TelemetrySensorType_QMC5883L = 11, /* High accuracy temperature and humidity */ - meshtastic_TelemetrySensorType_SHT31 = 12 + meshtastic_TelemetrySensorType_SHT31 = 12, + /* PM2.5 air quality sensor */ + meshtastic_TelemetrySensorType_PMSA003I = 13 } meshtastic_TelemetrySensorType; /* Struct definitions */ @@ -69,6 +71,34 @@ typedef struct _meshtastic_EnvironmentMetrics { float current; } meshtastic_EnvironmentMetrics; +/* Air quality metrics */ +typedef struct _meshtastic_AirQualityMetrics { + /* Standard PM1.0 */ + uint32_t pm10_standard; + /* Standard PM2.5 */ + uint32_t pm25_standard; + /* Standard PM10.0 */ + uint32_t pm100_standard; + /* Environmental PM1.0 */ + uint32_t pm10_environmental; + /* Environmental PM2.5 */ + uint32_t pm25_environmental; + /* Environmental PM10.0 */ + uint32_t pm100_environmental; + /* 0.3um Particle Count */ + uint32_t particles_03um; + /* 0.5um Particle Count */ + uint32_t particles_05um; + /* 1.0um Particle Count */ + uint32_t particles_10um; + /* 2.5um Particle Count */ + uint32_t particles_25um; + /* 5.0um Particle Count */ + uint32_t particles_50um; + /* 10.0um Particle Count */ + uint32_t particles_100um; +} meshtastic_AirQualityMetrics; + /* Types of Measurements the telemetry module is equipped to handle */ typedef struct _meshtastic_Telemetry { /* This is usually not sent over the mesh (to save space), but it is sent @@ -83,6 +113,8 @@ typedef struct _meshtastic_Telemetry { meshtastic_DeviceMetrics device_metrics; /* Weather station or other environmental metrics */ meshtastic_EnvironmentMetrics environment_metrics; + /* Air quality metrics */ + meshtastic_AirQualityMetrics air_quality_metrics; } variant; } meshtastic_Telemetry; @@ -93,8 +125,9 @@ extern "C" { /* Helper constants for enums */ #define _meshtastic_TelemetrySensorType_MIN meshtastic_TelemetrySensorType_SENSOR_UNSET -#define _meshtastic_TelemetrySensorType_MAX meshtastic_TelemetrySensorType_SHT31 -#define _meshtastic_TelemetrySensorType_ARRAYSIZE ((meshtastic_TelemetrySensorType)(meshtastic_TelemetrySensorType_SHT31+1)) +#define _meshtastic_TelemetrySensorType_MAX meshtastic_TelemetrySensorType_PMSA003I +#define _meshtastic_TelemetrySensorType_ARRAYSIZE ((meshtastic_TelemetrySensorType)(meshtastic_TelemetrySensorType_PMSA003I+1)) + @@ -103,9 +136,11 @@ extern "C" { /* Initializer values for message structs */ #define meshtastic_DeviceMetrics_init_default {0, 0, 0, 0} #define meshtastic_EnvironmentMetrics_init_default {0, 0, 0, 0, 0, 0} +#define meshtastic_AirQualityMetrics_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_Telemetry_init_default {0, 0, {meshtastic_DeviceMetrics_init_default}} #define meshtastic_DeviceMetrics_init_zero {0, 0, 0, 0} #define meshtastic_EnvironmentMetrics_init_zero {0, 0, 0, 0, 0, 0} +#define meshtastic_AirQualityMetrics_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_Telemetry_init_zero {0, 0, {meshtastic_DeviceMetrics_init_zero}} /* Field tags (for use in manual encoding/decoding) */ @@ -119,9 +154,22 @@ extern "C" { #define meshtastic_EnvironmentMetrics_gas_resistance_tag 4 #define meshtastic_EnvironmentMetrics_voltage_tag 5 #define meshtastic_EnvironmentMetrics_current_tag 6 +#define meshtastic_AirQualityMetrics_pm10_standard_tag 1 +#define meshtastic_AirQualityMetrics_pm25_standard_tag 2 +#define meshtastic_AirQualityMetrics_pm100_standard_tag 3 +#define meshtastic_AirQualityMetrics_pm10_environmental_tag 4 +#define meshtastic_AirQualityMetrics_pm25_environmental_tag 5 +#define meshtastic_AirQualityMetrics_pm100_environmental_tag 6 +#define meshtastic_AirQualityMetrics_particles_03um_tag 7 +#define meshtastic_AirQualityMetrics_particles_05um_tag 8 +#define meshtastic_AirQualityMetrics_particles_10um_tag 9 +#define meshtastic_AirQualityMetrics_particles_25um_tag 10 +#define meshtastic_AirQualityMetrics_particles_50um_tag 11 +#define meshtastic_AirQualityMetrics_particles_100um_tag 12 #define meshtastic_Telemetry_time_tag 1 #define meshtastic_Telemetry_device_metrics_tag 2 #define meshtastic_Telemetry_environment_metrics_tag 3 +#define meshtastic_Telemetry_air_quality_metrics_tag 4 /* Struct field encoding specification for nanopb */ #define meshtastic_DeviceMetrics_FIELDLIST(X, a) \ @@ -142,28 +190,49 @@ X(a, STATIC, SINGULAR, FLOAT, current, 6) #define meshtastic_EnvironmentMetrics_CALLBACK NULL #define meshtastic_EnvironmentMetrics_DEFAULT NULL +#define meshtastic_AirQualityMetrics_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, UINT32, pm10_standard, 1) \ +X(a, STATIC, SINGULAR, UINT32, pm25_standard, 2) \ +X(a, STATIC, SINGULAR, UINT32, pm100_standard, 3) \ +X(a, STATIC, SINGULAR, UINT32, pm10_environmental, 4) \ +X(a, STATIC, SINGULAR, UINT32, pm25_environmental, 5) \ +X(a, STATIC, SINGULAR, UINT32, pm100_environmental, 6) \ +X(a, STATIC, SINGULAR, UINT32, particles_03um, 7) \ +X(a, STATIC, SINGULAR, UINT32, particles_05um, 8) \ +X(a, STATIC, SINGULAR, UINT32, particles_10um, 9) \ +X(a, STATIC, SINGULAR, UINT32, particles_25um, 10) \ +X(a, STATIC, SINGULAR, UINT32, particles_50um, 11) \ +X(a, STATIC, SINGULAR, UINT32, particles_100um, 12) +#define meshtastic_AirQualityMetrics_CALLBACK NULL +#define meshtastic_AirQualityMetrics_DEFAULT NULL + #define meshtastic_Telemetry_FIELDLIST(X, a) \ X(a, STATIC, SINGULAR, FIXED32, time, 1) \ X(a, STATIC, ONEOF, MESSAGE, (variant,device_metrics,variant.device_metrics), 2) \ -X(a, STATIC, ONEOF, MESSAGE, (variant,environment_metrics,variant.environment_metrics), 3) +X(a, STATIC, ONEOF, MESSAGE, (variant,environment_metrics,variant.environment_metrics), 3) \ +X(a, STATIC, ONEOF, MESSAGE, (variant,air_quality_metrics,variant.air_quality_metrics), 4) #define meshtastic_Telemetry_CALLBACK NULL #define meshtastic_Telemetry_DEFAULT NULL #define meshtastic_Telemetry_variant_device_metrics_MSGTYPE meshtastic_DeviceMetrics #define meshtastic_Telemetry_variant_environment_metrics_MSGTYPE meshtastic_EnvironmentMetrics +#define meshtastic_Telemetry_variant_air_quality_metrics_MSGTYPE meshtastic_AirQualityMetrics extern const pb_msgdesc_t meshtastic_DeviceMetrics_msg; extern const pb_msgdesc_t meshtastic_EnvironmentMetrics_msg; +extern const pb_msgdesc_t meshtastic_AirQualityMetrics_msg; extern const pb_msgdesc_t meshtastic_Telemetry_msg; /* Defines for backwards compatibility with code written before nanopb-0.4.0 */ #define meshtastic_DeviceMetrics_fields &meshtastic_DeviceMetrics_msg #define meshtastic_EnvironmentMetrics_fields &meshtastic_EnvironmentMetrics_msg +#define meshtastic_AirQualityMetrics_fields &meshtastic_AirQualityMetrics_msg #define meshtastic_Telemetry_fields &meshtastic_Telemetry_msg /* Maximum encoded size of messages (where known) */ +#define meshtastic_AirQualityMetrics_size 72 #define meshtastic_DeviceMetrics_size 21 #define meshtastic_EnvironmentMetrics_size 30 -#define meshtastic_Telemetry_size 37 +#define meshtastic_Telemetry_size 79 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/modules/Modules.cpp b/src/modules/Modules.cpp index e8481356b..bc874a9a3 100644 --- a/src/modules/Modules.cpp +++ b/src/modules/Modules.cpp @@ -14,6 +14,7 @@ #include "modules/TraceRouteModule.h" #include "modules/WaypointModule.h" #if HAS_TELEMETRY +#include "modules/Telemetry/AirQualityTelemetry.h" #include "modules/Telemetry/DeviceTelemetry.h" #include "modules/Telemetry/EnvironmentTelemetry.h" #endif @@ -63,6 +64,9 @@ void setupModules() #if HAS_TELEMETRY new DeviceTelemetryModule(); new EnvironmentTelemetryModule(); + if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_PMSA003I] > 0) { + new AirQualityTelemetryModule(); + } #endif #if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) new SerialModule(); diff --git a/src/modules/Telemetry/AirQualityTelemetry.cpp b/src/modules/Telemetry/AirQualityTelemetry.cpp new file mode 100644 index 000000000..2b744c489 --- /dev/null +++ b/src/modules/Telemetry/AirQualityTelemetry.cpp @@ -0,0 +1,128 @@ +#include "AirQualityTelemetry.h" +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "MeshService.h" +#include "NodeDB.h" +#include "PowerFSM.h" +#include "RTC.h" +#include "Router.h" +#include "configuration.h" +#include "main.h" + +int32_t AirQualityTelemetryModule::runOnce() +{ +#ifndef ARCH_PORTDUINO + int32_t result = INT32_MAX; + /* + Uncomment the preferences below if you want to use the module + without having to configure it from the PythonAPI or WebUI. + */ + + // moduleConfig.telemetry.environment_measurement_enabled = 1; + + if (!(moduleConfig.telemetry.environment_measurement_enabled)) { + // If this module is not enabled, and the user doesn't want the display screen don't waste any OSThread time on it + return disable(); + } + + if (firstTime) { + // This is the first time the OSThread library has called this function, so do some setup + firstTime = 0; + + if (moduleConfig.telemetry.environment_measurement_enabled) { + LOG_INFO("Air quality Telemetry: Initializing\n"); + if (!aqi.begin_I2C()) { + LOG_WARN("Could not establish i2c connection to AQI sensor\n"); + return disable(); + } + return 1000; + } + return result; + } else { + // if we somehow got to a second run of this module with measurement disabled, then just wait forever + if (!moduleConfig.telemetry.environment_measurement_enabled) + return result; + + uint32_t now = millis(); + if (((lastSentToMesh == 0) || + ((now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval))) && + airTime->isTxAllowedAirUtil()) { + sendTelemetry(); + lastSentToMesh = now; + } else if (service.isToPhoneQueueEmpty()) { + // Just send to phone when it's not our time to send to mesh yet + // Only send while queue is empty (phone assumed connected) + sendTelemetry(NODENUM_BROADCAST, true); + } + } + return sendToPhoneIntervalMs; +#endif +} + +bool AirQualityTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t) +{ + if (t->which_variant == meshtastic_Telemetry_air_quality_metrics_tag) { + const char *sender = getSenderShortName(mp); + + LOG_INFO("(Received from %s): pm10_standard=%i, pm25_standard=%i, pm100_standard=%i\n", sender, + t->variant.air_quality_metrics.pm10_standard, t->variant.air_quality_metrics.pm25_standard, + t->variant.air_quality_metrics.pm100_standard); + + LOG_INFO(" | PM1.0(Environmental)=%i, PM2.5(Environmental)=%i, PM10.0(Environmental)=%i\n", + t->variant.air_quality_metrics.pm10_environmental, t->variant.air_quality_metrics.pm25_environmental, + t->variant.air_quality_metrics.pm100_environmental); + + // release previous packet before occupying a new spot + if (lastMeasurementPacket != nullptr) + packetPool.release(lastMeasurementPacket); + + lastMeasurementPacket = packetPool.allocCopy(mp); + } + + return false; // Let others look at this message also if they want +} + +bool AirQualityTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) +{ + if (!aqi.read(&data)) { + LOG_WARN("Skipping send measurements. Could not read AQIn\n"); + return false; + } + + meshtastic_Telemetry m; + m.time = getTime(); + m.which_variant = meshtastic_Telemetry_air_quality_metrics_tag; + m.variant.air_quality_metrics.pm10_standard = data.pm10_standard; + m.variant.air_quality_metrics.pm25_standard = data.pm25_standard; + m.variant.air_quality_metrics.pm100_standard = data.pm100_standard; + + m.variant.air_quality_metrics.pm10_environmental = data.pm10_env; + m.variant.air_quality_metrics.pm25_environmental = data.pm25_env; + m.variant.air_quality_metrics.pm100_environmental = data.pm100_env; + + LOG_INFO("(Sending): PM1.0(Standard)=%i, PM2.5(Standard)=%i, PM10.0(Standard)=%i\n", + m.variant.air_quality_metrics.pm10_standard, m.variant.air_quality_metrics.pm25_standard, + m.variant.air_quality_metrics.pm100_standard); + + LOG_INFO(" | PM1.0(Environmental)=%i, PM2.5(Environmental)=%i, PM10.0(Environmental)=%i\n", + m.variant.air_quality_metrics.pm10_environmental, m.variant.air_quality_metrics.pm25_environmental, + m.variant.air_quality_metrics.pm100_environmental); + + meshtastic_MeshPacket *p = allocDataProtobuf(m); + p->to = dest; + p->decoded.want_response = false; + p->priority = meshtastic_MeshPacket_Priority_MIN; + + // release previous packet before occupying a new spot + if (lastMeasurementPacket != nullptr) + packetPool.release(lastMeasurementPacket); + + lastMeasurementPacket = packetPool.allocCopy(*p); + if (phoneOnly) { + LOG_INFO("Sending packet to phone\n"); + service.sendToPhone(p); + } else { + LOG_INFO("Sending packet to mesh\n"); + service.sendToMesh(p, RX_SRC_LOCAL, true); + } + return true; +} diff --git a/src/modules/Telemetry/AirQualityTelemetry.h b/src/modules/Telemetry/AirQualityTelemetry.h new file mode 100644 index 000000000..8900c0eab --- /dev/null +++ b/src/modules/Telemetry/AirQualityTelemetry.h @@ -0,0 +1,37 @@ +#pragma once +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "Adafruit_PM25AQI.h" +#include "NodeDB.h" +#include "ProtobufModule.h" + +class AirQualityTelemetryModule : private concurrency::OSThread, public ProtobufModule +{ + public: + AirQualityTelemetryModule() + : concurrency::OSThread("AirQualityTelemetryModule"), + ProtobufModule("AirQualityTelemetry", meshtastic_PortNum_TELEMETRY_APP, &meshtastic_Telemetry_msg) + { + lastMeasurementPacket = nullptr; + setIntervalFromNow(10 * 1000); + aqi = Adafruit_PM25AQI(); + } + + protected: + /** Called to handle a particular incoming message + @return true if you've guaranteed you've handled this message and no other handlers should be considered for it + */ + virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *p) override; + virtual int32_t runOnce() override; + /** + * Send our Telemetry into the mesh + */ + bool sendTelemetry(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false); + + private: + Adafruit_PM25AQI aqi; + PM25_AQI_Data data; + bool firstTime = 1; + meshtastic_MeshPacket *lastMeasurementPacket; + uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute + uint32_t lastSentToMesh = 0; +}; diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index c1693a8c8..d9b129e70 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -118,6 +118,16 @@ int32_t EnvironmentTelemetryModule::runOnce() #endif } +bool EnvironmentTelemetryModule::wantUIFrame() +{ + return moduleConfig.telemetry.environment_screen_enabled; +} + +float EnvironmentTelemetryModule::CelsiusToFahrenheit(float c) +{ + return (c * 9) / 5 + 32; +} + uint32_t GetTimeSinceMeshPacket(const meshtastic_MeshPacket *mp) { uint32_t now = getTime(); @@ -130,16 +140,6 @@ uint32_t GetTimeSinceMeshPacket(const meshtastic_MeshPacket *mp) return delta; } -bool EnvironmentTelemetryModule::wantUIFrame() -{ - return moduleConfig.telemetry.environment_screen_enabled; -} - -float EnvironmentTelemetryModule::CelsiusToFahrenheit(float c) -{ - return (c * 9) / 5 + 32; -} - void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { display->setTextAlignment(TEXT_ALIGN_LEFT); From 1748db31605b289155177085fcfcc4fa319b08fe Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 4 Feb 2023 13:35:02 -0600 Subject: [PATCH 40/54] Init struct --- src/modules/Telemetry/AirQualityTelemetry.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/Telemetry/AirQualityTelemetry.h b/src/modules/Telemetry/AirQualityTelemetry.h index 8900c0eab..ab77d61e7 100644 --- a/src/modules/Telemetry/AirQualityTelemetry.h +++ b/src/modules/Telemetry/AirQualityTelemetry.h @@ -29,7 +29,7 @@ class AirQualityTelemetryModule : private concurrency::OSThread, public Protobuf private: Adafruit_PM25AQI aqi; - PM25_AQI_Data data; + PM25_AQI_Data data = {0}; bool firstTime = 1; meshtastic_MeshPacket *lastMeasurementPacket; uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute From b70af5cc782d95c2d183b1136ea7dfbf42718af5 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 4 Feb 2023 15:11:36 -0600 Subject: [PATCH 41/54] Set ham mode admin message --- src/modules/AdminModule.cpp | 16 ++++++++++++++++ src/modules/AdminModule.h | 1 + 2 files changed, 17 insertions(+) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 8d69289f0..94d7ebbcd 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -106,6 +106,10 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta else handleSetChannel(r->set_channel); break; + case meshtastic_AdminMessage_set_ham_mode_tag: + LOG_INFO("Client is setting ham mode\n"); + handleSetHamMode(r->set_ham_mode); + break; /** * Other @@ -598,6 +602,18 @@ void AdminModule::saveChanges(int saveWhat, bool shouldReboot) } } +void AdminModule::handleSetHamMode(const meshtastic_HamParameters &p) +{ + strncpy(owner.long_name, p.call_sign, sizeof(owner.long_name)); + owner.is_licensed = true; + config.lora.override_duty_cycle = true; + config.lora.tx_power = p.tx_power; + config.lora.override_frequency = p.frequency; + + service.reloadOwner(!hasOpenEditTransaction); + service.reloadConfig(SEGMENT_CONFIG | SEGMENT_DEVICESTATE); +} + AdminModule::AdminModule() : ProtobufModule("Admin", meshtastic_PortNum_ADMIN_APP, &meshtastic_AdminMessage_msg) { // restrict to the admin channel for rx diff --git a/src/modules/AdminModule.h b/src/modules/AdminModule.h index 76f6f8033..7170e61d6 100644 --- a/src/modules/AdminModule.h +++ b/src/modules/AdminModule.h @@ -43,6 +43,7 @@ class AdminModule : public ProtobufModule void handleSetConfig(const meshtastic_Config &c); void handleSetModuleConfig(const meshtastic_ModuleConfig &c); void handleSetChannel(); + void handleSetHamMode(const meshtastic_HamParameters &req); void reboot(int32_t seconds); }; From 405430fd964f5da85f5a12e87fa1dd93b42f2f85 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 4 Feb 2023 15:15:32 -0600 Subject: [PATCH 42/54] Whoops --- src/modules/AdminModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 94d7ebbcd..3c4cef829 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -610,7 +610,7 @@ void AdminModule::handleSetHamMode(const meshtastic_HamParameters &p) config.lora.tx_power = p.tx_power; config.lora.override_frequency = p.frequency; - service.reloadOwner(!hasOpenEditTransaction); + service.reloadOwner(false); service.reloadConfig(SEGMENT_CONFIG | SEGMENT_DEVICESTATE); } From 829318046ab576c637e9557ef76328ef750fddd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sun, 5 Feb 2023 00:11:00 +0100 Subject: [PATCH 43/54] rsyslog is working --- src/DebugConfiguration.cpp | 23 +++++++++++++++++------ src/DebugConfiguration.h | 3 ++- src/RedirectablePrint.cpp | 7 ++++++- src/mesh/eth/ethClient.cpp | 2 +- src/mesh/http/WiFiAPClient.cpp | 2 +- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/DebugConfiguration.cpp b/src/DebugConfiguration.cpp index 875d4d129..9df402e77 100644 --- a/src/DebugConfiguration.cpp +++ b/src/DebugConfiguration.cpp @@ -40,7 +40,11 @@ Syslog::Syslog(UDP &client) Syslog &Syslog::server(const char *server, uint16_t port) { - this->_server = server; + if (this->_ip.fromString(server)) { + this->_server = NULL; + } else { + this->_server = server; + } this->_port = port; return *this; } @@ -93,6 +97,11 @@ bool Syslog::isEnabled() } bool Syslog::vlogf(uint16_t pri, const char *fmt, va_list args) +{ + return this->vlogf(pri, this->_appName, fmt, args); +} + +bool Syslog::vlogf(uint16_t pri, const char *appName, const char *fmt, va_list args) { char *message; size_t initialLen; @@ -111,13 +120,13 @@ bool Syslog::vlogf(uint16_t pri, const char *fmt, va_list args) vsnprintf(message, len + 1, fmt, args); } - result = this->_sendLog(pri, message); + result = this->_sendLog(pri, appName, message); delete[] message; return result; } -inline bool Syslog::_sendLog(uint16_t pri, const char *message) +inline bool Syslog::_sendLog(uint16_t pri, const char *appName, const char *message) { int result; @@ -149,13 +158,15 @@ inline bool Syslog::_sendLog(uint16_t pri, const char *message) this->_client->print(F(">1 - ")); this->_client->print(this->_deviceHostname); this->_client->print(' '); - this->_client->print(this->_appName); + this->_client->print(appName); this->_client->print(F(" - - - \xEF\xBB\xBF")); - this->_client->print(F("[0]: ")); + this->_client->print(F("[")); + this->_client->print(int(millis() / 1000)); + this->_client->print(F("]: ")); this->_client->print(message); this->_client->endPacket(); return true; } -#endif \ No newline at end of file +#endif diff --git a/src/DebugConfiguration.h b/src/DebugConfiguration.h index 3bf476f72..36b009ff2 100644 --- a/src/DebugConfiguration.h +++ b/src/DebugConfiguration.h @@ -131,7 +131,7 @@ class Syslog uint8_t _priMask = 0xff; bool _enabled = false; - bool _sendLog(uint16_t pri, const char *message); + bool _sendLog(uint16_t pri, const char *appName, const char *message); public: explicit Syslog(UDP &client); @@ -148,6 +148,7 @@ class Syslog bool isEnabled(); bool vlogf(uint16_t pri, const char *fmt, va_list args) __attribute__((format(printf, 3, 0))); + bool vlogf(uint16_t pri, const char *appName, const char *fmt, va_list args) __attribute__((format(printf, 3, 0))); }; #endif // HAS_ETHERNET || HAS_WIFI diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index c7f60f980..14e85f0c8 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -124,7 +124,12 @@ size_t RedirectablePrint::log(const char *logLevel, const char *format, ...) default: ll = 0; } - syslog.vlogf(ll, format, arg); + auto thread = concurrency::OSThread::currentThread; + if (thread) { + syslog.vlogf(ll, thread->ThreadName.c_str(), format, arg); + } else { + syslog.vlogf(ll, format, arg); + } } #endif diff --git a/src/mesh/eth/ethClient.cpp b/src/mesh/eth/ethClient.cpp index 22365c647..659de05f8 100644 --- a/src/mesh/eth/ethClient.cpp +++ b/src/mesh/eth/ethClient.cpp @@ -45,7 +45,7 @@ static int32_t reconnectETH() LOG_INFO("Starting Syslog client\n"); // Defaults int serverPort = 514; - const char *serverAddr = moduleConfig.mqtt.address; + const char *serverAddr = config.network.rsyslog_server; String server = String(serverAddr); int delimIndex = server.indexOf(':'); if (delimIndex > 0) { diff --git a/src/mesh/http/WiFiAPClient.cpp b/src/mesh/http/WiFiAPClient.cpp index a1cf98bb3..cc8d4b168 100644 --- a/src/mesh/http/WiFiAPClient.cpp +++ b/src/mesh/http/WiFiAPClient.cpp @@ -142,7 +142,7 @@ static void onNetworkConnected() LOG_INFO("Starting Syslog client\n"); // Defaults int serverPort = 514; - const char *serverAddr = moduleConfig.mqtt.address; + const char *serverAddr = config.network.rsyslog_server; String server = String(serverAddr); int delimIndex = server.indexOf(':'); if (delimIndex > 0) { From fb611ef9861348f1a73e11146b12b742a5741abf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sun, 5 Feb 2023 01:46:16 +0100 Subject: [PATCH 44/54] fix time display --- src/graphics/Screen.cpp | 30 ++++++++++++++++++------------ src/graphics/Screen.h | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 09cafc348..49dbb0645 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -70,6 +70,8 @@ static char btPIN[16] = "888888"; uint32_t logo_timeout = 5000; // 4 seconds for EACH logo +uint32_t hours_in_month = 730; // 730 hours in a month + // This image definition is here instead of images.h because it's modified dynamically by the drawBattery function uint8_t imgBattery[16] = {0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xE7, 0x3C}; @@ -386,10 +388,11 @@ static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state uint32_t days = hours / 24; if (config.display.heading_bold) { - display->drawStringf(1 + x, 0 + y, tempBuf, "%s ago from %s", screen->drawTimeDelta(days, hours, minutes, seconds), + display->drawStringf(1 + x, 0 + y, tempBuf, "%s ago from %s", + screen->drawTimeDelta(days, hours, minutes, seconds).c_str(), (node && node->has_user) ? node->user.short_name : "???"); } - display->drawStringf(0 + x, 0 + y, tempBuf, "%s ago from %s", screen->drawTimeDelta(days, hours, minutes, seconds), + display->drawStringf(0 + x, 0 + y, tempBuf, "%s ago from %s", screen->drawTimeDelta(days, hours, minutes, seconds).c_str(), (node && node->has_user) ? node->user.short_name : "???"); display->setColor(WHITE); @@ -1336,17 +1339,20 @@ void Screen::blink() dispdev.setBrightness(brightness); } -String Screen::drawTimeDelta(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds) +std::string Screen::drawTimeDelta(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds) { - String uptime; - if (days >= 2) - uptime = String(days) + "d"; + std::string uptime; + + if (days > (hours_in_month * 6)) + uptime = "?"; + else if (days >= 2) + uptime = std::to_string(days) + "d"; else if (hours >= 2) - uptime = String(hours) + "h"; + uptime = std::to_string(hours) + "h"; else if (minutes >= 1) - uptime = String(minutes) + "m"; + uptime = std::to_string(minutes) + "m"; else - uptime = String(seconds) + "s"; + uptime = std::to_string(seconds) + "s"; return uptime; } @@ -1714,7 +1720,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat display->setColor(WHITE); // Show uptime as days, hours, minutes OR seconds - String uptime = screen->drawTimeDelta(days, hours, minutes, seconds); + std::string uptime = screen->drawTimeDelta(days, hours, minutes, seconds); uint32_t rtc_sec = getValidTime(RTCQuality::RTCQualityDevice); if (rtc_sec > 0) { @@ -1729,12 +1735,12 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat int min = (hms % SEC_PER_HOUR) / SEC_PER_MIN; int sec = (hms % SEC_PER_HOUR) % SEC_PER_MIN; // or hms % SEC_PER_MIN - char timebuf[9]; + char timebuf[10]; snprintf(timebuf, sizeof(timebuf), " %02d:%02d:%02d", hour, min, sec); uptime += timebuf; } - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, uptime); + display->drawString(x, y + FONT_HEIGHT_SMALL * 1, uptime.c_str()); // Display Channel Utilization char chUtil[13]; diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index 1d732ad4c..5e92e73bb 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -207,7 +207,7 @@ class Screen : public concurrency::OSThread } /// generates a very brief time delta display - String drawTimeDelta(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds); + std::string drawTimeDelta(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds); /// Overrides the default utf8 character conversion, to replace empty space with question marks static char customFontTableLookup(const uint8_t ch) From a3dbac73fe74362cba0ed65a7afed4ae4e0b0d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sun, 5 Feb 2023 01:49:07 +0100 Subject: [PATCH 45/54] trunk fmt --- src/graphics/Screen.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 49dbb0645..c5b428537 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -70,7 +70,7 @@ static char btPIN[16] = "888888"; uint32_t logo_timeout = 5000; // 4 seconds for EACH logo -uint32_t hours_in_month = 730; // 730 hours in a month +uint32_t hours_in_month = 730; // This image definition is here instead of images.h because it's modified dynamically by the drawBattery function uint8_t imgBattery[16] = {0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xE7, 0x3C}; @@ -797,9 +797,6 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ else if (agoSecs < 120 * 60) // last 2 hrs snprintf(lastStr, sizeof(lastStr), "%u minutes ago", agoSecs / 60); else { - - uint32_t hours_in_month = 730; - // Only show hours ago if it's been less than 6 months. Otherwise, we may have bad // data. if ((agoSecs / 60 / 60) < (hours_in_month * 6)) { From b952c35da68080fa2a15fb478b0454ad776a1087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 7 Feb 2023 01:02:51 +0100 Subject: [PATCH 46/54] eliminate main source of multiline logging --- src/RedirectablePrint.cpp | 20 ++++++++++++++++++++ src/RedirectablePrint.h | 3 +++ src/mesh/RadioInterface.cpp | 31 ++++++++++++++++--------------- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index 14e85f0c8..943d38982 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -5,6 +5,7 @@ #include "configuration.h" #include #include +#include #include #include @@ -173,3 +174,22 @@ void RedirectablePrint::hexDump(const char *logLevel, unsigned char *buf, uint16 } log(logLevel, " +------------------------------------------------+ +----------------+\n"); } + +std::string RedirectablePrint::mt_sprintf(const std::string fmt_str, ...) +{ + int final_n, n = ((int)fmt_str.size()) * 2; /* Reserve two times as much as the length of the fmt_str */ + std::unique_ptr formatted; + va_list ap; + while (1) { + formatted.reset(new char[n]); /* Wrap the plain char array into the unique_ptr */ + strcpy(&formatted[0], fmt_str.c_str()); + va_start(ap, fmt_str); + final_n = vsnprintf(&formatted[0], n, fmt_str.c_str(), ap); + va_end(ap); + if (final_n < 0 || final_n >= n) + n += abs(final_n - n + 1); + else + break; + } + return std::string(formatted.get()); +} \ No newline at end of file diff --git a/src/RedirectablePrint.h b/src/RedirectablePrint.h index 659b6e10d..560021972 100644 --- a/src/RedirectablePrint.h +++ b/src/RedirectablePrint.h @@ -2,6 +2,7 @@ #include #include +#include /** * A Printable that can be switched to squirt its bytes to a different sink. @@ -40,6 +41,8 @@ class RedirectablePrint : public Print size_t vprintf(const char *format, va_list arg); void hexDump(const char *logLevel, unsigned char *buf, uint16_t len); + + std::string mt_sprintf(const std::string fmt_str, ...); }; class NoopPrint : public Print diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 61c864394..94dab0bcd 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -241,47 +241,48 @@ uint32_t RadioInterface::getTxDelayMsecWeighted(float snr) void printPacket(const char *prefix, const meshtastic_MeshPacket *p) { - LOG_DEBUG("%s (id=0x%08x fr=0x%02x to=0x%02x, WantAck=%d, HopLim=%d Ch=0x%x", prefix, p->id, p->from & 0xff, p->to & 0xff, - p->want_ack, p->hop_limit, p->channel); + std::string out = DEBUG_PORT.mt_sprintf("%s (id=0x%08x fr=0x%02x to=0x%02x, WantAck=%d, HopLim=%d Ch=0x%x", prefix, p->id, + p->from & 0xff, p->to & 0xff, p->want_ack, p->hop_limit, p->channel); if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { auto &s = p->decoded; - LOG_DEBUG(" Portnum=%d", s.portnum); + out += DEBUG_PORT.mt_sprintf(" Portnum=%d", s.portnum); if (s.want_response) - LOG_DEBUG(" WANTRESP"); + out += DEBUG_PORT.mt_sprintf(" WANTRESP"); if (s.source != 0) - LOG_DEBUG(" source=%08x", s.source); + out += DEBUG_PORT.mt_sprintf(" source=%08x", s.source); if (s.dest != 0) - LOG_DEBUG(" dest=%08x", s.dest); + out += DEBUG_PORT.mt_sprintf(" dest=%08x", s.dest); if (s.request_id) - LOG_DEBUG(" requestId=%0x", s.request_id); + out += DEBUG_PORT.mt_sprintf(" requestId=%0x", s.request_id); /* now inside Data and therefore kinda opaque if (s.which_ackVariant == SubPacket_success_id_tag) - LOG_DEBUG(" successId=%08x", s.ackVariant.success_id); + out += DEBUG_PORT.mt_sprintf(" successId=%08x", s.ackVariant.success_id); else if (s.which_ackVariant == SubPacket_fail_id_tag) - LOG_DEBUG(" failId=%08x", s.ackVariant.fail_id); */ + out += DEBUG_PORT.mt_sprintf(" failId=%08x", s.ackVariant.fail_id); */ } else { - LOG_DEBUG(" encrypted"); + out += " encrypted"; } if (p->rx_time != 0) { - LOG_DEBUG(" rxtime=%u", p->rx_time); + out += DEBUG_PORT.mt_sprintf(" rxtime=%u", p->rx_time); } if (p->rx_snr != 0.0) { - LOG_DEBUG(" rxSNR=%g", p->rx_snr); + out += DEBUG_PORT.mt_sprintf(" rxSNR=%g", p->rx_snr); } if (p->rx_rssi != 0) { - LOG_DEBUG(" rxRSSI=%i", p->rx_rssi); + out += DEBUG_PORT.mt_sprintf(" rxRSSI=%i", p->rx_rssi); } if (p->priority != 0) - LOG_DEBUG(" priority=%d", p->priority); + out += DEBUG_PORT.mt_sprintf(" priority=%d", p->priority); - LOG_DEBUG(")\n"); + out + ")\n"; + LOG_DEBUG("%s", out.c_str()); } RadioInterface::RadioInterface() From 4ac0de21ab75fb77ba7ef644afd3837b9dc34bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 7 Feb 2023 01:30:55 +0100 Subject: [PATCH 47/54] great, the ONE time i remember trunk fmt i forget to cppcheck ... --- src/RedirectablePrint.cpp | 5 +++-- suppressions.txt | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index 943d38982..04dbcdd49 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -5,6 +5,7 @@ #include "configuration.h" #include #include +#include #include #include #include @@ -177,14 +178,14 @@ void RedirectablePrint::hexDump(const char *logLevel, unsigned char *buf, uint16 std::string RedirectablePrint::mt_sprintf(const std::string fmt_str, ...) { - int final_n, n = ((int)fmt_str.size()) * 2; /* Reserve two times as much as the length of the fmt_str */ + int n = ((int)fmt_str.size()) * 2; /* Reserve two times as much as the length of the fmt_str */ std::unique_ptr formatted; va_list ap; while (1) { formatted.reset(new char[n]); /* Wrap the plain char array into the unique_ptr */ strcpy(&formatted[0], fmt_str.c_str()); va_start(ap, fmt_str); - final_n = vsnprintf(&formatted[0], n, fmt_str.c_str(), ap); + int final_n = vsnprintf(&formatted[0], n, fmt_str.c_str(), ap); va_end(ap); if (final_n < 0 || final_n >= n) n += abs(final_n - n + 1); diff --git a/suppressions.txt b/suppressions.txt index 3db2d5b7d..0dd5198ec 100644 --- a/suppressions.txt +++ b/suppressions.txt @@ -43,3 +43,4 @@ postfixOperator:*/mqtt/* missingOverride virtualCallInConstructor +passedByValue:*/RedirectablePrint.h From 7ddd8c99301529376cfe8f400693fd1bd44879d4 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 7 Feb 2023 07:06:24 -0600 Subject: [PATCH 48/54] Update protobufs to release version --- protobufs | 2 +- src/mesh/generated/meshtastic/telemetry.pb.h | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/protobufs b/protobufs index 2b391ff8a..4bd60496c 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 2b391ff8a76bfc07662faa007bb4fd6e01691ba8 +Subproject commit 4bd60496c7372b9612c8eac2b4365ff23cb92ab1 diff --git a/src/mesh/generated/meshtastic/telemetry.pb.h b/src/mesh/generated/meshtastic/telemetry.pb.h index 6d4a5e1fc..0e04ccf6e 100644 --- a/src/mesh/generated/meshtastic/telemetry.pb.h +++ b/src/mesh/generated/meshtastic/telemetry.pb.h @@ -73,17 +73,17 @@ typedef struct _meshtastic_EnvironmentMetrics { /* Air quality metrics */ typedef struct _meshtastic_AirQualityMetrics { - /* Standard PM1.0 */ + /* Concentration Units Standard PM1.0 */ uint32_t pm10_standard; - /* Standard PM2.5 */ + /* Concentration Units Standard PM2.5 */ uint32_t pm25_standard; - /* Standard PM10.0 */ + /* Concentration Units Standard PM10.0 */ uint32_t pm100_standard; - /* Environmental PM1.0 */ + /* Concentration Units Environmental PM1.0 */ uint32_t pm10_environmental; - /* Environmental PM2.5 */ + /* Concentration Units Environmental PM2.5 */ uint32_t pm25_environmental; - /* Environmental PM10.0 */ + /* Concentration Units Environmental PM10.0 */ uint32_t pm100_environmental; /* 0.3um Particle Count */ uint32_t particles_03um; From 9522d4d2f5f0a60f94b2d8c781b5fbeaaf6f45d3 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 7 Feb 2023 07:17:32 -0600 Subject: [PATCH 49/54] Make a pie? --- variants/portduino/platformio.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index 5bbde2adf..b79a97d20 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -1,6 +1,6 @@ [env:native] extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino +build_flags = ${portduino_base.build_flags} -fPIE -O0 -I variants/portduino board = cross_platform lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} @@ -8,7 +8,7 @@ build_src_filter = ${portduino_base.build_src_filter} ; The Portduino based sim environment on top of a linux OS and touching linux hardware devices [env:linux] extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -lgpiod -I variants/portduino +build_flags = ${portduino_base.build_flags} -fPIE -O0 -lgpiod -I variants/portduino board = linux_hardware lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} @@ -16,7 +16,7 @@ build_src_filter = ${portduino_base.build_src_filter} ; The Portduino based sim environment on top of a linux OS and touching linux hardware devices [env:linux-arm] extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -lgpiod -I variants/portduino +build_flags = ${portduino_base.build_flags} -fPIE -O0 -lgpiod -I variants/portduino board = linux_arm lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} From afc75b25529590253c513f19e4b6f6f0ef94bf95 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 7 Feb 2023 07:43:09 -0600 Subject: [PATCH 50/54] Can't find where this was included --- platformio.ini | 1 + src/DebugConfiguration.h | 1 + 2 files changed, 2 insertions(+) diff --git a/platformio.ini b/platformio.ini index a833c42a5..4f8f53d0c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -93,6 +93,7 @@ build_src_filter = ${env.build_src_filter} - lib_deps = knolleary/PubSubClient@^2.8 arduino-libraries/NTPClient@^3.1.0 + arcao/Syslog@^2.0.0 ; Common libs for environmental measurements in telemetry module ; (not included in native / portduino) diff --git a/src/DebugConfiguration.h b/src/DebugConfiguration.h index 36b009ff2..303e26899 100644 --- a/src/DebugConfiguration.h +++ b/src/DebugConfiguration.h @@ -117,6 +117,7 @@ #endif // HAS_WIFI #if HAS_WIFI || HAS_ETHERNET +#include class Syslog { From 4a0c341438efb0b49bd09c29b710ac31038ec3b6 Mon Sep 17 00:00:00 2001 From: GUVWAF Date: Tue, 7 Feb 2023 19:40:15 +0100 Subject: [PATCH 51/54] Make Portduino build again --- src/DebugConfiguration.h | 1 - variants/portduino/platformio.ini | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/DebugConfiguration.h b/src/DebugConfiguration.h index 303e26899..36b009ff2 100644 --- a/src/DebugConfiguration.h +++ b/src/DebugConfiguration.h @@ -117,7 +117,6 @@ #endif // HAS_WIFI #if HAS_WIFI || HAS_ETHERNET -#include class Syslog { diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index b79a97d20..e3845132b 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -1,6 +1,6 @@ [env:native] extends = portduino_base -build_flags = ${portduino_base.build_flags} -fPIE -O0 -I variants/portduino +build_flags = ${portduino_base.build_flags} -fPIC -O0 -I variants/portduino board = cross_platform lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} @@ -8,7 +8,7 @@ build_src_filter = ${portduino_base.build_src_filter} ; The Portduino based sim environment on top of a linux OS and touching linux hardware devices [env:linux] extends = portduino_base -build_flags = ${portduino_base.build_flags} -fPIE -O0 -lgpiod -I variants/portduino +build_flags = ${portduino_base.build_flags} -fPIC -O0 -lgpiod -I variants/portduino board = linux_hardware lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} @@ -16,7 +16,7 @@ build_src_filter = ${portduino_base.build_src_filter} ; The Portduino based sim environment on top of a linux OS and touching linux hardware devices [env:linux-arm] extends = portduino_base -build_flags = ${portduino_base.build_flags} -fPIE -O0 -lgpiod -I variants/portduino +build_flags = ${portduino_base.build_flags} -fPIC -O0 -lgpiod -I variants/portduino board = linux_arm lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} From a5b99ee5d57e77b478b6e46c8a38d42f886fda74 Mon Sep 17 00:00:00 2001 From: GUVWAF Date: Tue, 7 Feb 2023 20:05:40 +0100 Subject: [PATCH 52/54] Try other location --- arch/portduino/portduino.ini | 2 +- variants/portduino/platformio.ini | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index cd962b671..b44664f93 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -18,4 +18,4 @@ lib_deps = ${env.lib_deps} ${networking_base.lib_deps} rweather/Crypto@^0.4.0 -build_flags = ${arduino_base.build_flags} -Isrc/platform/portduino +build_flags = ${arduino_base.build_flags} -fPIE -Isrc/platform/portduino diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index e3845132b..5bbde2adf 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -1,6 +1,6 @@ [env:native] extends = portduino_base -build_flags = ${portduino_base.build_flags} -fPIC -O0 -I variants/portduino +build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino board = cross_platform lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} @@ -8,7 +8,7 @@ build_src_filter = ${portduino_base.build_src_filter} ; The Portduino based sim environment on top of a linux OS and touching linux hardware devices [env:linux] extends = portduino_base -build_flags = ${portduino_base.build_flags} -fPIC -O0 -lgpiod -I variants/portduino +build_flags = ${portduino_base.build_flags} -O0 -lgpiod -I variants/portduino board = linux_hardware lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} @@ -16,7 +16,7 @@ build_src_filter = ${portduino_base.build_src_filter} ; The Portduino based sim environment on top of a linux OS and touching linux hardware devices [env:linux-arm] extends = portduino_base -build_flags = ${portduino_base.build_flags} -fPIC -O0 -lgpiod -I variants/portduino +build_flags = ${portduino_base.build_flags} -O0 -lgpiod -I variants/portduino board = linux_arm lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} From 42b496b0db2972661c623ee445ce00af9d055956 Mon Sep 17 00:00:00 2001 From: GUVWAF Date: Tue, 7 Feb 2023 20:12:12 +0100 Subject: [PATCH 53/54] PIC --- arch/portduino/portduino.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index b44664f93..b6b17d391 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -18,4 +18,4 @@ lib_deps = ${env.lib_deps} ${networking_base.lib_deps} rweather/Crypto@^0.4.0 -build_flags = ${arduino_base.build_flags} -fPIE -Isrc/platform/portduino +build_flags = ${arduino_base.build_flags} -fPIC -Isrc/platform/portduino From dc230967233c6b589899fedbdb34e1a52499f5c2 Mon Sep 17 00:00:00 2001 From: thebentern Date: Tue, 7 Feb 2023 21:59:05 +0000 Subject: [PATCH 54/54] [create-pull-request] automated change --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index 78d9518bf..6443d32c2 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 0 -build = 19 +build = 20