Skip to content

Commit

Permalink
Fix #434: Implement Uptime
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Jul 24, 2023
1 parent ff55cf4 commit 9591e8d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -773,10 +773,14 @@ paths:
x-stoplight:
id: 7h1cpgfjj5j9j
format: date-time
uptime:
type: integer
description: EVSE gateway uptime, in seconds
required:
- time
- offset
- local_time
- uptime
operationId: get-time
description: Gets the time set on the OpenEVSE
post:
Expand Down
3 changes: 3 additions & 0 deletions models/Status.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,6 @@ properties:
limit_version:
type: integer
description: /limit endpoint current version
uptime:
type: integer
description: EVSE gateway uptime, in seconds
13 changes: 13 additions & 0 deletions src/time_man.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@ String time_format_time(tm &time)
return String(output);
}


// inspired from https://www.snad.cz/en/2018/12/21/uptime-and-esp8266/
// this works if this method is called at least once every 47 days, which is the case (each 8 hours at least based on TIME_POLL_TIME)
uint64_t millis64()
{
static uint32_t low32, high32;
uint32_t new_low32 = millis();
if (new_low32 < low32) high32++;
low32 = new_low32;
return (uint64_t) high32 << 32 | low32;
}

void TimeManager::serialise(JsonDocument &doc)
{
// get the current time
Expand All @@ -278,4 +290,5 @@ void TimeManager::serialise(JsonDocument &doc)
doc["time"] = time;
doc["local_time"] = local_time;
doc["offset"] = offset;
doc["uptime"] = millis64() / 1000;
}

0 comments on commit 9591e8d

Please sign in to comment.