[ST Edge] Web Requestor: a driver to issue local POST and GET HTTP requests

Thanks for sticking with me. Using Chrome’s developer tools, I am not sure what I am looking at or should be looking for. I don’t see the base64 converted key to sanity check:

General
Request URL: http://login:password@192.168.1.100:80/cgi-bin/coaxialControlIO.cgi?action=control&channel=8&info[0].Type=1&info[0].IO=1
Request Method: GET
Status Code: 200 OK
Remote Address: 192.168.1.100:80
Referrer Policy: strict-origin-when-cross-origin

Response Headers
CONNECTION: close
CONTENT-LENGTH: 4
Content-type: text/plain;charset=utf-8

Request Headers
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Cache-Control: max-age=0
Connection: keep-alive
DNT: 1
Host: 192.168.1.100:80
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36

Is there no 401 error return and then a retry?

Try it also without providing the userid & pw. You should get a popup window asking for your credentials if the camera is asking for them.

You may also need to reset the connection to the camera; you’re probably already logged in through your browser as far as the camera is concerned.

Thanks,

When I hit it again (without the login:password@ prefix) in Chrome and entered the login and password in the pop-up dialog, I get:

Authorization: Digest username=“login”, realm=“Login to XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”, nonce=“XXXXXXXXX”, uri=“/cgi-bin/coaxialControlIO.cgi?action=control&channel=8&info[0].Type=1&info[0].IO=1”, response=“XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”, opaque=“XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”, qop=auth, nc=00000002, cnonce=“XXXXXXXXXXXXXXXX”

I masked the numbers, since I have no idea what might be sensitive.

This makes me think it is using Basic for the main ip:port, but Digest for any sub urls.

Yup. You won’t be able to do what you want to; Digest authentication can’t be done through webrequestor. This is something I’d have to look at adding in the future.

Thanks for your hard work on all of these great tools, they have saved my bacon several times and kept me out of trouble with the wife lately as I make the transition.

I apologize for taking your time on this, I assumed that if I could hit the ip and port with Basic auth, that every other sub-url would be the same. My bad. Thanks for guiding me through it.

Any plan to add the ability for “login:password@ip:port” in the ip address field for this tool down the line? Or do you know if rules engin, or rules api, or whatever it is, can handle Digest auth?

It’s on my list of potential enhancements but can’t say right now when I’ll get it done. I have the Digest code from my ONVIF driver which has to support it, so at least I wouldn’t be starting from scratch. I think I’d want to provide both basic and digest and possibly ws-security.

Rules engine has nothing related to LAN-related authentication.

Sounds good… standing by. Let me know if I can beta test anything.

1 Like

Hi , sorry to ask a stupid question. im trying to use your driver to talk to a KNX gateway. how do i get it to push these commands

this turns device 97 on
http://192.168.1.240:80/baos/SetDatapointValue?Datapoint=97&Format=RAW&Command=SetSendVal&Length=1&Value=1

after running it returns

{
“Result”:true,
“Service”:“SetDatapointValue”
}

and this turns it off

http://192.168.1.240:80/baos/SetDatapointValue?Datapoint=97&Format=RAW&Command=SetSendVal&Length=1&Value=0

i tried just pasting this url into a web request #1 but it didnt work . should i use POST or GET or Put or what am i doing wrong ?

From my experience, as long as entering those into a browser works without needing to enter a login and password for the device, you should be able to use GET:

Try this in web request #1:

GET:http://192.168.1.240:80/baos/SetDatapointValue?Datapoint=97&Format=RAW&Command=SetSendVal&Length=1&Value=1

And if that doesn’t work, try this:

POST:http://192.168.1.240:80/baos/SetDatapointValue?Datapoint=97&Format=RAW&Command=SetSendVal&Length=1&Value=1

Thanks so much! GET: seems to work .

So if for example i need to turn on light number 97 then i need to make web request # the GET command for on and then make web request # 2 the Get command for off ?

stupid question , is there anyway to know the status of the light with this ?

sorry for the dumb questions , im a bit slow since the stroke last year.

For your first question. You can use Web Requestor to create individual debices for on and off separately using just web request #1, which may help you keep track, or you can have web request #1 and web request #2 used in the same one. With Web Req Multi Master open and after setting up your settings, scroll all the way to the bottom and use the Create New Device button to create the device.

For your second question. I think the easiest way would be to create a virtual switch in SmartThings that turns on and off with the routine(s) you are using to control your light. That way you can watch the virtual switch to see current state of the light. I am using Virtual Devices V2, also from @TAustin, for similar setup. This only works if your only method for controlling the light is via SmartThings.

The harder way would be if your light api has a method of checking the status, you could use Web Requestor to get the status periodically.

I am still learning all this stuff myself, so am interested in how others here might recommend doing it.

Adding to @JKnight’s response…

Another option, if you prefer to have separate devices, is to use my HTTP Devices driver. Instead of having one device where you can configure multiple requests, or even creating multiple webrequestor devices, with the HTTP Devices driver, you create a distinct device for each ‘thing’ you want to control. So for example if ‘light’ is one of your things, you could create a switch device under HTTP Devices driver and then configure the distinct ON and OFF HTTP requests in that device’s settings. It accomplishes the same thing, but sometimes due to the way your automations may be set up, it can be handy to have this alternative. This also kills two birds with one stone, as you wouldn’t need to create a separate virtual switch. The HTTP Device itself is a ‘virtual switch’ that happens to emit HTTP requests based on the switch value.

Getting the current status of the light would require an HTTP endpoint that allows you to retrieve it. In webrequestor, you can extract a value from the response data and have it put in a field that you could test. You can also choose to have it displayed on the dashboard card.

Otherwise if you really want two-way control of an external device, you might also consider MQTT. It requires you run a broker on your LAN, but if your KNX gateway supported it, it would make it easier to both get status and send commands via MQTT messaging from SmartThings.

I have a web based light dimmer which is can be controlled through HTTP POST. I would like to have the virtual dimmer switch from SmartThings to HTTP POST its current “level” to the URL specified.

I wonder if something mentioned by @TAustin for the HTTP Devices V1 ([ST Edge] Web Requestor: a driver to issue local POST and GET HTTP requests - #340 by TAustin) is possible or not with SmartThings rules:create where a {“level”=${level}} would get replaced with the actual “level” from SmartThings virtual dimmer. I couldn’t seem to find a way to achieve it. Can anyone advise me on a possible solutions?

Can a LAN computer get the “level” value through SmartThings RESTful API? Is there any guidance available on how to use SmartThings RESTful API to get get attributes like “level”?

Thanks!

Hi Eric and welcome to the community.

You want to use my HTTP Devices driver. If you create a dimmer device with that driver, it has exactly what you are looking for. You can include a ${level} either as part of the HTTP request header, or in the body of the HTTP message. See the examples in the readme file.

Thanks @TAustin for the suggestion. I’ve tried that out and wonder if you can add a “switch” for on/off to the current dimmer device or not.

Is there a way to make it so that the URL can be longer than the current version of Web Requester allows for. I have a URL in the following format that I have to hit and it seems to be too long for the entry area where you specify the URL to be hit.
http://192.168.0.81/apps/api/65/execute/:28ac717a5745ef69b7b35df99b5e5664:?access_token=9ec144a9-aed4-3628-882e-efb85659f55a

In my HTTP Devices driver I’ve provided a “more” field for the URL field, so if you can accomplish what you want with that driver that would be your best solution for now. One of these days I will also add a similar “more” field in web requestor as well.

I can. I’ll look at including that in my next driver update. How would you want to see the two different state values sent out? Would a JSON formatted message with both values work for you?

Instead, did you try saving it as a preset in Settings? There it should fit.

That would be great! Either format is fine as I’m running a Docker container locally to process these data. Thanks!