Page 1 of 1
how to get boolean answer from curl
Posted: Wednesday 23 November 2022 14:39
by Gravityz
Hello,
i am using ping to check if a device is online.
ping_success=os.execute('ping -c2 -w2 192.168.1.165')
if ping_success ......
WORKS
now i want to do the same with curl but it seems curl does not reply with either codes or boolean
ping_success=domoticz.utils.osCommand('curl -m 1 192.168.1.165')
DOES NOT WORK
ping_success=os.execute('curl -m 1 192.168.1.165')
DOES NOT WORK
does anybody know how i can do an easy check if the curl command went ok or not
the problem that either the reply is not boolean or there is no reply(returncode) at all
Re: how to get boolean answer from curl
Posted: Friday 02 December 2022 18:46
by waltervl
Re: how to get boolean answer from curl
Posted: Sunday 04 December 2022 14:13
by Gravityz
yes but they do not get returned into domoticz
both curl and ping should return a 0 when succesfull however i can not replace ping wirth curl so obviously the response is not the same
ping_success=os.execute('ping -c2 -w2 192.168.1.160')
returns 0/true when succesfull
i can use "when ping_success then"
ping_success=domoticz.utils.osCommand('curl -f -m 1 192.168.1.160')
has a different repsonse when successfull
"when ping_success then" does not work
Re: how to get boolean answer from curl
Posted: Sunday 04 December 2022 14:58
by azonneveld
Maybe the hardware device "system alive checker" provides a solution for your application?
This is the built in pinger from domoticz.
Running ping from your code holds the script until there is an awnser, this could cause the script to execute slowly.
Re: how to get boolean answer from curl
Posted: Sunday 04 December 2022 15:12
by Gravityz
@azonneveld. thanks for the tip. i already tried it and that indeed would work.
i however want to solve it without creating extra devices.
the device i need to ping is a lightbulb which can not be integrated correctly into domoticz.
i am using http code to turn it on/off and change color.
when the light is physically turned off (no AC to light) and a script wants to change the light i get an http error(because the light is not available)
so i am doing all of this basically to avoid this error in the log.
so if there is any other soplution to just suppress an http error when the site./address is not available that would solve my problem also
in a script you van use redirect >>/dev/null
i do not know if this exists for a http link
http://192.168.1.160/cm?cmnd=backlog%20 ... ture%20500