How to curl in Smart Things

Hi,

What would the equivalent command for curl? I’m trying to make Lannouncer work.
Typically the curl example would be like this: curl “192.168.1.20:1035/?SPEAK=@|ALARM=CHIME&@DONE@”

This works if sent it via curl but no avail on smart things.

I tried doing this but it didn’t work

def q = new physicalgraph.device.HubAction("""GET /$pathorparams HTTP/1.1\r\nHOST: $ip\r\n\r\n""", physicalgraph.device.Protocol.LAN, (device.deviceNetworkId))
sendHubCommand(q)

You probably want to start here to get the use of HubAction right:

http://docs.smartthings.com/en/latest/cloud-and-lan-connected-device-types-developers-guide/building-lan-connected-device-types/building-the-device-type.html

Though actually what you want looks so basic that you could just use CoRE, no programming required.

I tried creating the hubaction just like in the doc and it didn’t work either but I’ll try again and what is CoRE?
http://thingsthataresmart.wiki/index.php?title=CoRE

This is the first time I heard about it - how can I use it to send 1 ‘simple’ curl?

I’m not a CoRE expert, but you found the right link. CoRE is a rule engine, so you can set up things like “if this light turns on, then do that action”. And one possibility for the action is to send a web request (under “Then” select “using Location” / “make a web request”). You may have to figure out how to send your query parameters, as they look non-standard to me. There’s a thread here where you can ask for help with CoRE.

Sounds like IFTTT but a component inside SmartThings. Thanks, I’ll go check it out.

You can check out an example I have in the nvr_cameraPoll() function. The contents of “target” are in the form of “ip:port” and must be on the same LAN as the hub. You might have to change or omit the Accept header.

sendHubCommand( new physicalgraph.device.HubAction("""GET /api/2.0/camera/${state.id}?apiKey=${key} HTTP/1.1\r\n Accept: application/json\r\nHOST: ${target}\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${target}", [callback: nvr_cameraPollCallback]))

yes target is 192.168.x.xx:port and in the same network. I’ve tried just like what you have now. except when i did it the target is encapsulated in parenthesis and I didn’t have a callback function (which i’m assuming is optional argument)

I’m beginning to think that to be able to speak curl through ST i would have do it via a post(empty body?) instead of a get.

I’ll try to interpolate the target var instead and see if it’ll work thanks

Your curl example is a GET command so it should work very similarly. Yes, the callback is optional. If you don’t specify it, your device can get the reply through the “parse” function called by the ST platform. Try this:

target = "192.168.1.20:1035"
sendHubCommand( new physicalgraph.device.HubAction("""GET /?SPEAK=@|ALARM=CHIME&@DONE@ HTTP/1.1\r\n Accept: */*\r\nHOST: ${target}\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${target}"))

didn’t work. Did your original hubaction work?

Ahhh crap… sorry guys. It was working all along. It was because my hub is on main router and my wifi is on 2nd router.

Thanks for your help. Appreciate it!

Ah so they are on different subnets? I wish ST would remove the restriction to require the target be on the same subnet and maybe allow all RFC1918 address space :unamused: It prevents me from successfully doing things across local VLANs.

Yup hub on 192.168.1 and device on 192.168.2 - wasn’t expecting that either but glad I thought about it.

Seeing if anyone can help me with this I want to run this from ST:

curl -XPOST -d 01 192.168.1.12:8181/zones/14/pr

What would change is the “01” this is for volume control/On&Off/etc… 14 is the zone & pr for type of command pr is power on/off.