Host Provider
The Host Provider instance aggregates data and code available to scripts from the host.
Access
Section titled “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
Section titled “Instance Properties”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 pinconsole.log(device.pin.button); // logs the value for the on-board button pinIO Bus type for I2C communication
serial
Section titled “serial”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);provider
Section titled “provider”Object of IO Provider constructors available to the host environment.
sensors
Section titled “sensors”Object of Sensor constructors available to the host environment.
displays
Section titled “displays”Object of Display constructors available to the host environment.
Object of default Real-time clock constructor options available to the host environment.
network
Section titled “network”Object of networking-related constructor options.
network.dns.resolver
Section titled “network.dns.resolver”Object of default Domain Name Resolver constructor options.
network.interface
Section titled “network.interface”Object of default Network Interface constructor options.
console.log(device.network.interface.Ethernet0);network.ntp.client
Section titled “network.ntp.client”Object of default NTP Client constructor options.
network.http.client
Section titled “network.http.client”Object of default HTTP Client constructor options.
network.http.server
Section titled “network.http.server”Object of default HTTP Server constructor options.
network.mqtt.client
Section titled “network.mqtt.client”Object of default MQTT Client constructor options.
network.mqtts.client
Section titled “network.mqtts.client”Object of default secure MQTT Client constructor options.
network.tls.client
Section titled “network.tls.client”Object of default TLS Client constructor options.
network.ws.client
Section titled “network.ws.client”Object of default WebSocket Client constructor options.
network.wss.client
Section titled “network.wss.client”Object of default secure WebSocket Client constructor options.
Examples
Section titled “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);