Skip to content

Host Provider

The Host Provider instance aggregates data and code available to scripts from the host.

Access

The Host Provider instance is a singleton object that is created before hosted scripts are executed.

It may be imported:

import device from "embedded:provider/builtin"

Or be made available as a global object named device, if the host chooses to do so.

Instance Properties

pin

An object that maps pin names to pin specifiers. More than one pin name may map to the same pin specifier.

console.log(device.pin.led); // logs the value for the on-board LED pin
console.log(device.pin.button); // logs the value for the on-board button pin

i2c

IO Bus type for I2C communication

serial

IO Bus type for Serial communication

spi

IO Bus type for SPI communication

io

Object of IO constructors available to the host environment, such as Digital, I2C, and SPI.

console.log(device.io.Digital);
console.log(device.io.I2C);
console.log(device.io.SPI);

provider

Object of IO Provider constructors available to the host environment.

sensors

Object of Sensor constructors available to the host environment.

displays

Object of Display constructors available to the host environment.

rtc

Object of default Real-time clock constructor options available to the host environment.

network

Object of networking-related constructor options.

network.dns.resolver

Object of default Domain Name Resolver constructor options.

network.interface

Object of default Network Interface constructor options.

console.log(device.network.interface.Ethernet0);

network.ntp.client

Object of default NTP Client constructor options.

network.http.client

Object of default HTTP Client constructor options.

network.http.server

Object of default HTTP Server constructor options.

network.mqtt.client

Object of default MQTT Client constructor options.

network.mqtts.client

Object of default secure MQTT Client constructor options.

network.tls.client

Object of default TLS Client constructor options.

network.ws.client

Object of default WebSocket Client constructor options.

network.wss.client

Object of default secure WebSocket Client constructor options.

Examples

The following code is an example of establishing a SPI instance using the properties off the device Host Provider:

let spi = new device.io.SPI(device.spi.default);

Specifications

Host Provider instance