Re: [weewx-user] Re: DS18B20 Temp sensor daten in weewx einbinden auf Raspberry ?

2019-12-20 Thread p q
Agreed, writing to a text file is a start. For Weewx you'll want a driver
that brings it in.

You didn't mention if you have a weather station or not. Weewx was designed
to be used with a weather station.

Anyway, you can see how I solved a similar problem here:
https://hackaday.io/project/101680-solar-powered-wifi-temperature-sensor-for-weewx

On Fri, Dec 20, 2019 at 5:23 AM Paul McGeorge  wrote:

> The attached python script will write a file named soiltemp.txt for two
> DS18B20 Sensors.  You will need to edit the sensor numbers and names to fit
> your needs.
>
>
> On Friday, December 20, 2019 at 5:30:47 AM UTC-7, Andreas Weber wrote:
>>
>>  Hi there
>>
>> I have a weewx and Rasperry pi and would like to connect 3 temp sensors
>> DS18B20 and display them on my homepage.
>>
>> Installation of the 3 sensors on Raspberry is no problem, I have 3
>> folders for the 3 sensors and sensor data.
>>
>> Who can show me the way how to go on?
>>
>> There is a script in the weewx manual, but it cannot be used because
>> there is no query from the DS18B20.
>>
>> I am not programming and I have already experimented with different code
>> snippets on the internet, unfortunately without success.
>>
>> The sensor data must be written in a text file and weewx reads out the
>> data.
>>
>> But I have no idea how to do it.
>>
>> I would like to be shown the way how it works.
>>
>>
>> Please help
>>
>>
>> A heartfelt thank you
>>
> --
> You received this message because you are subscribed to the Google Groups
> "weewx-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to weewx-user+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/weewx-user/59a28e56-b7b1-4ef9-9e41-058474c2531f%40googlegroups.com
> 
> .
>


-- 
Peter Quinn
(415)794-2264

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to weewx-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/CAA1SM20PVYWxEoX63Ln_iyNrJDv%2BOEmg51JeJ-cteW_-cXu7sQ%40mail.gmail.com.


[weewx-user] Re: DS18B20 Temp sensor daten in weewx einbinden auf Raspberry ?

2019-12-20 Thread Paul McGeorge
The attached python script will write a file named soiltemp.txt for two 
DS18B20 Sensors.  You will need to edit the sensor numbers and names to fit 
your needs.


On Friday, December 20, 2019 at 5:30:47 AM UTC-7, Andreas Weber wrote:
>
>  Hi there
>
> I have a weewx and Rasperry pi and would like to connect 3 temp sensors 
> DS18B20 and display them on my homepage.
>
> Installation of the 3 sensors on Raspberry is no problem, I have 3 folders 
> for the 3 sensors and sensor data.
>
> Who can show me the way how to go on?
>
> There is a script in the weewx manual, but it cannot be used because there 
> is no query from the DS18B20.
>
> I am not programming and I have already experimented with different code 
> snippets on the internet, unfortunately without success.
>
> The sensor data must be written in a text file and weewx reads out the 
> data.
>
> But I have no idea how to do it.
>
> I would like to be shown the way how it works.
>
>
> Please help
>
>
> A heartfelt thank you
>

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to weewx-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/59a28e56-b7b1-4ef9-9e41-058474c2531f%40googlegroups.com.
import subprocess
import glob
import time
from datetime import datetime


sensor1 = '28-0113170101b8'# you need to add each sensor's address manually to these lines
sensor2 = '28-0113167dbf61'# you need to add each sensor's address manually to these lines
sensor1name = 'Left_temp'
sensor2name = 'Right_temp'

base_dir1 = '/sys/bus/w1/devices/'
device_folder1 = glob.glob(base_dir1 + sensor1)[0]
device_file1 = device_folder1 + '/w1_slave'

def read_temp_raw1():
catdata = subprocess.Popen(['cat',device_file1], stdout = subprocess.PIPE, stderr=subprocess.PIPE)
out,err = catdata.communicate()
out_decode = out.decode('utf-8')
lines = out_decode.split('\n')
return lines

def read_temp1():
lines = read_temp_raw1()
while lines[0].strip()[-3:] != 'YES':
time.sleep(10.0)
lines = read_temp_raw()
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
temp_f = temp_c * 9.0 / 5.0 + 32.0
return temp_f

base_dir2 = '/sys/bus/w1/devices/'
device_folder2 = glob.glob(base_dir2 + sensor2)[0] 
device_file2 = device_folder2 + '/w1_slave'

def read_temp_raw2():
catdata = subprocess.Popen(['cat',device_file2], stdout = subprocess.PIPE, stderr=subprocess.PIPE)
out,err = catdata.communicate()
out_decode = out.decode('utf-8')
lines = out_decode.split('\n')
return lines

def read_temp2():
lines = read_temp_raw2()
while lines[0].strip()[-3:] != 'YES':
time.sleep(10.0)
lines = read_temp_raw()
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
temp_f = temp_c * 9.0 / 5.0 + 32.0
return temp_f

while True:

date = datetime.today().strftime("%x , %X")
temp1 = str(read_temp1())
temp2 = str(read_temp2())
print (sensor1name+' = '+temp1)
print (sensor2name+' = '+temp2)
fd = open('/home/pi/soiltemp.txt','w')
fd.write(sensor1name+' = '+temp1+'\n')
fd.write(sensor2name+' = '+temp2+'\n')
fd.close()

time.sleep(25.0)