Browse Source

Calculate and display load average.

pull/642/head
Lazar Obradovic 6 years ago
parent
commit
d2cd087321
5 changed files with 41 additions and 3 deletions
  1. +7
    -0
      code/espurna/config/general.h
  2. +27
    -3
      code/espurna/system.ino
  3. +3
    -0
      code/espurna/utils.ino
  4. +1
    -0
      code/espurna/ws.ino
  5. +3
    -0
      code/html/index.html

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

@ -168,6 +168,12 @@
#define HEARTBEAT_REPORT_VERSION 1
#define HEARTBEAT_REPORT_INTERVAL 0
//------------------------------------------------------------------------------
// Load average
//------------------------------------------------------------------------------
#define LOADAVG_INTERVAL 30000 // Interval between calculating load average (in ms)
#define LOADAVG_REPORT 1 // Should we report Load average over MQTT?
//------------------------------------------------------------------------------
// RESET
//------------------------------------------------------------------------------
@ -595,6 +601,7 @@ PROGMEM const char* const custom_reset_string[] = {
#define MQTT_TOPIC_RFRAW "rfraw"
#define MQTT_TOPIC_UARTIN "uartin"
#define MQTT_TOPIC_UARTOUT "uartout"
#define MQTT_TOPIC_LOADAVG "loadavg"
// Light module
#define MQTT_TOPIC_CHANNEL "channel"


+ 27
- 3
code/espurna/system.ino View File

@ -26,6 +26,9 @@ bool _system_send_heartbeat = false;
bool _systemStable = true;
// Calculated load average 0 to 100;
unsigned short int _load_average = 100;
void systemCheck(bool stable) {
unsigned char value = EEPROM.read(EEPROM_CRASH_COUNTER);
if (stable) {
@ -72,14 +75,31 @@ void systemLoop() {
#if HEARTBEAT_ENABLED
// Heartbeat
static unsigned long last = 0;
if (_system_send_heartbeat || (last == 0) || (millis() - last > HEARTBEAT_INTERVAL)) {
static unsigned long last_hbeat = 0;
if (_system_send_heartbeat || (last_hbeat == 0) || (millis() - last_hbeat > HEARTBEAT_INTERVAL)) {
_system_send_heartbeat = false;
last = millis();
last_hbeat = millis();
heartbeat();
}
#endif // HEARTBEAT_ENABLED
// Increase temporary loop counter
static unsigned long load_counter_temp = 0;
static unsigned long load_counter = 0;
static unsigned long load_counter_max = 1;
static unsigned long last_loadcheck = 0;
load_counter_temp++;
if (millis() - last_loadcheck > LOADAVG_INTERVAL) {
load_counter = load_counter_temp;
load_counter_temp = 0;
if (load_counter > load_counter_max) {
load_counter_max = load_counter;
}
_load_average = 100 - (100 * load_counter / load_counter_max);
last_loadcheck = millis();
}
// Power saving delay
delay(_loopDelay);
@ -120,3 +140,7 @@ void systemSetup() {
espurnaRegisterLoop(systemLoop);
}
unsigned long getLoadAverage() {
return _load_average;
}

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

@ -172,6 +172,9 @@ void heartbeat() {
#if (HEARTBEAT_REPORT_STATUS)
mqttSend(MQTT_TOPIC_STATUS, MQTT_STATUS_ONLINE, true);
#endif
#if (LOADAVG_REPORT)
mqttSend(MQTT_TOPIC_LOADAVG, String(getLoadAverage()).c_str());
#endif
}
#endif


+ 1
- 0
code/espurna/ws.ino View File

@ -220,6 +220,7 @@ void _wsUpdate(JsonObject& root) {
root["heap"] = getFreeHeap();
root["uptime"] = getUptime();
root["rssi"] = WiFi.RSSI();
root["loadaverage"] = getLoadAverage();
#if NTP_SUPPORT
if (ntpSynced()) root["now"] = now();
#endif


+ 3
- 0
code/html/index.html View File

@ -223,6 +223,9 @@
<div class="pure-u-1-2 pure-u-lg-1-4">Uptime</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="uptime"></span></div>
<div class="pure-u-1-2 pure-u-lg-1-4">Load average</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="loadaverage"></span>%</div>
<div class="pure-u-1-2 pure-u-lg-1-4">Free heap</div>
<div class="pure-u-11-24 pure-u-lg-17-24"><span class="right" name="heap" post=" bytes"></span></div>


Loading…
Cancel
Save