Hello All,
For the past few months I have been playing around at writing a new
driver. This week I have decided to change my current driver that uses
FileParse (which works ok-ish), to using loop packets, which I believe to
be more effient.
Using my efforts and borrowing from other drivers I have created a small
part of my driver that uses data from a BME280 sensor, plugged into a
SwitchDoc labs Groveweather, the connect onto my GrovePi by the l2c port.
So far my efforts at least runs on Weewx and as far as I know with out
throwing any errors which I check by using sudo tail -f /var/log/syslog.
How ever it does not appear to port date into Weewx.
Please can some-one take a look at my code and point in the right direction
too getting it to work, so I may later add more sensors to it. It is
likely I have made some howling mistakes, for which I am sory.
Many thanks Michael.
--
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.
#!/usr/bin/python
#
# $Revision: 1.01$
# $Author: WhimickRH $
# $Date: 2016-10-20 $
# $SwitchdocGrove
# $Error logging enabled
# --------------------------IMPORT DEPENDENCIES---------------------------
from __future__ import with_statement
import grovepi
import RPi.GPIO as GPIO
from grovepi import *
import math
import time
from time import sleep
from datetime import datetime
from time import strftime, localtime
import weewx.drivers
import weewx.wxformulas
import syslog
import sys
sys.path.append('/home/pi/Adafruit_Python_BME280')
from Adafruit_BME280 import *
# --------------------------SENSOR SETTINGS---------------------------
rev = GPIO.RPI_REVISION
if rev == 2 or rev == 3:
bus = smbus.SMBus(1)
else:
bus = smbus.SMBus(0)
temperature = 0
Temp_F = 0
pressure = 0
inHg = 0
hPa = 0
outHumidity = 0
DRIVER_NAME = 'SwitchdocGrove'
DRIVER_VERSION = '1.01'
def loader(config_dict, _):
return SwitchdocGroveDriver(**config_dict[DRIVER_NAME])
# Read the data from the sensors
class SwitchdocGroveDriver(weewx.drivers.AbstractDevice):
def __init__(self, poll_interval=5, **stn_dict):
self.poll_interval = int(poll_interval) # seconds
#self.red_led = 3
#self.blue_led = 4
self.bme280 = BME280(mode=BME280_OSAMPLE_8)
def hardware_name(self):
return DRIVER_NAME
def bme280(self):
while True:
temperature = round(self.bme280.read_temperature(), 2)
hPa = round(self.bme280.read_pressure() / 100, 2)
outHumidity = round(self.bme280.read_humidity(), 2)
return [temperature, hPa, outHumidity]
def genLoopPackets(self):
global temperature, Temp_F, pressure, inHg, hPa, outHumidity
while True:
packet = {'dateTime': int(time.time() + 0.5), 'usUnits': weewx.US}
try:
[temperature, hPa, outHumidity] = self.bme280(self)
packet['outTemp'] = temperature
packet['pressure'] = hPa
packet['outHumidity'] = outHumidity
except (IOError, TypeError) as e:
continue
else:
yield packet
time.sleep(self.poll_interval)