ALLTERCO/shelly-script-examples

Script request: HTTPServer

Closed this issue · 2 comments

I am struggling with how to use the HTTPServer and would love to see your take on it. Could you maybe add a script using the HTTPServer? So far it seems the only feature not represented in this extensive and helpful script collection.

Anyway, thanks for the awesome work so far, its a lot of fun to check it out!

Here's a mini example, hope that helps you understanding the HTTPServer endpoint.

HTTPServer.registerEndpoint('testserver', function (req, res) {

    // check request and comapare the querystring
    if (req.query === 'turn=on') {
        // response with some text
        res.body = 'Shelly Webserver: on';
        res.code = 200;
        res.send();
        // Do something, e.g. Shelly.Call();


    } else if (req.query === 'turn=off') {
        // response with some text
        res.body = 'Shelly Webserver: off';
        res.code = 200;
        res.send();
        // Do something else, e.g. Shelly.Call();

    }
    else {
        res.body = 'Shelly Webserver';
        res.code = 200;
        res.send();
    }
})

can be called via
http://<ip>/script/<id>/testserver?turn=on

is the script ID
is the Shellies ip address.

@eurich Is there a way to call http:///script//testserver?turn=on with username & password if you set a password for the shelly?

http:///script//testserver?turn=on&user=admin&username=xyz doesn't work