TimeseriesAggregator
This service is experimental and may change in the future.
Supports aggregating timeseries data (especially sensor readings) and sending them to a cloud/storage service. Used in DeviceScript.
Note that f64 values are not necessarily aligned.
import { TimeseriesAggregator } from "@devicescript/core"
const timeseriesAggregator = new TimeseriesAggregator()
Commands
clear
Remove all pending timeseries.
timeseriesAggregator.clear(): Promise<void>
update
Add a data point to a timeseries.
timeseriesAggregator.update(value: number, label: string): Promise<void>
setWindow
Set aggregation window.
Setting to 0 will restore default.
timeseriesAggregator.setWindow(duration: number, label: string): Promise<void>
setUpload
Set whether or not the timeseries will be uploaded to the cloud.
The stored reports are generated regardless.
timeseriesAggregator.setUpload(upload: boolean, label: string): Promise<void>
Registers
now
This can queried to establish local time on the device.
type:
Register<number>(packing formatu32)read only
import { TimeseriesAggregator } from "@devicescript/core"
const timeseriesAggregator = new TimeseriesAggregator()
// ...
const value = await timeseriesAggregator.now.read()
- track incoming values
import { TimeseriesAggregator } from "@devicescript/core"
const timeseriesAggregator = new TimeseriesAggregator()
// ...
timeseriesAggregator.now.subscribe(async (value) => {
...
})
write and read will block until a server is bound to the client.
fastStart
When true, the windows will be shorter after service reset and gradually extend to requested length.
This is ensure valid data is being streamed in program development.
type:
Register<boolean>(packing formatu8)read and write
import { TimeseriesAggregator } from "@devicescript/core"
const timeseriesAggregator = new TimeseriesAggregator()
// ...
const value = await timeseriesAggregator.fastStart.read()
await timeseriesAggregator.fastStart.write(value)
- track incoming values
import { TimeseriesAggregator } from "@devicescript/core"
const timeseriesAggregator = new TimeseriesAggregator()
// ...
timeseriesAggregator.fastStart.subscribe(async (value) => {
...
})
write and read will block until a server is bound to the client.
defaultWindow
Window for timeseries for which set_window was never called.
Note that windows returned initially may be shorter if fast_start is enabled.
type:
Register<number>(packing formatu32)read and write
import { TimeseriesAggregator } from "@devicescript/core"
const timeseriesAggregator = new TimeseriesAggregator()
// ...
const value = await timeseriesAggregator.defaultWindow.read()
await timeseriesAggregator.defaultWindow.write(value)
- track incoming values
import { TimeseriesAggregator } from "@devicescript/core"
const timeseriesAggregator = new TimeseriesAggregator()
// ...
timeseriesAggregator.defaultWindow.subscribe(async (value) => {
...
})
write and read will block until a server is bound to the client.
defaultUpload
Whether labelled timeseries for which set_upload was never called should be automatically uploaded.
type:
Register<boolean>(packing formatu8)read and write
import { TimeseriesAggregator } from "@devicescript/core"
const timeseriesAggregator = new TimeseriesAggregator()
// ...
const value = await timeseriesAggregator.defaultUpload.read()
await timeseriesAggregator.defaultUpload.write(value)
- track incoming values
import { TimeseriesAggregator } from "@devicescript/core"
const timeseriesAggregator = new TimeseriesAggregator()
// ...
timeseriesAggregator.defaultUpload.subscribe(async (value) => {
...
})
write and read will block until a server is bound to the client.
uploadUnlabelled
Whether automatically created timeseries not bound in role manager should be uploaded.
type:
Register<boolean>(packing formatu8)read and write
import { TimeseriesAggregator } from "@devicescript/core"
const timeseriesAggregator = new TimeseriesAggregator()
// ...
const value = await timeseriesAggregator.uploadUnlabelled.read()
await timeseriesAggregator.uploadUnlabelled.write(value)
- track incoming values
import { TimeseriesAggregator } from "@devicescript/core"
const timeseriesAggregator = new TimeseriesAggregator()
// ...
timeseriesAggregator.uploadUnlabelled.subscribe(async (value) => {
...
})
write and read will block until a server is bound to the client.
sensorWatchdogPeriod
If no data is received from any sensor within given period, the device is rebooted.
Set to 0 to disable (default).
Updating user-provided timeseries does not reset the watchdog.
type:
Register<number>(packing formatu32)read and write
import { TimeseriesAggregator } from "@devicescript/core"
const timeseriesAggregator = new TimeseriesAggregator()
// ...
const value = await timeseriesAggregator.sensorWatchdogPeriod.read()
await timeseriesAggregator.sensorWatchdogPeriod.write(value)
- track incoming values
import { TimeseriesAggregator } from "@devicescript/core"
const timeseriesAggregator = new TimeseriesAggregator()
// ...
timeseriesAggregator.sensorWatchdogPeriod.subscribe(async (value) => {
...
})
write and read will block until a server is bound to the client.