Instantiate an obniz device with obniz id. Connection will be established automatically. onconnect will be called whenc success. onclose will be called when disconnected from a device.
Operations like turning on/off an io becomes possible only after connection is established, so any operations you want device to undertake must be written in onconnect
Operations written in onclose function never delivered to a device because connection is already lost. So you can't turn off a moving motor when disconnected. See more at Disconnection
You can configure settings at initialization
For example, specify access token when you configured on obniz Cloud device console.
If obniz id is incorrect, connection will never be established. In nodejs, an error occurs.
In HTML, obniz.js shows a prompt message. The user can put in a correct obniz id into it.
It shows up only when the format is invalid. If you specify obniz id which doesn't exist, this would never be shown.
Current connection state can be read from connectionState
We recommend you to use pre configured device classes.
obniz.js will get device information like how many io it has when first connection established.
obniz Board and M5StickC and other official devices are pre configured in obniz.js. You can find from here.
And below is M5StickC pre configured class reference.
You can instantiate it like below method. Params are same as "new Obinz()"
By using it, peripherals and internal sensors are pre configured.