@ -7,6 +7,7 @@ Copyright (C) 2017-2019 by Xose Pérez <xose dot perez at gmail dot com>
*/
*/
# include <Ticker.h>
# include <Ticker.h>
# include "libs/HeapStats.h"
String getIdentifier ( ) {
String getIdentifier ( ) {
char buffer [ 20 ] ;
char buffer [ 20 ] ;
@ -63,26 +64,6 @@ unsigned char getHeartbeatInterval() {
return getSetting ( " hbInterval " , HEARTBEAT_INTERVAL ) . toInt ( ) ;
return getSetting ( " hbInterval " , HEARTBEAT_INTERVAL ) . toInt ( ) ;
}
}
// WTF
// Calling ESP.getFreeHeap() is making the system crash on a specific
// AiLight bulb, but anywhere else...
unsigned int getFreeHeap ( ) {
if ( getSetting ( " wtfHeap " , 0 ) . toInt ( ) = = 1 ) return 9999 ;
return ESP . getFreeHeap ( ) ;
}
unsigned int getInitialFreeHeap ( ) {
static unsigned int _heap = 0 ;
if ( 0 = = _heap ) {
_heap = getFreeHeap ( ) ;
}
return _heap ;
}
unsigned int getUsedHeap ( ) {
return getInitialFreeHeap ( ) - getFreeHeap ( ) ;
}
String getEspurnaModules ( ) {
String getEspurnaModules ( ) {
return FPSTR ( espurna_modules ) ;
return FPSTR ( espurna_modules ) ;
}
}
@ -186,10 +167,10 @@ namespace Heartbeat {
void heartbeat ( ) {
void heartbeat ( ) {
unsigned long uptime_seconds = getUptime ( ) ;
unsigned long uptime_seconds = getUptime ( ) ;
unsigned int free_heap = getFree Heap ( ) ;
heap_stats_t heap_stats = getHeapStats ( ) ;
UNUSED ( uptime_seconds ) ;
UNUSED ( uptime_seconds ) ;
UNUSED ( free_ heap) ;
UNUSED ( heap_stats ) ;
# if MQTT_SUPPORT
# if MQTT_SUPPORT
unsigned char _heartbeat_mode = getHeartbeatMode ( ) ;
unsigned char _heartbeat_mode = getHeartbeatMode ( ) ;
@ -204,7 +185,7 @@ void heartbeat() {
if ( serial ) {
if ( serial ) {
DEBUG_MSG_P ( PSTR ( " [MAIN] Uptime: %lu seconds \n " ) , uptime_seconds ) ;
DEBUG_MSG_P ( PSTR ( " [MAIN] Uptime: %lu seconds \n " ) , uptime_seconds ) ;
infoMemory ( " Heap " , getInitialFreeHeap ( ) , getFreeHeap ( ) ) ;
infoHeapStats ( ) ;
# if ADC_MODE_VALUE == ADC_VCC
# if ADC_MODE_VALUE == ADC_VCC
DEBUG_MSG_P ( PSTR ( " [MAIN] Power: %lu mV \n " ) , ESP . getVcc ( ) ) ;
DEBUG_MSG_P ( PSTR ( " [MAIN] Power: %lu mV \n " ) , ESP . getVcc ( ) ) ;
# endif
# endif
@ -264,7 +245,7 @@ void heartbeat() {
# endif
# endif
if ( hb_cfg & Heartbeat : : Freeheap )
if ( hb_cfg & Heartbeat : : Freeheap )
mqttSend ( MQTT_TOPIC_FREEHEAP , String ( free_heap ) . c_str ( ) ) ;
mqttSend ( MQTT_TOPIC_FREEHEAP , String ( heap_stats . available ) . c_str ( ) ) ;
if ( hb_cfg & Heartbeat : : Relay )
if ( hb_cfg & Heartbeat : : Relay )
relayMQTT ( ) ;
relayMQTT ( ) ;
@ -311,7 +292,7 @@ void heartbeat() {
idbSend ( MQTT_TOPIC_UPTIME , String ( uptime_seconds ) . c_str ( ) ) ;
idbSend ( MQTT_TOPIC_UPTIME , String ( uptime_seconds ) . c_str ( ) ) ;
if ( hb_cfg & Heartbeat : : Freeheap )
if ( hb_cfg & Heartbeat : : Freeheap )
idbSend ( MQTT_TOPIC_FREEHEAP , String ( free_heap ) . c_str ( ) ) ;
idbSend ( MQTT_TOPIC_FREEHEAP , String ( heap_stats . available ) . c_str ( ) ) ;
if ( hb_cfg & Heartbeat : : Rssi )
if ( hb_cfg & Heartbeat : : Rssi )
idbSend ( MQTT_TOPIC_RSSI , String ( WiFi . RSSI ( ) ) . c_str ( ) ) ;
idbSend ( MQTT_TOPIC_RSSI , String ( WiFi . RSSI ( ) ) . c_str ( ) ) ;
@ -455,11 +436,15 @@ void info() {
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
static bool show_frag_stats = false ;
infoMemory ( " EEPROM " , SPI_FLASH_SEC_SIZE , SPI_FLASH_SEC_SIZE - settingsSize ( ) ) ;
infoMemory ( " EEPROM " , SPI_FLASH_SEC_SIZE , SPI_FLASH_SEC_SIZE - settingsSize ( ) ) ;
infoMemory ( " Heap " , getInitialFreeHeap ( ) , getFreeHeap ( ) ) ;
infoMemory ( " Stack " , 4096 , getFreeStack ( ) ) ;
infoHeapStats ( show_frag_stats ) ;
infoMemory ( " Stack " , CONT_STACKSIZE , getFreeStack ( ) ) ;
DEBUG_MSG_P ( PSTR ( " \n " ) ) ;
DEBUG_MSG_P ( PSTR ( " \n " ) ) ;
show_frag_stats = true ;
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
DEBUG_MSG_P ( PSTR ( " [MAIN] Boot version: %d \n " ) , ESP . getBootVersion ( ) ) ;
DEBUG_MSG_P ( PSTR ( " [MAIN] Boot version: %d \n " ) , ESP . getBootVersion ( ) ) ;