Merge pull request #770 from mc-hamster/master

#669 - Add restart counter
1.2-legacy
Jm Casler 2021-03-27 01:30:28 -07:00 zatwierdzone przez GitHub
commit 9fb6b1718f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
5 zmienionych plików z 42 dodań i 8 usunięć

Wyświetl plik

@ -7,9 +7,10 @@
#include "sleep.h" #include "sleep.h"
#include "target_specific.h" #include "target_specific.h"
#include "utils.h" #include "utils.h"
#include <Preferences.h>
#include <driver/rtc_io.h>
#include <nvs.h> #include <nvs.h>
#include <nvs_flash.h> #include <nvs_flash.h>
#include <driver/rtc_io.h>
void getMacAddr(uint8_t *dmac) void getMacAddr(uint8_t *dmac)
{ {
@ -45,6 +46,18 @@ void esp32Setup()
DEBUG_MSG("NVS: UsedEntries %d, FreeEntries %d, AllEntries %d\n", nvs_stats.used_entries, nvs_stats.free_entries, DEBUG_MSG("NVS: UsedEntries %d, FreeEntries %d, AllEntries %d\n", nvs_stats.used_entries, nvs_stats.free_entries,
nvs_stats.total_entries); nvs_stats.total_entries);
DEBUG_MSG("Setup Preferences in Flash Storage\n");
// Create object to store our persistant data
Preferences preferences;
preferences.begin("meshtastic", false);
uint32_t rebootCounter = preferences.getUInt("rebootCounter", 0);
rebootCounter++;
preferences.putUInt("rebootCounter", rebootCounter);
preferences.end();
DEBUG_MSG("Number of Device Reboots: %d\n", rebootCounter);
// enableModemSleep(); // enableModemSleep();
// Since we are turning on watchdogs rather late in the release schedule, we really don't want to catch any // Since we are turning on watchdogs rather late in the release schedule, we really don't want to catch any

Wyświetl plik

@ -24,6 +24,7 @@
#ifndef NO_ESP32 #ifndef NO_ESP32
#include "mesh/http/WiFiAPClient.h" #include "mesh/http/WiFiAPClient.h"
#include "plugins/esp32/StoreForwardPlugin.h" #include "plugins/esp32/StoreForwardPlugin.h"
#include <Preferences.h>
#endif #endif
NodeDB nodeDB; NodeDB nodeDB;
@ -234,6 +235,15 @@ void NodeDB::init()
myNodeInfo.hw_model_deprecated[0] = '\0'; myNodeInfo.hw_model_deprecated[0] = '\0';
// strncpy(myNodeInfo.hw_model, HW_VENDOR, sizeof(myNodeInfo.hw_model)); // strncpy(myNodeInfo.hw_model, HW_VENDOR, sizeof(myNodeInfo.hw_model));
#ifndef NO_ESP32
Preferences preferences;
preferences.begin("meshtastic", false);
myNodeInfo.reboot_count = preferences.getUInt("rebootCounter", 0);
preferences.end();
DEBUG_MSG("Number of Device Reboots: %d\n", myNodeInfo.reboot_count);
#endif
resetRadioConfig(); // If bogus settings got saved, then fix them resetRadioConfig(); // If bogus settings got saved, then fix them
DEBUG_MSG("region=%d, NODENUM=0x%x, dbsize=%d\n", radioConfig.preferences.region, myNodeInfo.my_node_num, *numNodes); DEBUG_MSG("region=%d, NODENUM=0x%x, dbsize=%d\n", radioConfig.preferences.region, myNodeInfo.my_node_num, *numNodes);

Wyświetl plik

@ -125,7 +125,7 @@ extern const pb_msgdesc_t ChannelFile_msg;
/* Maximum encoded size of messages (where known) */ /* Maximum encoded size of messages (where known) */
#define LegacyRadioConfig_size 4 #define LegacyRadioConfig_size 4
#define LegacyRadioConfig_LegacyPreferences_size 2 #define LegacyRadioConfig_LegacyPreferences_size 2
#define DeviceState_size 4920 #define DeviceState_size 4926
#define ChannelFile_size 832 #define ChannelFile_size 832
#ifdef __cplusplus #ifdef __cplusplus

Wyświetl plik

@ -110,6 +110,7 @@ typedef struct _MyNodeInfo {
CriticalErrorCode error_code; CriticalErrorCode error_code;
uint32_t error_address; uint32_t error_address;
uint32_t error_count; uint32_t error_count;
uint32_t reboot_count;
uint32_t message_timeout_msec; uint32_t message_timeout_msec;
uint32_t min_app_version; uint32_t min_app_version;
uint32_t max_channels; uint32_t max_channels;
@ -233,7 +234,7 @@ extern "C" {
#define Data_init_default {_PortNum_MIN, {0, {0}}, 0, 0, 0, 0} #define Data_init_default {_PortNum_MIN, {0, {0}}, 0, 0, 0, 0}
#define MeshPacket_init_default {0, 0, 0, 0, {Data_init_default}, 0, 0, 0, 0, 0, _MeshPacket_Priority_MIN, 0} #define MeshPacket_init_default {0, 0, 0, 0, {Data_init_default}, 0, 0, 0, 0, 0, _MeshPacket_Priority_MIN, 0}
#define NodeInfo_init_default {0, false, User_init_default, false, Position_init_default, 0} #define NodeInfo_init_default {0, false, User_init_default, false, Position_init_default, 0}
#define MyNodeInfo_init_default {0, 0, 0, "", "", "", _CriticalErrorCode_MIN, 0, 0, 0, 0, 0} #define MyNodeInfo_init_default {0, 0, 0, "", "", "", _CriticalErrorCode_MIN, 0, 0, 0, 0, 0, 0}
#define LogRecord_init_default {"", 0, "", _LogRecord_Level_MIN} #define LogRecord_init_default {"", 0, "", _LogRecord_Level_MIN}
#define FromRadio_init_default {0, 0, {MyNodeInfo_init_default}} #define FromRadio_init_default {0, 0, {MyNodeInfo_init_default}}
#define ToRadio_init_default {0, {MeshPacket_init_default}} #define ToRadio_init_default {0, {MeshPacket_init_default}}
@ -244,7 +245,7 @@ extern "C" {
#define Data_init_zero {_PortNum_MIN, {0, {0}}, 0, 0, 0, 0} #define Data_init_zero {_PortNum_MIN, {0, {0}}, 0, 0, 0, 0}
#define MeshPacket_init_zero {0, 0, 0, 0, {Data_init_zero}, 0, 0, 0, 0, 0, _MeshPacket_Priority_MIN, 0} #define MeshPacket_init_zero {0, 0, 0, 0, {Data_init_zero}, 0, 0, 0, 0, 0, _MeshPacket_Priority_MIN, 0}
#define NodeInfo_init_zero {0, false, User_init_zero, false, Position_init_zero, 0} #define NodeInfo_init_zero {0, false, User_init_zero, false, Position_init_zero, 0}
#define MyNodeInfo_init_zero {0, 0, 0, "", "", "", _CriticalErrorCode_MIN, 0, 0, 0, 0, 0} #define MyNodeInfo_init_zero {0, 0, 0, "", "", "", _CriticalErrorCode_MIN, 0, 0, 0, 0, 0, 0}
#define LogRecord_init_zero {"", 0, "", _LogRecord_Level_MIN} #define LogRecord_init_zero {"", 0, "", _LogRecord_Level_MIN}
#define FromRadio_init_zero {0, 0, {MyNodeInfo_init_zero}} #define FromRadio_init_zero {0, 0, {MyNodeInfo_init_zero}}
#define ToRadio_init_zero {0, {MeshPacket_init_zero}} #define ToRadio_init_zero {0, {MeshPacket_init_zero}}
@ -269,6 +270,7 @@ extern "C" {
#define MyNodeInfo_error_code_tag 7 #define MyNodeInfo_error_code_tag 7
#define MyNodeInfo_error_address_tag 8 #define MyNodeInfo_error_address_tag 8
#define MyNodeInfo_error_count_tag 9 #define MyNodeInfo_error_count_tag 9
#define MyNodeInfo_reboot_count_tag 10
#define MyNodeInfo_message_timeout_msec_tag 13 #define MyNodeInfo_message_timeout_msec_tag 13
#define MyNodeInfo_min_app_version_tag 14 #define MyNodeInfo_min_app_version_tag 14
#define MyNodeInfo_max_channels_tag 15 #define MyNodeInfo_max_channels_tag 15
@ -392,6 +394,7 @@ X(a, STATIC, SINGULAR, STRING, firmware_version, 6) \
X(a, STATIC, SINGULAR, UENUM, error_code, 7) \ X(a, STATIC, SINGULAR, UENUM, error_code, 7) \
X(a, STATIC, SINGULAR, UINT32, error_address, 8) \ X(a, STATIC, SINGULAR, UINT32, error_address, 8) \
X(a, STATIC, SINGULAR, UINT32, error_count, 9) \ X(a, STATIC, SINGULAR, UINT32, error_count, 9) \
X(a, STATIC, SINGULAR, UINT32, reboot_count, 10) \
X(a, STATIC, SINGULAR, UINT32, message_timeout_msec, 13) \ X(a, STATIC, SINGULAR, UINT32, message_timeout_msec, 13) \
X(a, STATIC, SINGULAR, UINT32, min_app_version, 14) \ X(a, STATIC, SINGULAR, UINT32, min_app_version, 14) \
X(a, STATIC, SINGULAR, UINT32, max_channels, 15) X(a, STATIC, SINGULAR, UINT32, max_channels, 15)
@ -461,7 +464,7 @@ extern const pb_msgdesc_t ToRadio_msg;
#define Data_size 260 #define Data_size 260
#define MeshPacket_size 309 #define MeshPacket_size 309
#define NodeInfo_size 126 #define NodeInfo_size 126
#define MyNodeInfo_size 89 #define MyNodeInfo_size 95
#define LogRecord_size 81 #define LogRecord_size 81
#define FromRadio_size 318 #define FromRadio_size 318
#define ToRadio_size 312 #define ToRadio_size 312

Wyświetl plik

@ -1,5 +1,6 @@
#include "NodeDB.h" #include "NodeDB.h"
#include "PowerFSM.h" #include "PowerFSM.h"
#include "RadioLibInterface.h"
#include "airtime.h" #include "airtime.h"
#include "main.h" #include "main.h"
#include "mesh/http/ContentHelper.h" #include "mesh/http/ContentHelper.h"
@ -10,8 +11,8 @@
#include <HTTPBodyParser.hpp> #include <HTTPBodyParser.hpp>
#include <HTTPMultipartBodyParser.hpp> #include <HTTPMultipartBodyParser.hpp>
#include <HTTPURLEncodedBodyParser.hpp> #include <HTTPURLEncodedBodyParser.hpp>
#include <Preferences.h>
#include <SPIFFS.h> #include <SPIFFS.h>
#include "RadioLibInterface.h"
#ifndef NO_ESP32 #ifndef NO_ESP32
#include "esp_task_wdt.h" #include "esp_task_wdt.h"
@ -836,6 +837,11 @@ void handleReport(HTTPRequest *req, HTTPResponse *res)
ResourceParameters *params = req->getParams(); ResourceParameters *params = req->getParams();
std::string content; std::string content;
Preferences preferences;
preferences.begin("meshtastic", false);
uint32_t rebootCounter = preferences.getUInt("rebootCounter", 0);
if (!params->getQueryParameter("content", content)) { if (!params->getQueryParameter("content", content)) {
content = "json"; content = "json";
} }
@ -934,6 +940,10 @@ void handleReport(HTTPRequest *req, HTTPResponse *res)
res->printf("\"is_charging\": %s\n", BoolToString(powerStatus->getIsCharging())); res->printf("\"is_charging\": %s\n", BoolToString(powerStatus->getIsCharging()));
res->println("},"); res->println("},");
res->println("\"device\": {");
res->printf("\"reboot_counter\": %d\n", myNodeInfo.reboot_count);
res->println("},");
res->println("\"radio\": {"); res->println("\"radio\": {");
res->printf("\"frequecy\": %f,\n", RadioLibInterface::instance->getFreq()); res->printf("\"frequecy\": %f,\n", RadioLibInterface::instance->getFreq());
res->printf("\"lora_channel\": %d\n", RadioLibInterface::instance->getChannelNum()); res->printf("\"lora_channel\": %d\n", RadioLibInterface::instance->getChannelNum());
@ -941,8 +951,6 @@ void handleReport(HTTPRequest *req, HTTPResponse *res)
res->println("},"); res->println("},");
res->println("\"status\": \"ok\""); res->println("\"status\": \"ok\"");
res->println("}"); res->println("}");
} }