Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #434: Implement Uptime #700

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
mathieucarbou marked this conversation as resolved.
Show resolved Hide resolved
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;
}