App

You can create your own app with certain features like a smartphone app and install it in the cloud.

The installation is done to the device. (The program is not transferred to the device).
The installed app will run in your browser or on the obniz cloud or on a separate server to enable IoT on the installed device.

If you are an obniz developer, you can create an app and offer it to yourself or others.

Unlike simple HTML or nodejs software, obniz allows you to develop device-independent software that can be easily distributed to multiple devices and people.

Types of Apps.

There are two main types of apps.

.
Browser App A browser application is an application created with HTML/JavaScript or a block program. As the name implies, it runs in the browser and can be remotely operated and graphed in real time. In addition, by setting up the "Cloud Execution" function, you can run the application in the obniz cloud as well as in your browser.
Hosted App This is used when using obniz devices on a service hosted on another server other than obniz. It allows you to retrieve information of installed devices and manage the devices and accounts of authorized users through OAuth.

Browser App.

A browser app is one with programs and settings that can be installed on your device.

By running the installed app.

  • The information of the installed devices is captured and executed by the program
  • The settings you made during installation are incorporated into the program.

Both HTML and block programs are described in a device-independent way in the program (do not include the obnizID directly).

// Example.

var obniz = new Obniz("OBNIZ_ID_HERE");

As shown above.
By installing this on a device called obnizID 0000-0000 and running it, you will be able to run

// Example.

var obniz = new Obniz("0000-0000", {access_token: "XXXXXX"});

The access token is replaced by a Access tokens are only applied if they are configured.(Block programs do not have access tokens set.)

You can also read the installation settings from the program if they are present in the app (HTML only)
For example, if you can set the watering interval during installation, it would read like this

// Example.

var obniz = new Obniz("OBNIZ_ID_HERE");
var install_configration = Obniz.App.configs();
var water_interval = install_configration['water_interval'];

The browser app can also be configured to run in the obniz cloud. It runs in the cloud based on a trigger and executes in an event-driven manner that finishes within a certain amount of time.
Triggers can be webhook calls, every 10 minutes, devices coming online, etc.
When executed by the server, the results are recorded and can be viewed in the device list.

// Example

// will replace by installed obnizID and access token
var obniz = new Obniz("OBNIZ_ID_HERE"); 

// read install configrations
var install_configration = Obniz.App.configs();
var water_interval = install_configration['water_interval'];

if (Obniz.App.isCloudRunning()) {
  // Cloud Execution
  const req = Obniz.App.req();
  console.log(req.query); // webhook query 
  console.log(req.body);  // webhook body

  // somethig tatsk

  // record a result
  Obniz.App.done({
    status: 'success',
    text: `${temp} degree`
  });
} else {
  // Runnninng on user's browser
}

For more information about the browser application, please see Browser App for more information about the browser application.

Hosted App.

If you want to create a service that runs on your server, a hosted app is useful.
By creating a hosted app, you can get information about the devices that you or other users have installed the app on through the API.
You can leave it to the obniz cloud to connect the app to the device and save the settings.
You can also manage the accounts and devices of approved users.

For more information, please refer to hosted app

Articles