Commands

Plug-in Commands

Data can be exchanged between obniz.js and devices by using commands between them.
This allows you to send sensor data and instruct plug-in from your browser.

Plug-in program.

You can program the plug-in with the following function

Device→JavaScript Send

obniz.commandSend(data,length);

Device←Receiving JavaScript

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

obniz.commandReceive(onCommand);

JavaScript programs.

The javascript program can be executed by the following function.

Device→Receive JavaScript

obniz.plugin.onreceive = data => {
  console.log(data);
};

Device←Send JavaScript

obniz.plugin.send("obniz.js send data get device?")