I have several temperature sensors on my Raspberry connected to GPIO. They work fine and I get the temperature values from the sensors in the files named “…/w1_slave”.
Content of this file is for example:
86 01 4b 46 7f ff 0c 10 f4 : crc=f4 YES
86 01 4b 46 7f ff 0c 10 f4 t=24437
The string t=24437 represents the temperature of 24.437 °C
Now I want to show the temps in my Basic UI
I found a bash script that reads the temperature values out of the files
#!/bin/bash
wert=‘cat /sys/bus/w1/devices/$1/w1_slave | tail -n1 | cut -d “=” -f2’
wert2=‘echo “scale=3; $wert/1000” | bc’
echo $wert2
(Hint: The ’ - characters are only shown here because I can´t use the original accent characters in this forum)
But this script causes linux to show the error:
(standard_in) 1: illegal character: ^M
So I wrote a test script that shows the value of the Sensor and also the hex-converted value
#!/bin/bash
wert=cat /sys/bus/w1/devices/$1/w1_slave | tail -n1 | cut -d "=" -f2
echo $wert
echo “hex:”cat /sys/bus/w1/devices/$1/w1_slave | tail -n1 | cut -d "=" -f2 | xxd -p
The output is:
24437
hex: 32343433370a
So the temperature is read correctly (24.437 °C) but there is the disturbing linefeed “0a” at the end.
How can I get the temperature value without that linefeed character?