Added new homeSpan.rebootCallback() function
An optional callback used to track the number of times the device reboots, where a reboot is defined as any restart where the uptime was less than a specified number of milliseconds (default=5000)
This commit is contained in:
parent
965bdc71b7
commit
713c5c65bf
|
|
@ -79,6 +79,11 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa
|
||||||
nvs_open("WIFI",NVS_READWRITE,&wifiNVS); // open WIFI data namespace in NVS
|
nvs_open("WIFI",NVS_READWRITE,&wifiNVS); // open WIFI data namespace in NVS
|
||||||
nvs_open("OTA",NVS_READWRITE,&otaNVS); // open OTA data namespace in NVS
|
nvs_open("OTA",NVS_READWRITE,&otaNVS); // open OTA data namespace in NVS
|
||||||
|
|
||||||
|
nvs_get_u8(wifiNVS,"REBOOTS",&rebootCount);
|
||||||
|
rebootCount++;
|
||||||
|
nvs_set_u8(wifiNVS,"REBOOTS",rebootCount);
|
||||||
|
nvs_commit(wifiNVS);
|
||||||
|
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if(strlen(network.wifiData.ssid)){ // if setWifiCredentials was already called
|
if(strlen(network.wifiData.ssid)){ // if setWifiCredentials was already called
|
||||||
|
|
@ -304,6 +309,14 @@ void Span::pollTask() {
|
||||||
}
|
}
|
||||||
|
|
||||||
statusLED->check();
|
statusLED->check();
|
||||||
|
|
||||||
|
if(rebootCallback && snapTime>rebootCallbackTime){
|
||||||
|
rebootCallback(rebootCount-1);
|
||||||
|
rebootCount=0;
|
||||||
|
rebootCallback=NULL;
|
||||||
|
nvs_set_u8(wifiNVS,"REBOOTS",rebootCount);
|
||||||
|
nvs_commit(wifiNVS);
|
||||||
|
}
|
||||||
|
|
||||||
} // poll
|
} // poll
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -213,11 +213,13 @@ class Span{
|
||||||
const char *sketchVersion="n/a"; // version of the sketch
|
const char *sketchVersion="n/a"; // version of the sketch
|
||||||
nvs_handle charNVS; // handle for non-volatile-storage of Characteristics data
|
nvs_handle charNVS; // handle for non-volatile-storage of Characteristics data
|
||||||
nvs_handle wifiNVS=0; // handle for non-volatile-storage of WiFi data
|
nvs_handle wifiNVS=0; // handle for non-volatile-storage of WiFi data
|
||||||
nvs_handle otaNVS; // handle for non-volatile storaget of OTA data
|
nvs_handle otaNVS; // handle for non-volatile storage of OTA data
|
||||||
char pairingCodeCommand[12]=""; // user-specified Pairing Code - only needed if Pairing Setup Code is specified in sketch using setPairingCode()
|
char pairingCodeCommand[12]=""; // user-specified Pairing Code - only needed if Pairing Setup Code is specified in sketch using setPairingCode()
|
||||||
String lastClientIP="0.0.0.0"; // IP address of last client accessing device through encrypted channel
|
String lastClientIP="0.0.0.0"; // IP address of last client accessing device through encrypted channel
|
||||||
boolean newCode; // flag indicating new application code has been loaded (based on keeping track of app SHA256)
|
boolean newCode; // flag indicating new application code has been loaded (based on keeping track of app SHA256)
|
||||||
boolean serialInputDisabled=false; // flag indiating that serial input is disabled
|
boolean serialInputDisabled=false; // flag indiating that serial input is disabled
|
||||||
|
uint8_t rebootCount=0; // counts number of times device was rebooted (used in optional Reboot callback)
|
||||||
|
uint32_t rebootCallbackTime; // length of time to wait (in milliseconds) before calling optional Reboot callback
|
||||||
|
|
||||||
int connected=0; // WiFi connection status (increments upon each connect and disconnect)
|
int connected=0; // WiFi connection status (increments upon each connect and disconnect)
|
||||||
unsigned long waitTime=60000; // time to wait (in milliseconds) between WiFi connection attempts
|
unsigned long waitTime=60000; // time to wait (in milliseconds) between WiFi connection attempts
|
||||||
|
|
@ -238,6 +240,7 @@ class Span{
|
||||||
boolean autoStartAPEnabled=false; // enables auto start-up of Access Point when WiFi Credentials not found
|
boolean autoStartAPEnabled=false; // enables auto start-up of Access Point when WiFi Credentials not found
|
||||||
void (*apFunction)()=NULL; // optional function to invoke when starting Access Point
|
void (*apFunction)()=NULL; // optional function to invoke when starting Access Point
|
||||||
void (*statusCallback)(HS_STATUS status)=NULL; // optional callback when HomeSpan status changes
|
void (*statusCallback)(HS_STATUS status)=NULL; // optional callback when HomeSpan status changes
|
||||||
|
void (*rebootCallback)(uint8_t)=NULL; // optional callback when device reboots
|
||||||
|
|
||||||
WiFiServer *hapServer; // pointer to the HAP Server connection
|
WiFiServer *hapServer; // pointer to the HAP Server connection
|
||||||
Blinker *statusLED; // indicates HomeSpan status
|
Blinker *statusLED; // indicates HomeSpan status
|
||||||
|
|
@ -355,6 +358,8 @@ class Span{
|
||||||
|
|
||||||
Span& setVerboseWifiReconnect(bool verbose=true){verboseWifiReconnect=verbose;return(*this);}
|
Span& setVerboseWifiReconnect(bool verbose=true){verboseWifiReconnect=verbose;return(*this);}
|
||||||
|
|
||||||
|
Span& setRebootCallback(void (*f)(uint8_t),uint32_t t=DEFAULT_REBOOT_CALLBACK_TIME){rebootCallback=f;rebootCallbackTime=t;return(*this);}
|
||||||
|
|
||||||
void autoPoll(uint32_t stackSize=8192, uint32_t priority=1, uint32_t cpu=0){ // start pollTask()
|
void autoPoll(uint32_t stackSize=8192, uint32_t priority=1, uint32_t cpu=0){ // start pollTask()
|
||||||
xTaskCreateUniversal([](void *parms){
|
xTaskCreateUniversal([](void *parms){
|
||||||
for(;;){
|
for(;;){
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,9 @@
|
||||||
|
|
||||||
#define DEFAULT_WEBLOG_URL "status" // change with optional fourth argument in homeSpan.enableWebLog()
|
#define DEFAULT_WEBLOG_URL "status" // change with optional fourth argument in homeSpan.enableWebLog()
|
||||||
|
|
||||||
#define DEFAULT_LOW_MEM_THRESHOLD 80000 // default low watermark memory threshold that triggers warning
|
#define DEFAULT_LOW_MEM_THRESHOLD 80000 // default low watermark memory threshold that triggers warning
|
||||||
|
|
||||||
|
#define DEFAULT_REBOOT_CALLBACK_TIME 5000 // default time (in milliseconds) to check for reboot callback
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
// OTA PARTITION INFO //
|
// OTA PARTITION INFO //
|
||||||
|
|
|
||||||
12
src/src.ino
12
src/src.ino
|
|
@ -74,7 +74,7 @@ void setup() {
|
||||||
// homeSpan.enableOTA();
|
// homeSpan.enableOTA();
|
||||||
|
|
||||||
homeSpan.setWifiCallback(wifiCB);
|
homeSpan.setWifiCallback(wifiCB);
|
||||||
homeSpan.setWifiCallbackAll(wifiCB_ALL).setVerboseWifiReconnect(true);
|
homeSpan.setWifiCallbackAll(wifiCB_ALL).setVerboseWifiReconnect(true).setRebootCallback(rebootCB,10000);
|
||||||
|
|
||||||
|
|
||||||
new SpanUserCommand('D', " - disconnect WiFi", [](const char *buf){WiFi.disconnect();});
|
new SpanUserCommand('D', " - disconnect WiFi", [](const char *buf){WiFi.disconnect();});
|
||||||
|
|
@ -88,8 +88,8 @@ void setup() {
|
||||||
|
|
||||||
// homeSpan.autoPoll();
|
// homeSpan.autoPoll();
|
||||||
|
|
||||||
for(int i=0;i<300;i++)
|
// for(int i=0;i<300;i++)
|
||||||
WEBLOG("Here is some text of a log file %d",i);
|
// WEBLOG("Here is some text of a log file %d",i);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,3 +113,9 @@ void wifiCB(){
|
||||||
void wifiCB_ALL(int n){
|
void wifiCB_ALL(int n){
|
||||||
Serial.printf("\n\n****** IN WIFI CALLBACK ALL. Count=%d *******\n\n",n);
|
Serial.printf("\n\n****** IN WIFI CALLBACK ALL. Count=%d *******\n\n",n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////
|
||||||
|
|
||||||
|
void rebootCB(uint8_t count){
|
||||||
|
Serial.printf("\n\n******* IN REBOOT CALLBACK: %d\n\n",count);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue