[Runkit]Use webhook

Get http request on runkit

Runkit has endpoint which can accept https request.
Let's make it which change LED state.

// Runkit Endpoint Example

const Obniz = require("obniz");
const express = require("@runkit/runkit/express-endpoint/1.0.0");
const app = express(exports);

const yourObnizId = "OBNIZ_ID_HERE";  // write your obniz id

app.get("/", async (req, res) => {

    let obniz = new Obniz(yourObnizId);

    let connected = await obniz.connectWait({timeout:10});

    if(connected){
         let led = obniz.wired("LED", {anode:0, cathode:1});
         let changed = "";
         if(req.query.led == "on"){
            led.on();
            changed = "on";
         }else{
            led.off();
            changed = "off";
         }

         obniz.resetOnDisconnect(false);
         obniz.close();

         res.send("LED Changed to "+changed);
    }

});

It is use famouse Node.js framework "express".

Can you see url instead of "run" button?
Click this button.

If you are writing on runkit, click endpoint.

If you see "LED Changed to off", it is ok.

If you see like this, it is something wrong.
Please check obniz_id and obniz state(is it online?).

{
  "error": "timeout",
  "message": "The server did not return a response quickly enough."
}

Next, Turn on LED.
Add ?led=on to the endpoint url .

If your endpoint is https://untitled-kgxjycirmufe.runkit.sh,
it will be https://untitled-kgxjycirmufe.runkit.sh?led=on.

Go to the page.

If you see "LED Changed to on", it is ok.
Your LED will be shining.

publish

The endpoint is made from ramdom text.
https://untitled-kgxjycirmufe.runkit.sh

It is difficurt to remenber, change to someting another.

On runkit, set name to your notebook.
The default is "untitled-notebook".
Please change to "obniz-led-onoff"

Click publish and write setting.

You can use this url.

https://runkit.com/[user name]/[notebook name]/[version]

My user name is 9wick, and notebook name is "obniz-led-onoff",
so my url is https://runkit.com/9wick/obniz-led-onoff/1.0.0.



Next : [Runkit]Make temperature api

You will Get in Few Days

Circuit for Starter “obniz Board” is available on Amazon and other online stores.
You can get it at below

Our products and resellers

Forum

Visit our developer’s forum to discuss and discover technologies.

Forum

Contact

Feel free to contact out support and technical team.

Contact us