コード例 #1
0
def read_light_value(addr=DEVICE):
    # Read data from I2C interface
    try:
        data = bus.read_i2c_block_data(addr,CONTINUOUS_HIGH_RES_MODE_1)
        return convertToNumber(data)
    except:
        text.error("read_light_value_error")
    return -1
コード例 #2
0
def read_moisture_value():
    try:
        GPIO.setup(PIN_MOISTURE, GPIO.IN)
        
        value = GPIO.input(PIN_MOISTURE)
        
        return 100 - (value * 100)
    except:
        text.error("read_moisture_error")
    return -1
コード例 #3
0
def read_value():
    global humidity, temperature
    try:
        h, t = dht.read_retry(dht.DHT22, DHT_PIN)
        humidity = h
        temperature = t
    except:
        text.error("read dht error")

    return humidity, temperature
コード例 #4
0
def Check_Settings_Changed():
    global last_settings_changed
    try:
        time = webservice.LoadSettingChanged(controller_id)
        if (time):
            changed = False
            settings_changed = datetime.datetime.strptime(
                time, "%Y-%m-%d %H:%M:%S")

            text.writeln("Check Settings Changes: " + str(settings_changed) +
                         " " + str(last_settings_changed))

            if (settings_changed != last_settings_changed):
                last_settings_changed = settings_changed
                changed = True
                Setup_Default_Settings()

    except:
        text.error("Check Settings Changes Error " + sys.exc_info()[0])
コード例 #5
0
def Update_Hardware_Status():
    try:
        data = {}

        data["moist"] = hardware.Get_Moisture_Status()
        data["humid"] = hardware.Get_Humidity_Status()
        data["temper"] = hardware.Get_Temperature_Status()
        data["lux"] = hardware.Get_Luminance_Status()

        data["light"] = hardware.Get_Light_Status()
        data["pump"] = hardware.Get_Pump_Status()
        data["aircon"] = hardware.Get_Aircon_Status()
        data["temp"] = hardware.Get_Temp_Status()
        data["fan"] = hardware.Get_Fan_Status()

        text.writeln("Update Status: " + str(data))

        webservice.UpdateStatus(controller_id, data)

    except:
        text.error("Update Status Error " + str(sys.exc_info()[0]))