matthewwall / weewx-sdr

weewx driver for software-defined radio
GNU General Public License v3.0
114 stars 74 forks source link

Added Support for Cotech 36-7959 Weatherstation, 433Mhz. #187

Open gremlin205 opened 3 months ago

gremlin205 commented 3 months ago

Also: SwitchDoc Labs Weather FT020T. Also: Sainlogic Weather Station WS019T Also: Sainlogic Weather Station FT0300 Also: Sainlogic Weather Station WS0310 (probably all current Sainlogic models) Also: Ragova WiFi Weather Station FT-0310 Also: NicetyMeter Weather Station 0366 (without Lux or UV index)

I am not sure the proper channel for this, but the following code will add support for the above devices when paired with the latest rtl_433 and rtl-sdr.

sdr.py

# JDR Added to support mixed format devices (RE US and METRICWX)
def to_C(v):
    if v is not None:
        v = (v - 32) / 1.8
    return v

class Cotech367959Packet(Packet):
    # This is for a  sensor array that identifies itself as
    # Cotech-367959. This configuration was tested on an Sainlogic  kit.

    # "time" : "2024-06-12 22:48:19", 
    # "model" : "Cotech-367959", 
    # "id" : 116, 
    # "battery_ok" : 1, 
    # "temperature_F" : 87.100, 
    # "humidity" : 45, 
    # "rain_mm" : 86.400, 
    # "wind_dir_deg" : 317, 
    # "wind_avg_m_s" : 0.400, 
    # "wind_max_m_s" : 0.700, 
    # "light_lux" : 10363, 
    # "uv" : 1.500, 
    # "mic" : 
    # "CRC"}  

    # {"time" : "2024-06-12 22:48:19", "model" : "Cotech-367959", "id" : 116, "battery_ok" : 1, "temperature_F" : 87.100, "humidity" : 45, "rain_mm" : 86.400, "wind_dir_deg" : 317, "wind_avg_m_s" : 0.400, "wind_max_m_s" : 0.700, "light_lux" : 10363, "uv" : 1.500, "mic" : "CRC"}

    IDENTIFIER = "Cotech-367959"

    @staticmethod
    def parse_json(obj):
        pkt = dict()
        pkt['dateTime'] = Packet.parse_time(obj.get('time'))
        pkt['usUnits'] = weewx.METRICWX
        pkt['station_id'] = obj.get('id')
        if 'temperature_F' in obj:
            pkt['temperature'] = to_C(Packet.get_float(obj, 'temperature_F'))
        elif 'temperature_C' in obj:
            pkt['temperature'] = Packet.get_float(obj, 'temperature_C')
        pkt['humidity'] = Packet.get_float(obj, 'humidity')
        pkt['wind_dir'] = Packet.get_float(obj, 'wind_dir_deg')
        pkt['wind_speed'] = Packet.get_float(obj, 'wind_avg_m_s')
        pkt['wind_gust'] = Packet.get_float(obj, 'wind_max_m_s')
        pkt['rain_total'] = Packet.get_float(obj, 'rain_mm')
        pkt['uv_index'] = Packet.get_float(obj, 'uv')
        pkt['luminosity'] = Packet.get_float(obj, 'light_lux')
        pkt['radiation'] = Packet.get_float(obj, 'light_lux')
        pkt['battery'] = 0 if Packet.get_int(obj, 'battery_ok') == 1 else 0
        return Cotech367959Packet.insert_ids(pkt)

    @staticmethod
    def insert_ids(pkt):
        station_id = pkt.pop('station_id', '0000')
        return Packet.add_identifiers(pkt, station_id, Cotech367959Packet.__name__)

weewx.conf

[SDR]
    # This section is for the software-defined radio driver.

    # The driver to use
    driver = user.sdr
    log_unknown_sensors = True
    log_unmapped_sensors = True

   [[sensor_map]]
        # Cotech-367959
        batteryStatus1 = battery.253.Cotech367959Packet
        outTemp = temperature.253.Cotech367959Packet
        outHumidity = humidity.253.Cotech367959Packet
        windSpeed = wind_speed.253.Cotech367959Packet
        windGust = wind_gust.253.Cotech367959Packet
        windDir = wind_dir.253.Cotech367959Packet
        UV = uv_index.253.Cotech367959Packet
        rain_total = rain_total.253.Cotech367959Packet
        radiation = luminosity.253.Cotech367959Packet
        illuminance = luminosity.253.Cotech367959Packet

[StdCalibrate]

    [[Corrections]] 
        radiation = radiation * 0.00789 if radiation > 0 else None

Enjoy!