Browse Source

Option to disable heartbeat. Added 3rd party hooks

i18n
Xose Pérez 6 years ago
parent
commit
6497238f4b
4 changed files with 28 additions and 6 deletions
  1. +4
    -0
      code/espurna/config/general.h
  2. +17
    -5
      code/espurna/espurna.ino
  3. +3
    -1
      code/espurna/mqtt.ino
  4. +4
    -0
      code/espurna/utils.ino

+ 4
- 0
code/espurna/config/general.h View File

@ -150,6 +150,10 @@
// HEARTBEAT // HEARTBEAT
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#ifndef HEARTBEAT_ENABLED
#define HEARTBEAT_ENABLED 1
#endif
#define HEARTBEAT_INTERVAL 300000 // Interval between heartbeat messages (in ms) #define HEARTBEAT_INTERVAL 300000 // Interval between heartbeat messages (in ms)
#define UPTIME_OVERFLOW 4294967295 // Uptime overflow value #define UPTIME_OVERFLOW 4294967295 // Uptime overflow value


+ 17
- 5
code/espurna/espurna.ino View File

@ -56,11 +56,13 @@ void hardwareSetup() {
void hardwareLoop() { void hardwareLoop() {
// Heartbeat // Heartbeat
static unsigned long last = 0;
if ((last == 0) || (millis() - last > HEARTBEAT_INTERVAL)) {
last = millis();
heartbeat();
}
#if HEARTBEAT_ENABLED
static unsigned long last = 0;
if ((last == 0) || (millis() - last > HEARTBEAT_INTERVAL)) {
last = millis();
heartbeat();
}
#endif // HEARTBEAT_ENABLED
} }
@ -177,6 +179,11 @@ void setup() {
schSetup(); schSetup();
#endif #endif
// 3rd party code hook
#if USE_EXTRA
extraSetup();
#endif
// Prepare configuration for version 2.0 // Prepare configuration for version 2.0
migrate(); migrate();
@ -241,6 +248,11 @@ void loop() {
mdnsClientLoop(); mdnsClientLoop();
#endif #endif
// 3rd party code hook
#if USE_EXTRA
extraLoop();
#endif
// Power saving delay // Power saving delay
delay(_loopDelay); delay(_loopDelay);


+ 3
- 1
code/espurna/mqtt.ino View File

@ -346,7 +346,9 @@ void _mqttCallback(unsigned int type, const char * topic, const char * payload)
mqttSubscribe(MQTT_TOPIC_ACTION); mqttSubscribe(MQTT_TOPIC_ACTION);
// Send heartbeat messages // Send heartbeat messages
heartbeat();
#if HEARTBEAT_ENABLED
heartbeat();
#endif
} }


+ 4
- 0
code/espurna/utils.ino View File

@ -94,6 +94,8 @@ unsigned long getUptime() {
} }
#if HEARTBEAT_ENABLED
void heartbeat() { void heartbeat() {
unsigned long uptime_seconds = getUptime(); unsigned long uptime_seconds = getUptime();
@ -201,6 +203,8 @@ void heartbeat() {
} }
#endif /// HEARTBEAT_ENABLED
unsigned int sectors(size_t size) { unsigned int sectors(size_t size) {
return (int) (size + SPI_FLASH_SEC_SIZE - 1) / SPI_FLASH_SEC_SIZE; return (int) (size + SPI_FLASH_SEC_SIZE - 1) / SPI_FLASH_SEC_SIZE;
} }


Loading…
Cancel
Save