Setup

Setup.

Install the plug-in to the Arduino IDE.
Please install the Arduino IDE beforehand.
This section is written in Windows environment, but there are similar settings for Mac as well.

After installing the Arduino IDE, launch it.
Open "File" -> "Preferences".

The Preferences dialog will appear.
Look for "Additional Board Manager URL" at the bottom of the dialog.

Insert the following URL into the "Additional Board Manager URL" field.

https://obniz.github.io/obniz-plugin-arduino/package_obniz_index.json

When you are done with the settings, click "OK" to close and save the settings.
Next, open "Tools" -> "Board" -> "Board Manager".

When you open the [Board Manager], the process will run and there will be a waiting time.
After a while, it will calm down and you can type "obniz" in the search field.
You can see the button "Install" in the next picture.

Once you have installed the device as shown in the image above, you can see multiple devices such as "ESP32 Dev Module" as obniz plug-in in the "Tools" > "Board" option.

If you are using DevKitC, choose "ESP32 Dev Module" to proceed with your development.

Setup is now complete.

Writing with the Arduino IDE

When you write the program, you need to select the appropriate serial port.
Select "Tools" -> "Serial Port" -> "Appropriate Port".

After you choose, you can write your program by clicking "→" button of Arduino IDE.

What can I do with the obnizOS plug-in?

You can check a sample program from Arduino IDE.
Click "File" -> "Sketch Examples" -> "Obniz" to see several sample programs.

You can start using them from there.

Start obnizOS.

obniz.start();

Start obnizOS.

Exit obnizOS.

obniz.end();

Exit obnizOS.

Get the version of obnizOS.

obniz.getOsVersion();

You can get the version of obnizOS.

Obtain obnizID.

obniz.getId();

You can get an obniz ID.

Send and receive plug-in commands.

Sending the command

obniz.commandSend(data,length);

Receiving Commands

void onCommand(uint8_t* data, uint16_t length){
  Serial.println("\nonCommand");
  Serial.write(data,length);
  Serial.println("\nEnd onCommand");
}

obniz.commandReceive(onCommand);

You can exchange data between obniz.js and the device by using commands.

Occupy and free IOs.

Allows you to occupy IO privileges without being controlled by obnizOS, and can be intentionally released. You can also release it intentionally.

The following functions occupy IO automatically.

  • pinMode
  • wire.begin
  • analogRead

If it is not occupied, there is a possibility that plug-in can't control the system by resetting IO when obnizOS starts up or when disconnecting from the server (if you want to disable resetting on disconnect, you need to set reset_obniz_on_ws_disconnection: false). Yes, there is.

Occupancy.

obniz.pinReserve(io)

liberation

obniz.pinFree(io)

obnizOS Events

You can get events when you are offline or online.

Network events

  • Network connection PLUGIN_EVENT_NETWORK_HARDWARE_CONNECTED
  • obniz cloud connection PLUGIN_EVENT_NETWORK_CLOUD_CONNECTED
  • Network Disconnect PLUGIN_EVENT_NETWORK_HARDWARE_DISCONNECTED
  • obniz cloud disconnected PLUGIN_EVENT_NETWORK_CLOUD_DISCONNECTED
  • WiFi scanning PLUGIN_EVENT_NETWORK_WIFI_SCANNING
  • WiFi not found PLUGIN_EVENT_NETWORK_WIFI_NOTFOUND
  • WiFi connection PLUGIN_EVENT_NETWORK_WIFI_CONNECTING
  • WiFi access point mode connection event PLUGIN_EVENT_NETWORK_WIFI_SOFTAP_CONNECTED
  • WiFi error PLUGIN_EVENT_NETWORK_WIFI_FAIL

Other

  • Other errors PLUGIN_EVENT_FAIL
  • Start OTA PLUGIN_EVENT_OTA_START
  • OTA ends PLUGIN_EVENT_OTA_END
  • OTA error PLUGIN_EVENT_OTA_ERROR
void onEvent(os_event_t event, uint8_t* data, uint16_t length) {
  switch (event) {
  case PLUGIN_EVENT_NETWORK_HARDWARE_CONNECTED:
  case PLUGIN_EVENT_NETWORK_CLOUD_CONNECTED:
  case PLUGIN_EVENT_NETWORK_HARDWARE_DISCONNECTED: case PLUGIN_EVENT_NETWORK_CLOUD_CONNECTED: case PLUGIN_EVENT_NETWORK_DISCONNECTED:
  case PLUGIN_EVENT_NETWORK_CLOUD_DISCONNECTED: case PLUGIN_EVENT_NETWORK_DISCONNECTED: case PLUGIN_EVENT_NETWORK_DISCONNECTED:
  case PLUGIN_EVENT_NETWORK_WIFI_SCANNING:
  case PLUGIN_EVENT_NETWORK_WIFI_NOTFOUND: case PLUGIN_EVENT_NETWORK_CLOUD_SCANNING: case PLUGIN_EVENT_NETWORK_SCANNING: case PLUGIN_EVENT_NETWORK_CLOUD_SCANNING:
  case PLUGIN_EVENT_NETWORK_WIFI_CONNECTING:
  case PLUGIN_EVENT_NETWORK_WIFI_SOFTAP_CONNECTED: case PLUGIN_EVENT_NETWORK_WIFI_CONNECTING: case PLUGIN_EVENT_NETWORK_CONNECTING: case PLUGIN_EVENT_NETWORK_NOTFOUND: case PLUGIN_EVENT_NETWORK_SOFTAP_CONNECTED:
  case PLUGIN_EVENT_NETWORK_WIFI_FAIL:
  case PLUGIN_EVENT_EVENT_FAIL:
  case PLUGIN_EVENT_OTA_FAIL: case PLUGIN_EVENT_EVENT_OTA_FAIL: case PLUGIN_EVENT_EVENT_FAIL:
  case PLUGIN_EVENT_OTA_END:
  case PLUGIN_EVENT_OTA_ERROR:
    break;
  }
}

obniz.onEvent(onEvent);

Status Check.

Running whether or not obnizOS is running.

obniz.isRunning()

Online status or not Online when true

obniz.isOnline()