Exemplo n.º 1
0
def getSensorList(rpgConfig, mcp):
    try:
        print("Getting Sensor Info...")

        # Returns a list of sensors
        mySensors = []

        # Read sensor info from the .ini file
        # That file contains the constants you can change to match your wiring
        if rpgConfig is None:
            rpgConfig = RpgConfig()

        # Set up the sensors. Store them in the mySensors list
        sensorList = rpgConfig.get("sensor_list" + "_" +
                                   socket.gethostname()).split(',')
        for sensorSection in sensorList:
            sensorName = sensorSection + "_" + socket.gethostname()
            sensortype = rpgConfig.getSensorType(sensorName)

            if sensortype == "dht":
                mySensors.append(Sensor.DhtSensor(sensorName))

            if sensortype == "photo" or sensortype == "moisture":
                mySensors.append(Sensor.McpSensor(sensorName, mcp))
        return mySensors
    except Exception as ex:
        # Handle other exceptions
        print(traceback.format_exc())
        print(type(ex))
        print(ex.args)
        print(ex)