示例#1
0
def heartbeat(request):
    cfg.watchdog = 0
    output = {}
    output['b'] = cfg.blue
    output['y'] = cfg.yellow
    output['c'] = cfg.chocks
    output['g'] = cfg.green
    output['v'] = cfg.video_status
    output['l'] = cfg.left_motor
    output['r'] = cfg.right_motor
    output['i1'] = hw.input_one_read()
    output['i2'] = hw.input_two_read()
    output['i3'] = hw.input_three_read()
    output['i4'] = hw.input_four_read()
    output['a1'] = hw.analog_one_read()
    output['a2'] = hw.analog_two_read()
    output['a3'] = hw.analog_three_read()
    output['a4'] = hw.analog_four_read()
    return response.json(output)
示例#2
0
文件: dht11.py 项目: sopoour/pi_robot
#!/usr/bin/python
import RPi.GPIO as GPIO
import sys
import Adafruit_DHT
import io_wrapper as hw

sensor = Adafruit_DHT.DHT11
DHT11_pin = 16

#TODO: right not properly reading, maybe use analog rather than input? Figure out what's wrong with line 16
try:
    state = hw.input_one_read()

    if state == 1:
        print("Ready to sense temp & humidity")
        humidity, temperature = Adafruit_DHT.read_retry(sensor, DHT11_pin)
        print("Got Data")
        if humidity is not None and temperature is not None:
            print('Temperature: {0:0.1f} C  Humidity: {1:0.1f} %'.format(
                temperature, humidity))
        else:
            print('Failed to get reading from the sensor. Try again!')

except OSError as err:
    print("OS error: {0}".format(err))
except:
    print("Unexpected error:", sys.exc_info()[0])
    raise
finally:
    print("cleaning up RFID")
    GPIO.cleanup()