Browser App: Cloud Execution

If the app has "Cloud Execution" set in the app, the program will be executed by the server whenever a trigger occurs after installation and the execution result will be saved.

When the app is triggered, it will be executed in the cloud. It will run until the Obniz.App.done() function is called or times out (30 seconds).

The maximum number of times to run the app per day is defined at Pricing.

Triggers can be set as follows, and multiple triggers can be set.

Triggers Description
Webhook Webhook issued on each device is launched when it is called. Obniz.App.req()Obniz.App.req() allows the app to retrieve the request object. You can retrieve a request object with Obniz.App.req().
Specified Time For example, everyday/11:11.
Intervally hourly aperture (e.g. 11:11). You can specify the interval in minutes as every/10minutes or in hours as every/10hours.
When the device comes online Run when the device comes online.
When the switch of the device is pressed (only for the target device) press the switch for obniz Board / 1Y. Press the "M5" button for M5StickC.

Cloud Execution Determination and Request

You can check if the program is running in the cloud with Obniz.App.isCloudRunning().
If the program is running in the cloud, you can use Obniz.App.isCloudRunning() to determine if the program is running in the cloud, and if it is running in the browser, you can display the graph.

You can get the query and body if the app is running in a webhook.

if (Obniz.App.isCloudRunning()) {
  const req = Obniz.App.req();
  console.log(req.query);
  console.log(req.body);
}

The result of the cloud execution.

You can save the results of cloud-run app execution.
It is used to display the temperature and status obtained by the sensors. (The block program has a dedicated block for this purpose.)

Obniz.App.done({
  status: 'success',
  text: `${temp} degree`
})

The status is

  • 'success'
  • 'error'

The text can be any string.
If you don't specify it, it will be considered a success.

Obniz.App.done();