Beispiel #1
0
def load_sensor():
	global attemp_DHT, attemp_GP2Y10
	global humidity, density, temp, pressure

	time_now = datetime.now()

	# 每 2 秒读一次
	# 读取 dht 湿度,温度;bmp085 温度,气压
	if (time_now - attemp_DHT).seconds > 10:
		humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)	# 时间间隔两秒
		temp = (bmp.readTemperature() + temperature) / 2
		pressure = bmp.readPressure()
		attemp_DHT = time_now
	# 读取 pm2.5浓度,每 5 秒读一次
	if (time_now - attemp_GP2Y10).seconds > 30:
		density = ZhyuIoT_GP2Y10.read(ZhyuIoT_GP2Y10.GP2Y1051A, 5)	# if density is None:	attemp = 1	ATTEMPS = 5
		attemp_GP2Y10 = time_now
Beispiel #2
0
def load_sensor():
	global attemp_DHT, attemp_GP2Y10
	global humidity, density, temp, pressure

	time_now = datetime.now()

	# 每 2 秒读一次
	# 读取 dht 湿度,温度;bmp085 温度,气压
	if (time_now - attemp_DHT).seconds > 10:
		attemp_DHT = time_now
		# humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) # 时间间隔两秒
		# adafruit dht 库有问题,反复执行 pi_version 函数,open('/proc/cpuinfo', 'r') 会导致出错
		humidity, temperature = Adafruit_DHT.read_retry(sensor, pin, 15, 2, platform)	# 时间间隔两秒
		temp = (bmp.readTemperature() + temperature) / 2
		pressure = bmp.readPressure()
	# 读取 pm2.5浓度,每 5 秒读一次
	if (time_now - attemp_GP2Y10).seconds > 30:
		attemp_GP2Y10 = time_now
		density = ZhyuIoT_GP2Y10.read(ZhyuIoT_GP2Y10.GP2Y1051A, 5, gp2y10)	# if density is None: attemp = 1 ATTEMPS = 5
Beispiel #3
0
def load_sensor():
    global attemp_DHT, attemp_GP2Y10
    global humidity, density, temp, pressure

    time_now = datetime.now()

    # 每 2 秒读一次
    # 读取 dht 湿度,温度;bmp085 温度,气压
    if (time_now - attemp_DHT).seconds > 10:
        attemp_DHT = time_now
        # humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) # 时间间隔两秒
        # adafruit dht 库有问题,反复执行 pi_version 函数,open('/proc/cpuinfo', 'r') 会导致出错
        humidity, temperature = Adafruit_DHT.read_retry(
            sensor, pin, 15, 2, platform)  # 时间间隔两秒
        temp = (bmp.readTemperature() + temperature) / 2
        pressure = bmp.readPressure()
    # 读取 pm2.5浓度,每 5 秒读一次
    if (time_now - attemp_GP2Y10).seconds > 30:
        attemp_GP2Y10 = time_now
        density = ZhyuIoT_GP2Y10.read(
            ZhyuIoT_GP2Y10.GP2Y1051A, 5,
            gp2y10)  # if density is None: attemp = 1 ATTEMPS = 5
Beispiel #4
0
#!/usr/bin/python
import sys

import ZhyuIoT_GP2Y10

# Parse command line parameters.
if len(sys.argv) == 1:
    sensor = ZhyuIoT_GP2Y10.GP2Y1051A
elif len(sys.argv) == 2 and sys.argv[1] in ZhyuIoT_GP2Y10.SENSORS:
    sensor = sensor_args[sys.argv[1]]
else:
    print 'usage: sudo ./ZhyuIoT_GP2Y10.py [51]'
    print 'example: sudo ./ZhyuIoT_GP2Y10.py - Read from a GP2Y10 51A'
    sys.exit(1)

# Try to grab a sensor reading.
density = ZhyuIoT_GP2Y10.read(sensor, 5)

if density is not None:
    print '{0:0.1f} ug/m3'.format(density)
else:
    print 'Failed to get reading. Try again!'
Beispiel #5
0
    print 'usage: sudo ./zhyu.py userkey [DeviceId]'
    print 'example: sudo ./zhyu.py userkey pi - Read from optical duster sensor GP2Y10 then send the data to ZhyuIoT with specified device id'
    sys.exit(1)

print 'Logging sensor measurements to ZhyuIoT every {0} seconds.'.format(FREQUENCY_SECONDS)
print 'Press Ctrl-C to quit.'

sensor_lists = None
ATTEMPS = 5
import ZhyuIoT_GP2Y10
while True:
    if sensor_lists == None:
        SENSOR_DESCRIPTIONS = ({'type': DUSTER_SENSOR_TYPE, 'typeName': '粉尘传感器', 'modelName': 'GP2Y10', 'unit': u'ug/m3'}, )
        sensor_lists = get_sensor_lists(userkey, deviceid, SENSOR_DESCRIPTIONS)
    # Attempt to get sensor reading.
    density = ZhyuIoT_GP2Y10.read(ZhyuIoT_GP2Y10.GP2Y1051A, 5)
    # Skip to the next reading if a valid measurement couldn't be taken.
    # This might happen if the CPU is under a lot of load and the sensor
    # can't be reliably read (timing is critical to read the sensor).
    attemp = 1
    if density is None:
        if attemp <= ATTEMPS:
            attemp += 1
            time.sleep(2)
            continue
        else:
            print 'Failed to get data from sensor after attempting {0} times.'.format(ATTEMPS)
            sys.exit(1)

    print 'PM 2.5: {0:0.1f} ug/m3'.format(density)
Beispiel #6
0
#!/usr/bin/python
import sys

import ZhyuIoT_GP2Y10


# Parse command line parameters.
if len(sys.argv) == 1:
  sensor = ZhyuIoT_GP2Y10.GP2Y1051A
elif len(sys.argv) == 2 and sys.argv[1] in ZhyuIoT_GP2Y10.SENSORS:
    sensor = sensor_args[sys.argv[1]]
else:
    print 'usage: sudo ./ZhyuIoT_GP2Y10.py [51]'
    print 'example: sudo ./ZhyuIoT_GP2Y10.py - Read from a GP2Y10 51A'
    sys.exit(1)

# Try to grab a sensor reading.
density = ZhyuIoT_GP2Y10.read(sensor, 5)

if density is not None:
    print '{0:0.1f} ug/m3'.format(density)
else:
    print 'Failed to get reading. Try again!'