#!/usr/bin/env python # -*- coding:utf-8 -*- import sys import DHTreader DHT11 = 11 DHT22 = 22 AM2302 = 22 DHTreader.init() if len(sys.argv) != 3: print("usage: {0} [11|22|2302] GPIOpin#".format(sys.argv[0])) print("example: {0} 2302 Read from an AM2302 connected to GPIO #4".format(sys.argv[0])) sys.exit(2) dev_type = None if sys.argv[1] == "11": dev_type = DHT11 elif sys.argv[1] == "22": dev_type = DHT22 elif sys.argv[1] == "2302": dev_type = AM2302 else: print("invalid type, only 11, 22 and 2302 are supported for now!") sys.exit(3) DHTpin = int(sys.argv[2]) if DHTpin <= 0:
if DHT: DHT = DHT[0] typeDHT = int(DHT[0]) pinDHT = int(DHT[1]) if typeDHT not in [11, 22, 2302]: print("invalid type, only DHT11, DHT22 and AM2302 are supported.") sys.exit(3) if pinDHT <= 0 | pinDHT > 40: print("invalid GPIO pin#") sys.exit(3) print("Detect on wiringPi PIN #{0} for DHT sensor".format(pinDHT)) DHTreader.init() Addons["DHTreader"] = True if AD and Addons["PCF8591"]: channel = int(AD[0]) if channel in [0, 1, 2, 3]: value = IOboard.readPCF8591(channel) inV = 3.3*value/255 print("I2C PCF8591: channel {0} input: {1} voltage.".format(channel, inV)) sendCmd("sensor-update readPCF8591 %.2f" % (inV)) else: print("I2C PCF8591 should read from channel [0 | 1 | 2 | 3]") if DA and Addons["PCF8591"]: out = int(DA[0]) IOboard.writePCF8591(out)