Skip to main content

Clients

In DeviceScript, all access to sensors, actuators or other hardware components are abstracted through services. Sensors act as servers and your scripts connects clients to interact with them. Servers are implemented by drivers, which may provide one or more services.

To interact with servers, you start clients, known as roles, for each service you need.

Let's illustrate these concept with a controller for a home heating system. The heating system has a relay to turn on/off the furnace, a temperature sensor and rotary encoder to change the desired temperature. Therefore, we declare 3 roles.

import { Temperature, Relay } from "@devicescript/core"

const thermometer = new Temperature()
const thermometer2 = new Temperature()
const relay = new Relay()

Onboard servers

You can also start servers for onboard sensors and actuators. For example, the startBME680 function maps a BME680 sensor to 4 roles: temperature, humidity, pressure and air quality index.

import { startBME680 } from "@devicescript/drivers"

// mount services on a BME680
const { temperature, humidity, pressure, airQualityIndex } = await startBME680()