OctoPrint Integration¶
This page explains how the plugin integrates with OctoPrint and how other plugins or scripts can consume its API and helpers.
Plugin registration¶
- The plugin registers an API endpoint under
/api/plugin/octoprint_uptime. - It exposes helper functions and formatting utilities in the
octoprint_uptimePython package which other plugins may import if installed in the same environment.
Consuming the API (frontend)¶
Use OctoPrint's JavaScript helper to query the plugin API:
OctoPrint.simpleApiGet("octoprint_uptime").done(function (data) {
// System uptime:
// data.seconds - raw system uptime in seconds
// data.uptime, data.uptime_dhm, data.uptime_dh, data.uptime_d - formatted variants
//
// OctoPrint process uptime:
// data.octoprint_seconds - raw OctoPrint uptime in seconds
// data.octoprint_uptime, data.octoprint_uptime_dhm, etc. - formatted variants
//
// Configuration & metadata:
// data.display_format - current display format preference
// data.poll_interval_seconds - recommended polling interval
});
data.seconds / data.uptime describe host system uptime, while
data.octoprint_seconds / data.octoprint_uptime describe the OctoPrint process uptime.
Successful API responses include the following fields:
seconds,uptime,uptime_dhm,uptime_dh,uptime_d: System uptime information in seconds and formatted variantsoctoprint_seconds,octoprint_uptime,octoprint_uptime_dhm,octoprint_uptime_dh,octoprint_uptime_d: OctoPrint process uptime informationdisplay_format: The currently configured display format preferencepoll_interval_seconds: Recommended polling interval for the client
Error responses (e.g., permission denied) include:
error: Error messageuptime_available: Booleanfalseindicating that uptime information could not be determined or returned
Consuming from Python (other plugins)¶
from octoprint_uptime import format_uptime
print(format_uptime(3600))
Permissions & security¶
- The plugin API follows OctoPrint's plugin API model; only authenticated requests with sufficient permissions can change settings.
- Read-only API access for uptime is allowed for authenticated UI sessions.