Skip to content

Commit

Permalink
Merge pull request #700 from mathieucarbou/uptime
Browse files Browse the repository at this point in the history
Fix #434: Implement Uptime
  • Loading branch information
jeremypoulter authored Jul 27, 2023
2 parents ff55cf4 + 1b1687b commit 9aa835e
Show file tree
Hide file tree
Showing 5 changed files with 22 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
2 changes: 2 additions & 0 deletions src/emonesp.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,6 @@ extern String serial;

void restart_system();

uint64_t uptimeMillis();

#endif // _EMONESP_H
12 changes: 12 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ void
loop() {
Profile_Start(loop);

uptimeMillis();

Profile_Start(Mongoose);
Mongoose.poll(0);
Profile_End(Mongoose, 10);
Expand Down Expand Up @@ -340,3 +342,13 @@ void handle_serial()
}
}
}

// inspired from https://www.snad.cz/en/2018/12/21/uptime-and-esp8266/
uint64_t uptimeMillis()
{
static uint32_t low32, high32;
uint32_t new_low32 = millis();
if (new_low32 < low32) high32++;
low32 = new_low32;
return (uint64_t) high32 << 32 | low32;
}
1 change: 1 addition & 0 deletions src/time_man.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,5 @@ void TimeManager::serialise(JsonDocument &doc)
doc["time"] = time;
doc["local_time"] = local_time;
doc["offset"] = offset;
doc["uptime"] = uptimeMillis() / 1000;
}

0 comments on commit 9aa835e

Please sign in to comment.