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