Reference

start

  • start()
  • start(HardwareSerial* serial)

Start obnizOS.

Arguments.

  • serial : Use this option to print out the log of obnizOS, you can set this option to NULL to disable logging. The default value is Serial.

Return value

There is a return value in int.

  • 0 : OK
  • -1 : id value error
  • -2 : Key value error
  • -3 : Certified error

end

  • end()

Terminate obnizOS. Disconnects from the network.

Arguments.

None

Return value

None

pinReserve

  • pinReserve(uint8_t pin)

Occupy IO without being controlled by obnizOS.

The following functions are used to automatically occupy IO

  • pinMode
  • wire.begin
  • analogRead

If it is not occupied, there is a possibility that plugins 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). There are.

Arguments.

  • Pin: Specify the actual IO to be used. 0-40 values are allowed.

Return value.

None

pinFree

  • pinFree(uint8_t pin)

Releases the right to use IO.

Arguments.

  • Pin: Specify the actual IO to be used. 0-40 values are allowed.

Return value.

None

commandSend

  • commandSend(uint8_t data, uint16_t length)

Sends data for the command.

Arguments.

  • data: array of data to be sent
  • length : length of data to be sent

Return value

None

commandReceive.

  • commandReceive(CallbackCommandFunction func)

Receive data from the command. Callback function is required.

Arguments.

  • func : Set a callback function.
    void func(uint8_t data, uint16\t length)

Return value

None

Sample Programs.

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

obniz.commandReceive(onCommand);

onEvent

  • onEvent(CallbackEventFunction func)

You can get the event when you are offline or online. Callback function is required.

Arguments.

  • func : Set a callback function.
    void func(os_event_t event, uint8_t* data, uint16_t length)

Return value

None

Types of Events.

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

Sample Programs.

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

getId

  • getId()

You can get an obnizID, you must have started obnizOS.
It returns NULL if executed immediately after start or when not running.

Arguments.

None

Return value

const char char* : obnizID is returned as a string.

getOsVersion.

  • getOsVersion()

You can get the version of obnizOS.

Arguments.

None

Return value

const char char* : The version of obnizOS is returned as a string.

isRunning

  • isRunning()

You can retrieve whether obnizOS is running or not.

Arguments.

None

Return value

bool: running when true.

isOnline.

  • isOnline()

You can retrieve whether it is online or not.

Arguments.

None

Return value

bool : true when online.