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
how to get boolean answer from curl
Moderator: leecollings
- waltervl
- Posts: 6691
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2025.1
- Location: NL
- Contact:
Re: how to get boolean answer from curl
Enough exit codes on curl: https://everything.curl.dev/usingcurl/returns
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
Gravityz
- Posts: 652
- Joined: Wednesday 16 December 2015 19:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2025.1
- Location: Netherlands
- Contact:
Re: how to get boolean answer from curl
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
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
-
azonneveld
- Posts: 179
- Joined: Wednesday 02 October 2019 7:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands
- Contact:
Re: how to get boolean answer from curl
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.
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.
rpi4 - zigbee2mqtt - roborock - espeasy - rfxcom - homewizard p1 - otgw - homebridge - surveillance station - egardia - goodwe - open weather map - wol - BBQ detection - rsync backup
-
Gravityz
- Posts: 652
- Joined: Wednesday 16 December 2015 19:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2025.1
- Location: Netherlands
- Contact:
Re: how to get boolean answer from curl
@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
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
Who is online
Users browsing this forum: No registered users and 1 guest