On Saturday, November 24, 2018 at 12:11:39 PM UTC-5, KattanaD wrote:
>
> Installed weewx 3.8.2 using the script on my raspberry pi
> I would like to add a co2 sensor to my weather station.
> im using acurite sensors and rtl_433 currently
>
> I have a Cozir gc-0017 co2 sensor 20% range
> serial sensor connected to usb to TTL cable
>

create a service that reads data directly from the sensor. 

the service would be a file user/cozir.py that looks something like this:

import serial
import syslog
import weewx.engine

class CozirService(weewx.engine.StdService):
    def __init__(self, engine, config_dict):
        d = config_dict.get('Cozir', {})
        port = d.get('port', '/dev/ttyS0')
        self.serial_port = serial.Serial(port)
        self.serial_port.write("M 4\r\n")
        self.serial_port.write("K 2\r\n") # put the device in polling mode
    def handle_new_loop(self, event):
        self.get_data(event.packet)
    def handle_new_archive(self, event):
        self.get_data(event.record)
    def get_data(self, data):
        v = None
        try:
            x = self.serial_port.write("Z\r\n")
            x = self.serial_port.read()
            v = float(x[2:8]
            data['co2'] = v # value in ppm
        except serial.serialutil.SerialException, e:
            syslog.syslog(syslog.LOG_ERR, "fail: %s" % e)


add an entry in the weewx configuration to specify the port:

[Cozir]
    port = /dev/ttyUSB0


enable the service in your weewx configuration file something like this:


[Engine]

    [[Services]]

        ...

        data_services = user.cozir.CozirService

        ...


then restart weewx


that should get you started :)


m


-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to