Skip to content

Host Provider

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

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.

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

IO Bus type for I2C communication

IO Bus type for Serial communication

IO Bus type for SPI communication

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);

Object of IO Provider constructors available to the host environment.

Object of Sensor constructors available to the host environment.

Object of Display constructors available to the host environment.

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

Object of networking-related constructor options.

Object of default Domain Name Resolver constructor options.

Object of default Network Interface constructor options.

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

Object of default NTP Client constructor options.

Object of default HTTP Client constructor options.

Object of default HTTP Server constructor options.

Object of default MQTT Client constructor options.

Object of default secure MQTT Client constructor options.

Object of default TLS Client constructor options.

Object of default WebSocket Client constructor options.

Object of default secure WebSocket Client constructor options.

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);

Host Provider instance