PDA

View Full Version : HTTP GET - help for first simple script



tonyG
March 21st, 2016, 09:23 AM
Hi Folks,

After a few days of reading and trying to get my first simple script to work in Girder, I'm embarrassed to say I've failed; hence my request for some help.

I'm looking to trigger some Housebot tasks using Girder.


Housebot External Control using HTTP
Since December 2015, Housebot now offers HTTP control without the requirement of a webserver:
The HTTP Protocol defines one of the communication APIs that the External Control Device expects when it is running in ASCII mode. To control the Device, a separate application (like a web browser) is needed that can connect to an IP address and send and receive data. This allows commands to be sent and status to be queried from web browsers or other applications that can issue HTTP (GET method) commands.

This example command works in a web browser, triggering an event in Housebot (with returned message: Task [Restart] has executed.)
http://127.0.0.1:8001/ET?T=Restart

Where 8001 is the port defined in the external control within Housebot.
<ET?T=Restart> executes a housebot task "Restart"

I'm not using any passwords for this example.


Sending the same command from Girder

I'm assuming this is the correct call to use this, within a script action: network.get( url, callback, timeout, username, password, headers )

I've assumed the help example will work with a few amendments, but I'm not sure how to incorporate the "function" - which in my case will be <ET?T="Restart">

network.get( "http://127.0.0.1:8001", function ( success, status, body )

if not success then
print("Sorry could not connect with server")
return
end

if status ~= 200 then
print("Sorry server returned", status)
return
end

print(body)

end, 3000)

Tried and failed
Could someone point me in the right direction - any help very much appreciated!

KRO74
March 22nd, 2016, 05:30 PM
Have you tried someting like,


network.get( "http://127.0.0.1:8001/ET?T=Restart", function ( success, status, body )

if not success then
print("Sorry could not connect with server")
return
end

if status ~= 200 then
print("Sorry server returned", status)
return
end

print(body)

end, 3000)

tonyG
March 22nd, 2016, 06:15 PM
Have you tried someting like,


network.get( "http://127.0.0.1:8001/ET?T=Restart", function ( success, status, body )

if not success then
print("Sorry could not connect with server")
return
end

if status ~= 200 then
print("Sorry server returned", status)
return
end

print(body)

end, 3000)

Worked first time!

My inadequacies in scripting have just a hit an all-time low (I scrape through in Arduino using examples). I was separating the <ET?T=Restart> element as a part of the function.

Still, with your help it's working. Thank you!

Regards,


Tony