Skip to main content

SensorAggregator

caution

This service is experimental and may change in the future.

Aggregate data from multiple sensors into a single stream (often used as input to machine learning models on the same device, see model runner service).

import { SensorAggregator } from "@devicescript/core"

const sensorAggregator = new SensorAggregator()

Registers

inputs

Set automatic input collection. These settings are stored in flash.

  • type: Register<any[]> (packing format u16 u16 u32 r: b[8] u32 u8 u8 u8 i8)

  • track incoming values

import { SensorAggregator } from "@devicescript/core"

const sensorAggregator = new SensorAggregator()
// ...
sensorAggregator.inputs.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

numSamples

Number of input samples collected so far.

  • type: Register<number> (packing format u32)

  • read only

import { SensorAggregator } from "@devicescript/core"

const sensorAggregator = new SensorAggregator()
// ...
const value = await sensorAggregator.numSamples.read()
  • track incoming values
import { SensorAggregator } from "@devicescript/core"

const sensorAggregator = new SensorAggregator()
// ...
sensorAggregator.numSamples.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

sampleSize

Size of a single sample.

  • type: Register<number> (packing format u8)

  • read only

import { SensorAggregator } from "@devicescript/core"

const sensorAggregator = new SensorAggregator()
// ...
const value = await sensorAggregator.sampleSize.read()
  • track incoming values
import { SensorAggregator } from "@devicescript/core"

const sensorAggregator = new SensorAggregator()
// ...
sensorAggregator.sampleSize.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

streamingSamples

When set to N, will stream N samples as current_sample reading.

  • type: Register<number> (packing format u32)

  • read and write

import { SensorAggregator } from "@devicescript/core"

const sensorAggregator = new SensorAggregator()
// ...
const value = await sensorAggregator.streamingSamples.read()
await sensorAggregator.streamingSamples.write(value)
  • track incoming values
import { SensorAggregator } from "@devicescript/core"

const sensorAggregator = new SensorAggregator()
// ...
sensorAggregator.streamingSamples.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

reading

Last collected sample.

  • type: Register<Buffer> (packing format b)

  • track incoming values

import { SensorAggregator } from "@devicescript/core"

const sensorAggregator = new SensorAggregator()
// ...
sensorAggregator.reading.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.