Esempio n. 1
0
def readTemperature(sensorId):
    tfile = open("/sys/bus/w1/devices/" + sensorId + "/w1_slave") 
    #tfile = open("temp_demo.txt")
    text = tfile.read() 
    tfile.close() 
    secondline = text.split("\n")[1] 
    temperaturedata = secondline.split(" ")[9] 
    temperature = float(temperaturedata[2:])
    temperature = temperature / 1000 
    return temperature


sensorsToMonitor = getThermometerList()
publishIntervalMins = sensor_common.config.getint('intervals','temp_publish_mins')
start = sensor_common.getStart(publishIntervalMins)
sensor_common.waitUntil(start, True)

while True:
    sensorReadings = []
    #Create space in sensorsReadings for readings for each sensor
    for sensorId in sensorsToMonitor:
        sensorReadings.append([])
    #For each minute between now and the final reading, take a reading
    for x in range(publishIntervalMins):
        start = start + datetime.timedelta(seconds=60)
        sensor_common.waitUntil(start, True)
        print("Reading @ " + str(datetime.datetime.now()))
        for y in range(len(sensorsToMonitor)):
            currentTemp = readTemperature(sensorsToMonitor[y])
            sensorReadings[y].append(currentTemp)
Esempio n. 2
0
    SPIMOSI = 24
    SPICS = 25
     
    # set up the SPI interface pins
    GPIO.setup(SPIMOSI, GPIO.OUT)
    GPIO.setup(SPIMISO, GPIO.IN)
    GPIO.setup(SPICLK, GPIO.OUT)
    GPIO.setup(SPICS, GPIO.OUT)

    sensorsToMonitor = []
    for x in range(sensor_common.config.getint('adc_sensors', 'count')):
        sensorsToMonitor.append(sensor_common.config.get('adc_sensors', str(x)))
    #print sensorsToMonitor

    readingIntervalMins = sensor_common.config.getint('intervals','soil_reading_mins')
    start = sensor_common.getStart(readingIntervalMins)
    sensor_common.waitUntil(start, True)
 
    while True:
        #Read and publish for each sensor
        print("Publishing @ " + str(datetime.datetime.now()))
        for i in range(len(sensorsToMonitor)):
            sensorId = sensorsToMonitor[i]
            sensorReading = readadc(i, SPICLK, SPIMOSI, SPIMISO, SPICS)
            moisturePerc = 100.0 - ((sensorReading / 4096.0) * 100.0)
            message = sensor_common.enqueueSensorMessage(moisturePerc, sensorId, start)
            print("Publishing : " + str(message))        
        #Wait until next reading point
        sys.stdout.flush()
        start = start + datetime.timedelta(seconds=(readingIntervalMins * 60))
        sensor_common.waitUntil(start, True)