Methods
| Method | API call | Returns |
|---|---|---|
publish(station) | PUT /api/v1/station | { state } |
updatePoints(points) | PATCH /api/v1/station/points | { state } |
heartbeat() | POST /api/v1/station/heartbeat | nothing |
get() | GET /api/v1/station | stored data + state |
startHeartbeat(options?) | heartbeat() every intervalMs (default 5 minutes) | a stop function |
metrics() | none | the station's Prometheus text exposition |
publish replaces everything goodcharge knows about the station. updatePoints changes only the listed points; a point's position is its index in charging_points plus one.
startHeartbeat never throws once started, and never rejects: a failed beat is reported to onError (if given) instead, and a throwing onError is itself ignored, so a broken handler can't crash your process. An out-of-range intervalMs still throws invalid_option synchronously when you call startHeartbeat, before the first beat is scheduled. Call the returned function to stop.
Metrics helpers
Exported from @goodcharge/sdk:
| Function | Returns |
|---|---|
metricsText(stations) | the text exposition for several stations |
metricsHandler(stations) | a (req, res) handler for Node.js http and Express; the list is fixed when you create it |
metricsResponse(stations) | a Response, for fetch-style frameworks |
Also exported from @goodcharge/sdk:
METRICS_CONTENT_TYPE: the content type both helpers send,text/plain; version=0.0.4; charset=utf-8, for when you servemetricsTextyourself.MetricsResponseLike(type): the part of a Node.jsServerResponseor ExpressresthatmetricsHandlerwrites to:statusCode,setHeader(name, value)andend(body).
Exported from @goodcharge/sdk/prom-client: registerGoodchargeMetrics(registry, stations).