oh7fxk
Posts: 7
Joined: Fri Nov 30, 2012 7:00 pm

Onewire temperature logging

Sun Dec 09, 2012 12:35 pm

Evening, I have an DS18S20 chip connected via GPIO to my RPi.
I have tried to get my RPi read temperature once a hour from it and after that to write it in .txt or .html file.
So far, I can get it only make an file, no more.
And my way to do that takes 100% CPU load.

So, how to do that easier?

User avatar
joan
Posts: 14196
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Onewire temperature logging

Sun Dec 09, 2012 12:55 pm

#!/bin/bash
while true
do
temperature=`your program to read chip`
echo $temperature >>logfile
sleep 3600
done

jamiesk
Posts: 95
Joined: Mon Nov 26, 2012 8:48 pm
Location: Ipswich, Suffolk, England, UK.

Re: Onewire temperature logging

Sun Dec 09, 2012 2:52 pm

Be much easier to put the program into a cron job. The cron job set to run every hour. Note that any paths etc you need will have to be setup. I usually call the program from a bash script. So the one supplied would look like...

#!/bin/bash
temperature=`your program to read chip`
echo $temperature >>logfile
Pi1 (Nov 2012 loft)= 1KW immersion controller for Solar panel
Pi2 (Jan 2013 living room)=Play thing
Pi3 (Feb 2013 mobile)= Play thing with Tandy Ladder board,breakout board,Nokia display
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=28193

oh7fxk
Posts: 7
Joined: Fri Nov 30, 2012 7:00 pm

Re: Onewire temperature logging

Sun Dec 09, 2012 3:04 pm

Both ways work well, but there is one problem, it's allways writes over old temperature.
And my way to add timestamp looks explode whole bomb.

jamiesk
Posts: 95
Joined: Mon Nov 26, 2012 8:48 pm
Location: Ipswich, Suffolk, England, UK.

Re: Onewire temperature logging

Sun Dec 09, 2012 6:37 pm

You are using TWO greater than signs ? One makes the file EXACTLY what you put in to it. Two appends to the end.

Show us your script and we might be able to help.
Pi1 (Nov 2012 loft)= 1KW immersion controller for Solar panel
Pi2 (Jan 2013 living room)=Play thing
Pi3 (Feb 2013 mobile)= Play thing with Tandy Ladder board,breakout board,Nokia display
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=28193

Return to “General programming discussion”