Exemple #1
0
def update_data():
    """ function to update temp, humidity and Alarm data on display """
    global update_interval, temperature, unit

    threading.Timer(
        update_interval,
        update_data).start()  # to autorun function once every update interval

    humidity, temperature = sensorRead.get_TempHum()
    time = datetime.now().strftime('%b-%d-%Y %H:%M:%S')
    ui.label_updateTime.setText(time)

    if (unit == 1 and temperature !=
            None):  # if unit is set to degF convert temperature to degF
        temperature = sensorRead.todegF(temperature)

    if (temperature == None):  # handling data not being sent
        ui.lcd_temperature.display("Err")
    else:
        ui.lcd_temperature.display(temperature)

    if (humidity == None):  # handling data not being sent
        ui.lcd_humidity.display("Err")
    else:
        ui.lcd_humidity.display(humidity)

    alarm_check()
    update_last_temp()
    update_avg_temp()
    update_max_temp()
    update_min_temp()
    update_last_hum()
    update_avg_hum()
    update_max_hum()
    update_min_hum()
def addDataToDb():
    """ function to update temp, humidity into database 
    the timestamp is split into different keys for year,month , day, hour, min and sec 
    as tinydb cannot read in the python datetime type"""
    global dbSamplingInterval, docId

    threading.Timer(
        dbSamplingInterval,
        addDataToDb).start()  # to autorun function once every update interval

    humidity, temperature = sensorRead.get_TempHum(
    )  #read temperature and humidity
    if (temperature == None):
        temperature = -1
    if (humidity == None):
        humidity = -1
    db.insert({
        'timestamp_year': datetime.now().year,
        'timestamp_month': datetime.now().month,
        'timestamp_day': datetime.now().day,
        'timestamp_hour': datetime.now().hour,
        'timestamp_minute': datetime.now().minute,
        'timestamp_second': datetime.now().second,
        'temperature': temperature,
        'humidity': humidity
    })
def publishTempHumidity():
    """" Function to publish temp and humidity data to AWS using MQTT"""
    global dbSamplingInterval,topic
    threading.Timer(dbSamplingInterval,publishTempHumidity).start() # to autorun function once every update interval
    ts=datetime.now()
    h,t= sensorRead.get_TempHum()
    msg = '"ts": "{}", "Temperature": "{}", "Humidity": "{}"'.format(ts, t,h)
    msg = '{'+msg+'}'
    myAWSIoTMQTTClient.publish(topic, msg, 1)
Exemple #4
0
def getData(unit):
    """ function to get latest data from sensors , 
    accounts for unit change from the webpage and
    converts temperature values accordingly"""
    h,t= sensorRead.get_TempHum()
    if(t==None):
        t=-1
    if(h==None):
        h=-1
    if(unit==1):
        t=sensorRead.todegF(t)
    return (str(round(t,2))+','+str(round(h,2)))