Cloud Execution by time

The browser app can be run in the obnizcloud as well as the user's browser. Periodic execution is a setting that allows your app to run in the cloud at regular intervals.

Configuring Periodic Execution.

From the app's settings, under "Cloud Execution", list the time in "Run in Time". The format is as found in document

  • Regular interval: every/10minutes, every/10hours
  • Every day at a specific time: daily/11:11

You can specify the time in the following way.

Installing a configured app will start it automatically for that device.

Periodic execution can be used to monitor things that don't change much or to manipulate things that only need to be moved occasionally, as it runs at regular intervals.

(Example.)

  • Watering the plants by moving the pump at regular intervals
  • Monitor the river level every 30 minutes and email me if there is anything unusual.

The following is an example of a pump connected to io0 and io1 that runs at regular intervals.

var obniz = new Obniz("OBNIZ_ID_HERE");
obniz.onconnect = async function () {
  var motor = obniz.wired("DCMotor",  {forward:0, back:1});
  motor.forward();
  await obniz.wait(1000);

  if (Obniz.App.isCloudRunning()) {
    Obniz.App.done({
      status: 'success',
      text: `Worked`
    })
  } else {
    alert("Done.")
  }
}

Or if you want to throw an API that monitors the temperature and sends an email

var obniz = new Obniz("OBNIZ_ID_HERE");
obniz.onconnect = async function () {
let device = obniz.wired("DHT12",{scl:26,sda:0});
let temperature = await device.getTempWait();
  if (Obniz.App.isCloudRunning()) {
    if(temperature > 30) {
      try {
        fetch(`https://xxxxx/xxxxx`)
      } catch(e) {
        console.error(e);
      }
      Obniz.App.done({
        status: 'error',
        text: `Too hot ${temperature} degree`
      })
    } else {
      Obniz.App.done({
        status: 'success',
        text: `It's fine ${temperature} degree`
      })
    }

  } else {
    alert("Done.")
  }
}