Tom, Gary
Got it working. Now just need to remove about 10 digits after the decimal
in the outHumidity and convert the temperature from Celsius to Fahrenheit.
Also found that I had to run weewxd as python3 and not python.
The code that is working is below, suggestions on the humidity and
temperature issues welcome -
========================extra_sensors_service
# Weewx Service to gather data from Adafruit_DHT. DHT22 Sensor  RUN AS
python3
import syslog
import weewx
import time
import os
from weewx.wxengine import StdService
import Adafruit_DHT as DHT

DHT_SENSOR = Adafruit_DHT.DHT22
DHT_PIN = 4
DHT22_PIN = 4

class ExtraSensorsService(StdService):
    def __init__(self, engine, config_dict):
        super(ExtraSensorsService, self).__init__(engine, config_dict)
        d = config_dict.get('ExtraSensorsService', {})
        # Read from config which pin to use on the RPI GPIO
        # Defaults to 4
        self.DHT22_PIN = d.get('DHT22_PIN', 4)
        # Use the loop packet event as that allows data to still get into
the WeeWX database
        # as well as supporting a OLED module on the RPI
        self.bind(weewx.NEW_LOOP_PACKET, self.load_data)

    def load_data(self, event):
#       try:
#            self.get_bmp180(event)
            self.get_dht22(event)
#       except Exception, e:
#            syslog.syslog(syslog.LOG_ERR, "extrasensors: cannot read
value: %s" % e)

    # Get DHT22 data
    def get_DHT22(self, event):
        humidity, temperature = DHT.read_retry(DHT.DHT22, self.DHT22_PIN)
        if humidity is not None:
            syslog.syslog(syslog.LOG_DEBUG, "extrasensors: found humidity
value of %s %%" % humidity)
            event.packet['inHumidity'] = float(humidity)
        if temperature is not None:
            syslog.syslog(syslog.LOG_DEBUG, "extrasensors: found
temperature value of %s C" % temperature)
            # NOTE: stores as celsius
            event.packet['inTemp'] = float(temperature)
========================

Michael H Grossie
[email protected]


On Wed, Sep 2, 2020 at 7:01 PM Tom Keffer <[email protected]> wrote:

> Tom,
>> Is this the line you think I should remove from the
>> extra_sensors_service.py -
>>
>>
>> *except Exception, e:            syslog.syslog(syslog.LOG_ERR,
>> "extrasensors: cannot read value: %s" % e) *
>>
>
> Yes (along with its corresponding 'try' statement).
>
> It appears that you also have another "DHT" that is undefined. Removing
> the exception statement will show you exactly where it is. What you want in
> its place... I have no idea. Maybe your variable DHT_SENSOR?
>
> Michael, this would go a lot faster if you do a critical review of your
> code, rather than relying on remote debugging.
>
> -tk
>
> -tk
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "weewx-user" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/weewx-user/nsLIaQaK7IU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/weewx-user/CAPq0zECe0n8u%3D21mQtWEAaBEdrsBB%2Bx16tj%2BZCwdiB_7udTn3w%40mail.gmail.com
> <https://groups.google.com/d/msgid/weewx-user/CAPq0zECe0n8u%3D21mQtWEAaBEdrsBB%2Bx16tj%2BZCwdiB_7udTn3w%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/CAJBcQpX6PxJaV%2BKiZi315FJQ9-5tBPiOLi8s0wehHctbv-PaYA%40mail.gmail.com.

Reply via email to