X-Git-Url: http://git.smho.de/gw/?p=owSlave2.git;a=blobdiff_plain;f=tools%2FowReadBMP.py;fp=tools%2FowReadBMP.py;h=00eac22290fb0110f81f954f8ca7c394190085a7;hp=0000000000000000000000000000000000000000;hb=3608ace7dd5bd4fa5d7d49224ef770b21596092c;hpb=3f2aceaf525eeceff3baece206b2048bbf286c40 diff --git a/tools/owReadBMP.py b/tools/owReadBMP.py new file mode 100644 index 0000000..00eac22 --- /dev/null +++ b/tools/owReadBMP.py @@ -0,0 +1,130 @@ +#!/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 +# + + +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"): + dl.append(g) + dc=dc+1 + print dc,") ",g +if dc==0: + print "No 26 1-Wire Device found" + exit(0) +n=int(raw_input("No. of Device (28-Device will get automatically): ")) +n=n-1 +if (n>dc-1)or(n<0): + exit(0) +s=dl[n] +config=owcom(s,[0x85],17) +print(config) +s2="%02x-%02x%02x%02x%02x%02x%02x" % (config[9],config[15],config[14],config[13],config[12],config[11],config[10]) +print("Second Device: %s" %( s2)) +f=open("/sys/bus/w1/devices/%s/w1_slave" %(s2),"rb",0) +res=f.read().split(" ") +f.close() +Press=((int(res[0],16)+int(res[1],16)*256)/16.0*3.2+700) +owcom(s,[0x4E,0x00,0x01],0) +owcom(s,[0x44],0) +time.sleep(1) +owcom(s,[0xB4],0) +time.sleep(1) + +p=owcom(s,[0xBE,0x00],10) +print (p) +T=((p[1]+p[2]*256)/256.0) +if (config[5]==8): + RH=((p[3]+p[4]*256)/100.0) +if (config[5]==7): + 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)); +print("Druck (absolut): %f hPa" %(Press)); +h=float(raw_input("Höhe über Meerespiegel in m: ")) +P0=Press/((1-h/44330)**5.255) +print("Druck (normalisiert): %f hPa" %(P0));