Create Hourly Alarm

Automac program execution with obniz Event.

Aboutobniz Event

obniz Event is a service which run a program automatically by trigger. Just set triger and program. You don't need to run a program yourself.

See more details on obniz Event.

With obniz Event, You don't required to opening HTML on your browser and run program on Nodejs. obniz Event run it automatically.
Now we are going to create 1 hour alarm.

Let's make

See how to create an event at obniz Event.

First you should Create an account then on My Page, add your obniz to your account.

After that, Create a program on your repository.
We are going to register it to an event to be called hourly.
Press Create on repository file list to create new HTML, then input name you want (Example shows "test").

Wire and program

Connect a speaker to your obniz. Now we use io3 and io9

Let's program. Beep it by just opening HTML.

<!-- HTML Example -->
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://obniz.io/js/jquery-3.2.1.min.js"></script>
  <script src="https://unpkg.com/obniz@2.0.2/obniz.js"></script>
</head>
<body>

<div id="obniz-debug"></div>

<script>
var obniz = new Obniz("OBNIZ_ID_HERE");
obniz.onconnect = async function () {

  var speaker = obniz.wired("Speaker", {signal:3, gnd:9});
  speaker.play(1000);
  await obniz.wait(1000);
  speaker.stop();
}
</script>
</body>
</html>

Copy this to your HTML. Does it beep by opening HTML?

A program which called from event should call done() function(details on obniz Event).
If don't do that, your HTML will be closed after 30seconds.
done funciton only exists when executed from event. So, check existance first then call it.

<!-- HTML Example -->
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://obniz.io/js/jquery-3.2.1.min.js"></script>
  <script src="https://unpkg.com/obniz@latest/obniz.js"></script>
</head>
<body>

<div id="obniz-debug"></div>

<script>
var obniz = new Obniz("OBNIZ_ID_HERE");
obniz.onconnect = async function () {

  var speaker = obniz.wired("Speaker", {signal:3, gnd:9});
  speaker.play(1000);
  await obniz.wait(1000);
  speaker.stop();

  if (typeof done === "function") {
    done();
  }
}
</script>
</body>
</html>

Event Registration

Open event creation form from My Page. It is on right of event list.

Input forms.

  1. name: name you want.
  2. WebApp to run: Select one which program to be executed.
  3. Event Triggers: Select Scheduled trigger. "Every 1 hour" should be selected.

Press Create.

Done!

OK, Let's try it.
Press "Test Run" on your event page. It will manually trigger the event.
Does it Beep? YES!
It will beep every hour continuously.

If don't beep, you can check execution logs on event page.
See what's happens on exectuion.



Next : Webhook IFTTT Integration