X-Git-Url: http://git.smho.de/gw/?p=owSlave2.git;a=blobdiff_plain;f=tools%2FreadTempHum.py;fp=tools%2FreadTempHum.py;h=0000000000000000000000000000000000000000;hp=d129db68f28fe7970c9c4ad4b30f3700fc228a9e;hb=5398c69061a72e7a6ad3423c4e17516ee6d09de6;hpb=22b81b6c288ca56f58d064627c310e437f9453a4 diff --git a/tools/readTempHum.py b/tools/readTempHum.py deleted file mode 100644 index d129db6..0000000 --- a/tools/readTempHum.py +++ /dev/null @@ -1,125 +0,0 @@ -#!/usr/bin/python -# Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the -# distribution. -# * All advertising materials mentioning features or use of this -# software must display the following acknowledgement: This product -# includes software developed by tm3d.de and its contributors. -# * Neither the name of tm3d.de nor the names of its contributors may -# be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - - - -import time -import subprocess -import sys - -def owcom(dev,send,rc): - res=[] - f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0) - f.write("".join(map(chr, send))) - if (rc!=0): - res=map(ord,f.read(rc)) - f.close() - return res - - -def crc8(arr): - lscrc=0x0; - for v in arr: - bit=1; - while bit<256: - if (v&bit)==bit: - lb=1 - else: - lb=0 - if (lscrc&1)!=lb: - lscrc=(lscrc>>1)^0x8c - else: - lscrc=(lscrc>>1) - bit=bit*2 - return lscrc - -def testnr(s): - for c in s.lower()[:]: - if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']): - return False - return True - -def addid(id,val): - for i in range(7): - id[i+1]=id[i+1]+val - if id[i+1]>254: - id[i+1]=id[i+1]-254 - val=1 - else: - return id - return id -# - -def readDS18B20(s): - f=open("/sys/bus/w1/devices/%s/w1_slave" %(s),"rb",0) - res=f.read().split(" ") - f.close() - T=((int(res[0],16)+int(res[1],16)*256)/16.0) - print("Temperatur: %f °C" %(T)); - -def readDS2438(s): - owcom(s,[0x4E,0x00,0x01],0) - owcom(s,[0x44],0) - time.sleep(1) - owcom(s,[0xB4],0) - time.sleep(1) - owcom(s,[0xB8,0x00],0) - crc=1 - while crc: - p=owcom(s,[0xBE,0x00],9) - crc=crc8(p) - #print (p) - T=((p[1]+p[2]*256)/256.0) - RH=(((p[3]+p[4]*256)/ 500.0 - 0.16) / 0.0062) / (1.0546 - 0.00216*T); - print("Temperatur: %f °C" %(T)); - print("Luftfeuchte: %f %%" %(RH)); - - - -l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True) -dc=0 -dl=[] -for g in (l.split("\n")): - if len(g)>2: - if testnr(g[0:2]): - if (g[0:2]=="26"): - print dc,") ",g - readDS2438(g) - dl.append(g) - dc=dc+1 - if (g[0:2]=="28"): - print dc,") ",g - readDS18B20(g) - dl.append(g) - dc=dc+1