Protected_HTTP method for this endpoint.
Protected_ProtectedlogRun one update, then (while the poll loop is active) schedule the next
tick after the current request settles. This serialises requests so a
slow update can't trigger overlapping in-flight fetches and skew
_consecutiveFails bookkeeping. Effective interval becomes
max(updateInterval, request_time).
Calling autoUpdate() directly also enters the poll loop; call
stop to leave it.
ProtectedrequestPerform the HTTP request configured for this service.
The HTTP method, Authorization header (when basicAuth is enabled),
and signal are always controlled by this method and cannot be
overridden via init: an explicit init.method is ignored, and a
caller-supplied init.signal is composed (via AbortSignal.any) with
the internal timeout signal rather than replacing it. An external abort
re-throws the original AbortError so callers can distinguish it from
a timeout.
Any other fetch init field (body, headers, cache, etc.) is
passed through to fetch; caller headers are merged on top of the
service's _requestHeaders.
Optional fetch init plus a params shortcut. params,
if provided, is serialised as key=value&key=value and appended to
the URL without URL-encoding — values must already be URL-safe
(numbers and ASCII letters are fine; spaces / special chars are not).
This matches the wire format the controller's legacy endpoints expect
(e.g. literal commas in ?MAN_DOSAGE=0,60).
The raw Response for the caller to parse.
BadCredentialsError on HTTP 401 or 403.
BadStatusCodeError on any other 4xx/5xx response.
RequestTimeoutError if the request exceeds the configured timeout.
Start the polling loop. Calls successCallback on every successful update
and errorCallback once the consecutive-failure tolerance is hit.
OptionalsuccessCallback: (data: GetStateData) => voidInvoked with the freshly parsed GetStateData after every successful poll.
OptionalerrorCallback: (e: Error) => voidInvoked with the most recent Error when the
errorTolerance is reached. The error is one of the typed classes
from 'procon-ip' (BadCredentialsError, BadStatusCodeError,
RequestTimeoutError) or a TypeError on network failure.
OptionalstopOnError: booleanWhen true, calling the error callback also stops
the polling loop. Default false (loop keeps running, callback fires
each time the tolerance is hit).
import { GetStateService, Logger } from 'procon-ip';
const svc = new GetStateService(
{ controllerUrl: 'http://192.168.2.3', basicAuth: false,
timeout: 5000, updateInterval: 5000, errorTolerance: 3 },
new Logger(),
);
svc.start(
(data) => console.log('uptime:', data.sysInfo.uptime),
(e) => console.error('poll failed:', e.message),
);
Endpoint path relative to IServiceConfig.controllerUrl.