Reputation: 1628
I'm using Occidentalis v0.2 and calling modprobe with a python script to read out temperatures from one DS18B20!
I'm new to python as well so bear with me, this is a small part of my code:
with open(path, "r") as f:
contentArray = []
for line in f:
contentArray.append (line)
f.close
s = contentArray[0]
if s.find('YES'):
return contentArray[0]
else:
return 88
Example: contentArray[0] can give results as:
68 01 4b 46 7f ff 0c 10 05 : crc=3e NO
or:
68 01 4b 46 7f ff 08 10 05 : crc=05 YES
If the above code is wrong, how do I do to find the YES
? Because this states
correct CRC. If I have a yes, I actually want to return contentArray[1]
(which
contains the correct temperature value).
Upvotes: 2
Views: 182
Reputation: 707
Thank you, I will try out the .find command next time. I just scripted a little one-liner for the bash to save temperature readings. Of course the is much space for improvement.
while true; do echo -n "$(date '+%D %T'); " >> output.csv; cat /sys/devices/w1_bus_master1/*/w1_slave | grep -A 1 YES | grep -m 1 t= | cut -c30- >> output.csv; sleep 1; done
As you can see, the keywords "YES" and "t=" are found by the grep command.
Upvotes: 0
Reputation: 1628
Solved, I had to make this change in the code:
s = contentArray[0]
if s.find('YES') != -1:
return contentArray[0]
else:
return 88
Upvotes: 1