Serverless Event

obniz Cloud runs your program on the cloud automatically using a trigger.

About

To use a device you would need an external program for that purpose, but the Event function on obniz Cloud allows you to manage the program without a server.
obniz Event is a service which runs a program on the cloud automatically when pre-set triggers occur.
This way, just by pre-setting the trigger and program, the program will be activated automatically in the cloud whenever a trigger occurs even without you.
Let's create an Event by choosing a trigger and a program you wish to run.

Triggers

You can choose one of triggers from below:

  1. Webhook
  2. Scheduled Time
  3. Scheduled Interval
  4. obniz online
  5. obniz switch pressed

(Webhook will run a program when URL is called, Scheduled Time will run it according to time.)

Specifications

Maximum number of event you can register is depends on kind and number of licenses you have.

Each Event can be run up to 120 times per day(12 minutes is the minimal interval).

Programs to be registered can only be chosen from the user's repository. Private files can also be chosen.

When a trigger occurs, obniz Event will open the registered HTML on a browser within the server and activate JavaScript.
To stop, call done() from your js. Otherwise, obniz Event will close HTML automatically after 30 seconds.

For Webhook, GET/POST can be used. For query string and post, body can be acquired from js.

After execution, execution logs become available on Event detail page. The capacity of the log storage is 1MB for each obniz license.

Getting Started

First, create your account from Sign In.
Next, buy a license or add your obniz Board to your account to activate a license obniz Board included. It can be done on Device.

When that is done, create a HTML file in your repository.

When running a program through obniz Event, there are few differences compared to when running it on program page, as detailed out below.

done()

Please call done() after your task is done.
Below is a convenient way of calling done, which allows you to finish the task smoothly even on the program page.

if(typeof done === "function") {
  done();
}

req

You can get query and body that were called by webhook through req object.

let request = {};
if (typeof req === "object") {
  request = req;
}
console.log(request.query);
console.log(request.body);

Query and body are parsed objects.
For example, when you access https://obniz.io/events/X/XXXXXX/run?a=1&b=stringdata, request.query is {a:1, b:"stirngdata " }.

When the requested body is {"c":true, "d":100}, {c:true, d:100} gets (parsed) to the body.
If the request is not in JSON string, the body ends up being undefined.

After you finish programming and confirm that it works, register the program in a new Event.
Create the Event by clicking "Create New" on Developer's console.

Type in the names, and select HTML to run as well as a trigger type.

Press "Create" to complete the process.
If you choose webhook, an url for webhook will be shown.

Test

When you want to execute a program right away without a trigger, you can manually execute the program by clicking "Test Run Now" button on the Event page.

Logs

You can check every log after execution on the log list on the Event page.
To check details, click the files with the execution date you wish to check.