Page 1 of 1

Passing system temp to Domoticz using a bash script

Posted: Saturday 22 August 2020 11:31
by pgielen
I am trying to read the system temperature from my RPi and send it to Domoticz, using the following bash script:

Code: Select all

#! /bin/sh
temp=$(vcgencmd measure_temp | egrep -o '[0-9]*\.[0-9]*')
echo "System temperature: $temp"
url="http://192.168.1.52:8080/json.htm?type=command&param=udevice&idx=571&nvalue=0&svalue=$temp"
echo "$curl"
curl "$url"
Lines 3 and 5 are only there for testing if the values passed on to the url are correct.

However, this does not work; curl answers (3) URL using bad/illegal format or missing URL, because it apparently expects double quotes arount the url (if I directly type in something like: curl "http://192.168.1.52:8080/json.htm?type= ... &svalue=77" in the cli, the value is passed on to Domoticz without problems).

Changing line 4 to:

Code: Select all

url="\"http://192.168.1.56:8088/json.htm?type=command&param=udevice&idx=571&nvalue=0&svalue=$temp\""
does not work either, because the url string will get a leading double quote, but the double quote at the end of the string still gets lost for some reason.

I tried the same with wget in stead of curl, with the same results...

Is there another way to pass such a value from bash to Domoticz or should I switch to PHP or Python for this relatively simple task?

Re: Passing system temp to Domoticz using a bash script

Posted: Saturday 22 August 2020 12:03
by felix63
did you try this?

Code: Select all

curl $url

Re: Passing system temp to Domoticz using a bash script

Posted: Saturday 22 August 2020 14:11
by pgielen
felix63 wrote: Saturday 22 August 2020 12:03 did you try this?

Code: Select all

curl $url
Yes, same problem

Re: Passing system temp to Domoticz using a bash script

Posted: Saturday 22 August 2020 15:53
by waaren
pgielen wrote: Saturday 22 August 2020 11:31 I am trying to read the system temperature from my RPi and send it to Domoticz
I normally use the bash shell.
sh is behaving different.

I tested below script and it does the job.

Code: Select all

#!/bin/bash
temp=$(vcgencmd measure_temp | egrep -o '[0-9]*\.[0-9]*')
echo "System temperature: $temp"
url="http://192.168.1.52:8080/json.htm?type=command&param=udevice&idx=571&nvalue=0&svalue=$temp"
echo $url
curl $url

Re: Passing system temp to Domoticz using a bash script

Posted: Sunday 23 August 2020 15:03
by pgielen
Yes it does. Remarkably enough the problem were -once more- CRLF characters in the script. I dit not see this coming, since the CR's ended up not in the variable names, but in the values of the variables $temp and $url. No idea how this can happen, but after I removed the CR from the end of every line in the script, the problem was solved.

Re: Passing system temp to Domoticz using a bash script

Posted: Sunday 23 August 2020 15:41
by gizmocuz
Could you try beta 12268, when you add the motherboard hardware to your domoticz (from the hardware setup page), you should see your motherboard temperature. (double check if accept new hardware/devices is enabled in your settings)
(I think this should also with with previous beta's already as It's working on my RPi4)