mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-17 17:03:12 +00:00
Fixed uptime rollover in UI
This commit is contained in:
parent
9b70802450
commit
c07c2e66d6
8
src/Uptime.cpp
Normal file
8
src/Uptime.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include "Uptime.h"
|
||||
|
||||
uint64_t millis64() {
|
||||
uint32_t new_low32 = millis();
|
||||
if (new_low32 < _uptime_last_value) _uptime_rollovers++;
|
||||
_uptime_last_value = new_low32;
|
||||
return (uint64_t) _uptime_rollovers << 32 | _uptime_last_value;
|
||||
}
|
||||
10
src/Uptime.h
Normal file
10
src/Uptime.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef _UPTIME_H
|
||||
#define _UPTIME_H
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
static uint32_t _uptime_last_value = 0;
|
||||
static uint32_t _uptime_rollovers = 0;
|
||||
uint64_t millis64();
|
||||
|
||||
#endif
|
||||
@ -37,6 +37,8 @@ void AmsWebServer::loop() {
|
||||
|
||||
|
||||
void AmsWebServer::setData(AmsData& data) {
|
||||
millis64(); // Make sure it catch all those rollovers
|
||||
|
||||
this->data.apply(data);
|
||||
|
||||
if(maxPwr == 0 && data.getListType() > 1 && config->hasConfig() && config->getMainFuse() > 0 && config->getDistributionSystem() > 0) {
|
||||
@ -351,11 +353,10 @@ void AmsWebServer::dataJson() {
|
||||
json["po_pct"] = -1;
|
||||
}
|
||||
|
||||
unsigned long now = millis();
|
||||
json["id"] = WiFi.macAddress();
|
||||
json["maxPower"] = maxPwr;
|
||||
json["meterType"] = config->getMeterType();
|
||||
json["currentMillis"] = now;
|
||||
json["uptime_seconds"] = millis64() / 1000;
|
||||
double vcc = hw.getVcc();
|
||||
json["vcc"] = serialized(String(vcc, 3));
|
||||
|
||||
@ -383,6 +384,7 @@ void AmsWebServer::dataJson() {
|
||||
}
|
||||
json["status"]["esp"] = espStatus;
|
||||
|
||||
unsigned long now = millis();
|
||||
String hanStatus;
|
||||
if(config->getMeterType() == 0) {
|
||||
hanStatus = "secondary";
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#include "AmsConfiguration.h"
|
||||
#include "HwTools.h"
|
||||
#include "AmsData.h"
|
||||
#include "Uptime.h"
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
@ -33,7 +34,7 @@ public:
|
||||
void setData(AmsData& data);
|
||||
|
||||
private:
|
||||
int maxPwr;
|
||||
int maxPwr = 0;
|
||||
HwTools hw;
|
||||
AmsConfiguration* config;
|
||||
AmsData data;
|
||||
|
||||
@ -241,7 +241,7 @@ var fetch = function() {
|
||||
}
|
||||
|
||||
if(window.moment) {
|
||||
$('#currentMillis').html(moment.duration(parseInt(json.currentMillis)).humanize());
|
||||
$('#currentMillis').html(moment.duration(parseInt(json.uptime_seconds), 'seconds').humanize());
|
||||
$('#currentMillis').closest('.row').show();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user