Example #1
0
def main():
	rospy.init_node("Measure_CO2", anonymous=True)
	CO2_int_pub = rospy.Publisher("CO2", CO2, queue_size=1000)
	loop_rate = rospy.Rate(RATE)#Set the refresh rate in Hertz
	CO2_value = CO2()
	sensor_attached = True
	try:#Try to connect the sensor
		c = Cozir('/dev/ttyUSB0')#Create the sensor object
		c.set_filter(16)#Set the filter to 16
	except:
		rospy.loginfo("CO2 sensor not attached")
		sensor_attached = False
	
	CO2_value.sensor_attached = sensor_attached;
	
	temperature_calibration_factor = 1.0
	humidity_calibration_factor = 1.0

	while not rospy.is_shutdown():
		if(sensor_attached):
			CO2_value.CO2level = round(c.read_CO2(),1)
			CO2_value.temperature = round(c.read_temperature() *temperature_calibration_factor,1)
			CO2_value.humidity = round(c.read_humidity()* humidity_calibration_factor,1)
		else:#If the sensor is not connected the sensor will give 0.0 measurements
			CO2_value.CO2level = 0.0
			CO2_value.temperature = 0.0
			CO2_value.humidity = 0.0
			
		CO2_int_pub.publish(CO2_value)
		loop_rate.sleep()
Example #2
0
    def __init__(self, input_dev, testing=False):
        super(InputModule, self).__init__(input_dev,
                                          testing=testing,
                                          name=__name__)

        if not testing:
            from cozir import Cozir

            self.uart_location = input_dev.uart_location
            self.sensor = Cozir(self.uart_location)
Example #3
0
    def __init__(self, input_dev, testing=False):
        super(InputModule, self).__init__()
        self.setup_logger(testing=testing, name=__name__, input_dev=input_dev)

        if not testing:
            from cozir import Cozir

            self.device_measurements = db_retrieve_table_daemon(
                DeviceMeasurements).filter(
                    DeviceMeasurements.device_id == input_dev.unique_id)

            self.uart_location = input_dev.uart_location
            self.sensor = Cozir(self.uart_location)
Example #4
0
    def __init__(self, input_dev, testing=False):
        super(COZIRSensor, self).__init__()
        self.logger = logging.getLogger("mycodo.inputs.cozir")
        self._co2 = None
        self._dew_point = None
        self._humidity = None
        self._temperature = None

        if not testing:
            from cozir import Cozir
            self.logger = logging.getLogger(
                "mycodo.inputs.cozir_{id}".format(id=input_dev.id))
            self.device_loc = input_dev.device_loc
            self.convert_to_unit = input_dev.convert_to_unit
            self.sensor = Cozir(self.device_loc)
Example #5
0
    def __init__(self, input_dev, testing=False):
        super(InputModule, self).__init__()
        self.logger = logging.getLogger("mycodo.inputs.cozir_co2")

        if not testing:
            from cozir import Cozir
            self.logger = logging.getLogger("mycodo.cozir_co2_{id}".format(
                id=input_dev.unique_id.split('-')[0]))

            self.device_measurements = db_retrieve_table_daemon(
                DeviceMeasurements).filter(
                    DeviceMeasurements.device_id == input_dev.unique_id)

            self.uart_location = input_dev.uart_location
            self.sensor = Cozir(self.uart_location)
Example #6
0
    def initialize_input(self):
        from cozir import Cozir

        self.sensor = Cozir(self.input_dev.uart_location)
Example #7
0
def get_co2_sensor(device):
    return Cozir(device)