Weewx and Grovepi

648 views
Skip to first unread message

Mike Whimick

unread,
Apr 28, 2016, 5:36:05 PM4/28/16
to weewx-user
Hello everyone

I am very new to to weewx and was wondering if I con use my Grovepi to send data to weewx.

If I can how do this?

I have searched but not found any information

Please note I only know a  little about programming

thanks

vince

unread,
Apr 28, 2016, 6:23:46 PM4/28/16
to weewx-user
On Thursday, April 28, 2016 at 2:36:05 PM UTC-7, Mike Whimick wrote:
I am very new to to weewx and was wondering if I con use my Grovepi to send data to weewx.


If the GrovePi site description of it being essentially a RasPi with sensors is accurate, it should run weewx ok if you install all the things weewx needs (see the weewx docs for a debian install for starters)


Please note I only know a  little about programming

 
ooh that might be a problem if you're asking how to use the GrovePi sensors themselves rather than having an external weather station....

mwall

unread,
Apr 28, 2016, 9:47:13 PM4/28/16
to weewx-user
On Thursday, April 28, 2016 at 5:36:05 PM UTC-4, Mike Whimick wrote:
Hello everyone

I am very new to to weewx and was wondering if I con use my Grovepi to send data to weewx.

If I can how do this?

you'll have to learn how to program in python.

it looks like grove industries has created a python interface that makes it easy to talk to their sensors.  instead of having to learn i2c, serial, or other interfaces, you just use the grovepi interface such as grovepi.digitalWrite

to make that work with weewx, you would write a weewx driver.  the weewx driver would simply call the grovepi functions to talk to the sensors.

for a really basic driver, put something like this in user/grovepi.py:

import time
import grovepi
import weewx.drivers

DRIVER_NAME = 'GrovePi'

def loader(config_dict, _):
    return GrovePiDriver(**config_dict[DRIVER_NAME])

class GrovePiDriver(weewx.drivers.AbstractDevice):
    def __init__(self, **stn_dict):
        self.poll_interval = int(stn_dict.get('poll_interval', 10)) # seconds
        self.air_temperature = 0
        self.air_sensor = 1
        grovepi.pinMode(self.air_sensor, 'INPUT')

    def hardware_name(self):
        return DRIVER_NAME

    def genLoopPackets(self):
        while True:
            packet = {
                'air_quality': grovepi.analogRead(self.air_sensor),
                'inTemp': grovepi.temp(self.air_temperature, '1.1')}
            yield packet
            time.sleep(self.poll_interval)

then in weewx.conf do this:

[Station]
    station_type = GrovePi
[GrovePi]
    poll_interval = 10
    driver = user.grovepi

then start weewx directly:

sudo weewxd /etc/weewx/weewx.conf

that should get you started. 

this example reads data from an air quality sensor at position 1 and a version 1.1 air temperature sensor at position 0.

m

Mike Whimick

unread,
Apr 29, 2016, 9:41:05 AM4/29/16
to weewx-user
Thankyou for your reply

It most most helpful.

Can you tell me in the import weewx.drivers I need to download any particular driver?

Also if I tweek you code would the dht sensor work?

Meanwhile I will try my hand at a little python scripting, which I am slowly learning

Whimick

mwall

unread,
Apr 29, 2016, 10:16:58 AM4/29/16
to weewx-user
On Friday, April 29, 2016 at 9:41:05 AM UTC-4, Mike Whimick wrote:
Can you tell me in the import weewx.drivers I need to download any particular driver?

i'm not sure what you mean.  'import weewx.drivers' is python code that means "i'm going to use code from the weewx.drivers module".  the weewx.drivers module defines the interface for weewx drivers, and it also contains drivers for some of the most common weather stations.

you don't have to download any additional drivers, because you are writing your own.
 
Also if I tweek you code would the dht sensor work?

i guess that depends how you tweek (sic) it ;)  twerk it and it will probably do many things you never imagined possible.

follow the pattern in the code i posted, but use the code from the grovepi examples for specific types of sensors:

https://github.com/DexterInd/GrovePi/tree/master/Software/Python

code for the dht is here:

https://github.com/DexterInd/GrovePi/blob/master/Software/Python/grove_dht_pro.py

so you probably want something like this (assuming you have the blue one):

    [packet['outTemp'], packet['outHumidity']] = grovepi.dht(self.th_sensor, 0)

Meanwhile I will try my hand at a little python scripting, which I am slowly learning

python is not difficult to learn, and there are many, many examples and tutorials.  please post when you get something running - it will help you learn faster and help others as well.

good luck!

m

Mike Whimick

unread,
Apr 29, 2016, 1:27:36 PM4/29/16
to weewx-user
I have just tried to run weewx after pling drivers in /usr/share/weewx/weewx/drivers/grovepi.py
 and I get this error

sudo weewxd /etc/weewx/weewx.conf
Traceback (most recent call last):
  File "/usr/bin/weewxd", line 64, in <module>
    weewx.engine.main(options, args)
  File "/usr/share/weewx/weewx/engine.py", line 853, in main
    engine = EngineClass(config_dict)
  File "/usr/share/weewx/weewx/engine.py", line 69, in __init__
    self.setupStation(config_dict)
  File "/usr/share/weewx/weewx/engine.py", line 92, in setupStation
    __import__(driver)
ImportError: No module named grovepi

mwall

unread,
Apr 29, 2016, 2:04:50 PM4/29/16
to weewx-user
On Friday, April 29, 2016 at 1:27:36 PM UTC-4, Mike Whimick wrote:
I have just tried to run weewx after pling drivers in /usr/share/weewx/weewx/drivers/grovepi.py
 and I get this error

mike,

the contents of the weewx 'drivers' directory will be overwritten when you update weewx, so keep all of your modifications in the user directory.  you should put your grovepi driver code in the weewx user directory:

/usr/share/weewx/user/grovepi.py

you will probably have to get the grovepi libraries into your python path too.  one way is something like this:

PYTHONPATH=/home/pi/Desktop/GrovePi/Software/Python weewxd /etc/weewx/weewx.conf

use the actual path to wherever you cloned the grovepi git repository.

m

Mike Whimick

unread,
Apr 30, 2016, 5:45:44 PM4/30/16
to weewx-user
Thanks your you help.

I have to re install my Raspberrypi Sd card today.

Weewx is now running after copying Grovepi.py and path as suggested, and adjusted weewx.conf so it look as below:

##############################################################################

[GrovePi]
    poll_interval = 10
    driver = user.grovepi


##############################################################################

 and added

[Station]
 
    # Set to type of station hardware. There must be a corresponding stanza
    # in this file with a 'driver' parameter indicating the driver to be used.
    station_type = GrovePi


Am I on the right track?

Do I need to adjust any other items?





Mike Whimick

unread,
May 2, 2016, 7:55:22 AM5/2/16
to weewx-user
Hi

I am trying to to write so dht (blue) sensor with my grovepi.

And with your help I have made this, that when I run weewx using, sudo weewxd /etc/weewx/weewx.conf weewx appears to start without showing any errors.

When I look at the index.html it still shows it as a simulation!

I have added
PYTHONPATH=/home/pi/Desktop/GrovePi/Software/Python as suggested

Can any one tell me if this driver will work, and if not tell what needs to be changed, or send me a working driver, so I can better understand it so I can add other sensors
.
I am trying to learn python as best I can but find it a little to understand.
Hoping soneone can help.
Script below:

import sys
import syslog

import time
import grovepi
import weewx.drivers
import weewx.wxformulas

DRIVER_NAME = 'GrovePi'
DRIVER_VERSION = '1.1'


def loader(config_dict, _):
    return GrovePiDriver(**config_dict[DRIVER_NAME])
   
sensor = 4  # The Sensor goes on digital port 4.

# temp_humidity_sensor_type
# Grove Base Kit comes with the blue sensor.
#blue = 0    # The Blue colored sensor.
#white = 1   # The White colored sensor.   

class GrovePiDriver(weewx.drivers.AbstractDevice):
    def __init__(self, **stn_dict):
        self.poll_interval = int(stn_dict.get('poll_interval', 10)) # seconds
        [temp,humidity] = grovepi.dht(sensor,0)
        self.dth_temp = 0
        #self.dht_sensor = 1
        grovepi.pinMode(self.dht_sensor, 'INPUT')


    def hardware_name(self):
        return DRIVER_NAME

    def genLoopPackets(self):
        while True:
            [packet['outtemp'], packet['outhum']] = grovepi.dht(self.dth_sensor, 0)
            yield packet
            time.sleep(self.poll_interval)

mwall

unread,
May 2, 2016, 8:12:50 AM5/2/16
to weewx-user


On Monday, May 2, 2016 at 7:55:22 AM UTC-4, Mike Whimick wrote:
Hi

I am trying to to write so dht (blue) sensor with my grovepi.

And with your help I have made this, that when I run weewx using, sudo weewxd /etc/weewx/weewx.conf weewx appears to start without showing any errors.

When I look at the index.html it still shows it as a simulation!


look for the 'station_type' in weewx.conf.  you must change it from 'Simulator' to 'GrovePi':

[Station]
    ...
    station_type = GrovePi

as for the driver, you only need something like this:

import time

import grovepi
import weewx.drivers


DRIVER_NAME = 'GrovePi'
DRIVER_VERSION = '0.1'

def loader(config_dict, _):
    return GrovePiDriver(**config_dict[
DRIVER_NAME])   

class GrovePiDriver(weewx.drivers.
AbstractDevice):

    def __init__(self, **stn_dict):
        self.poll_interval = int(stn_dict.get('poll_
interval', 10)) # seconds
        self.dht_sensor = 4 # sensor is on port 4
        grovepi.pinMode(self.dht_
sensor, 'INPUT')

    def hardware_name(self):
        return DRIVER_NAME

    def genLoopPackets(self):
        while True:

            packet = {'dateTime': int(time.time() + 0.5), 'usUnits': weewx.METRIC}
            [packet['outTemp'], packet['outHumidity']] = grovepi.dht(self.dht_sensor, 0)
            yield packet
            time.sleep(self.poll_interval)


don't just randomly add code - only add code that you actually need.

m

Mike Whimick

unread,
May 3, 2016, 5:36:17 PM5/3/16
to weewx-user
Thankyou for replying you are very helpful,

Ive have done as you asked and placed the drivers in /usr/share/weewx/user/grovepi.py

I also put the GrovepiDrivers that come with the GrovePi in /usr/share/weewx/weewx/drivers/grovepi.py
should they still be there?

and edited /etc/weewx/weewx.conf making sure they are as below:

Weewx still seems to be running in simulation mode and not using the weewx drivers,
at least as far as I know.

Is there any way to check, note I have used the sudo tail -f /var/log/syslog
which so far I do not understand.
I can post it if it helps

I have ** my location in this message

##############################################################################

#   This section is for information about the station.

[Station]
   
    # Description of the station location
    location = "Home, UK"
   
    # Latitude and longitude in decimal degrees
    latitude = **.267
    longitude = **.323
   
    # Altitude of the station, with unit it is in. This is downloaded from
    # from the station if the hardware supports it.
    altitude = 40, meter

   
    # Set to type of station hardware. There must be a corresponding stanza
    # in this file with a 'driver' parameter indicating the driver to be used.
    station_type = GrovePi
   
    # If you have a website, you may specify an URL
    #station_url = http://www.example.com
    /var/www/weewx/index.html
    # The start of the rain year (1=January; 10=October, etc.). This is
    # downloaded from the station if the hardware supports it.
    rain_year_start = 1
   
    # Start of week (0=Monday, 6=Sunday)
    week_start = 6


##############################################################################

[GrovePi]
    poll_interval = 10
    driver = user.grovepi
##############################################################################

I copied from index /var/www/weewx/index.html

About this weather station:
Location
Latitude:    *° 16.02' N
Longitude:    *° 19.38' W
Altitude:    131 feet
This station uses a Simulator, controlled by 'weewx',
an experimental weather software system written in Python.
Weewx was designed to be simple, fast, and easy to understand by leveraging modern software


I realy want to learn how to use weewx and to see it running with my Grovepi
which is fitted to my Raspberry Pi.
I am slowly getting to grips with python, but with some difficulty.
I have also purchased some books to help me.



mwall

unread,
May 3, 2016, 7:58:09 PM5/3/16
to weewx-user
On Tuesday, May 3, 2016 at 5:36:17 PM UTC-4, Mike Whimick wrote:
Ive have done as you asked and placed the drivers in /usr/share/weewx/user/grovepi.py

I also put the GrovepiDrivers that come with the GrovePi in /usr/share/weewx/weewx/drivers/grovepi.py
should they still be there?

no.  you should not add anything to the drivers directory.  remove any files that you put there.
 

Is there any way to check, note I have used the sudo tail -f /var/log/syslog
which so far I do not understand.
I can post it if it helps

the first thing you should do is stop weewx:

sudo /etc/init.d/weewx stop

it will be running with the simulator driver since you installed from the debian package.

the next thing is to make sure you are modifying the correct configuration file.  which weewx.conf did you modify?

finally, please post these things:

- the log output
- your weewx.conf file (remove any passwords before posting it)
- the file user/grovepi.py
- exactly the command you typed to start weewx
 
m

Mike Whimick

unread,
May 4, 2016, 4:41:29 AM5/4/16
to weewx-user
Hi m,

Thanks for your reply

I have done what you suggest and have sent a zip file with the files you asked for

Whimick
weewx.zip

Mike Whimick

unread,
May 5, 2016, 4:51:40 PM5/5/16
to weewx-user
Hi,
With all yor help I may be making progress

Firstly after some checking my DhT sensor was connected to D7 in my GrovePi so I changed this line

self.dht_sensor = 4 # sensor is on port 4 to self.dht_sensor = 7 # sensor is on port 7.

And it would appear that when I restart weewx the griver is loaded the throse and error as shown in the log
 
sudo tail -f /var/log/syslog
May  5 21:33:33 PiDex3 weewx[18676]: engine: Initializing weewx version 3.5.0
May  5 21:33:33 PiDex3 weewx[18676]: engine: Using Python 2.7.9 (default, Mar  8 2015, 00:52:26) #012[GCC 4.9.2]
May  5 21:33:33 PiDex3 weewx[18676]: engine: Platform Linux-4.1.19-v7+-armv7l-with-debian-8.0
May  5 21:33:33 PiDex3 weewx[18676]: engine: pid file is /var/run/weewx.pid
May  5 21:33:33 PiDex3 weewx[18680]: engine: Using configuration file /etc/weewx/weewx.conf
May  5 21:33:33 PiDex3 weewx[18680]: engine: Loading station type GrovePi (user.grovepi)
May  5 21:33:33 PiDex3 weewx[18680]: engine: Unable to load driver: 'module' object has no attribute 'pinMode'
May  5 21:33:33 PiDex3 weewx[18680]:     ****  Exiting...
May  5 21:33:33 PiDex3 weewx[18663]: Starting weewx weather system: weewx.
May  5 21:33:33 PiDex3 systemd[1]: Started LSB: weewx weather system.

I have looked over the internet to find about Pinmode, to see if I could find how correct the error, unfortunatlly its just a little to technical,
for me.

Can someone please explain in simple term what is wrong and how I can correct it.  I am slowly getting to understand python,(its hard going)

I gues it must lay in this section of code.

grovepi.pinMode(self.dht_sensor, 'INPUT')

Michael

mwall

unread,
May 5, 2016, 10:57:06 PM5/5/16
to weewx-user
On Thursday, May 5, 2016 at 4:51:40 PM UTC-4, Mike Whimick wrote:
Can someone please explain in simple term what is wrong and how I can correct it.  I am slowly getting to understand python,(its hard going)

the only way anyone can help is if you:

 - post the code
 - show how you invoked the program
 - post the program output
 - post the log

otherwise no one will have any way to help you.


I gues it must lay in this section of code.

grovepi.pinMode(self.dht_sensor, 'INPUT')

try commenting or removing the pinMode line.  that is not necessary, based on the examples at github:

https://github.com/DexterInd/GrovePi/blob/master/Software/Python/grove_dht_pro.py

m

Mike Whimick

unread,
May 6, 2016, 5:55:11 AM5/6/16
to weewx-user

Hi m,

Thank you for replying.

I have attached the file requested.

I use the :

sudo /etc/init.d/weewx start

sudo /etc/init.d/weewx stop

as the web page suggests

What output files do you need?

Michael


grovepi.py
syslog
weewx.conf

Andrew Milner

unread,
May 6, 2016, 6:11:02 AM5/6/16
to weewx-user
have you tried commenting out or removing the pinmode line as Mathew suggested earlier?

mwall

unread,
May 6, 2016, 6:17:02 AM5/6/16
to weewx-user
On Friday, May 6, 2016 at 5:55:11 AM UTC-4, Mike Whimick wrote:
Hi m,

Thank you for replying.

I have attached the file requested.

I use the :

sudo /etc/init.d/weewx start

sudo /etc/init.d/weewx stop

as the web page suggests


that is how you run weewx as a daemon, i.e., in the background.  once everything is working, you should run weewx as a daemon - that way it automatically runs when the system boots up.

however, when you are developing a driver or trying to diagnose a problem, you should run weewx directly, like this:

sudo weewxd /etc/weewx/weewx.conf

whether you run weewx directly or as a daemon, monitor the log like this:

sudo tail -f /var/log/syslog
 
so when you're developing you'll have three windows open: one to start/stop weewx, another to tail the log, and another to edit the driver.


What output files do you need?


first comment out the pinmode line, i.e., line 15 of your grovepi.py driver

then try running weewx again (directly, not as a daemon)

m

Mike Whimick

unread,
May 6, 2016, 10:25:25 AM5/6/16
to weewx-user
Yes, so the scrpits looks as below:

import time
import grovepi
import weewx.drivers

DRIVER_NAME = 'GrovePi'
DRIVER_VERSION = '0.1'

def loader(config_dict, _):
    return GrovePiDriver(**config_dict[DRIVER_NAME])   

class GrovePiDriver(weewx.drivers.AbstractDevice):
    def __init__(self, **stn_dict):
        self.poll_interval = int(stn_dict.get('poll_interval', 10)) # seconds
        self.dht_sensor = 7 # sensor is on port 7
        #grovepi.pinMode(self.dht_sensor, 'INPUT')


    def hardware_name(self):
        return DRIVER_NAME

    def genLoopPackets(self):
        while True:
            packet = {'dateTime': int(time.time() + 0.5), 'usUnits': weewx.METRIC}
            [packet['outTemp'], packet['outHumidity']] = grovepi.dht(self.dht_sensor, 0)
            yield packet
            time.sleep(self.poll_interval)

And this error is produced

sudo tail -f /var/log/syslog
May  6 15:20:57 PiDex3 weewx[10855]:     ****  'module' object has no attribute 'dht'
May  6 15:20:57 PiDex3 weewx[10855]:     ****  Traceback (most recent call last):
May  6 15:20:57 PiDex3 weewx[10855]:     ****    File "/usr/share/weewx/weewx/engine.py", line 859, in main
May  6 15:20:57 PiDex3 weewx[10855]:     ****      engine.run()
May  6 15:20:57 PiDex3 weewx[10855]:     ****    File "/usr/share/weewx/weewx/engine.py", line 182, in run
May  6 15:20:57 PiDex3 weewx[10855]:     ****      for packet in self.console.genLoopPackets():
May  6 15:20:57 PiDex3 weewx[10855]:     ****    File "/usr/share/weewx/user/grovepi.py", line 26, in genLoopPackets
May  6 15:20:57 PiDex3 weewx[10855]:     ****      [packet['outTemp'], packet['outHumidity']] = grovepi.dht(self.dht_sensor, 0)
May  6 15:20:57 PiDex3 weewx[10855]:     ****  AttributeError: 'module' object has no attribute 'dht'
May  6 15:20:57 PiDex3 weewx[10855]:     ****  Exiting.

Andrew Milner

unread,
May 6, 2016, 11:53:35 AM5/6/16
to weewx-user
shouldn't it be something more like:

while True:
           [temperature, humidity] = grovepi.dht(self.dht_sensor,0)
            packet = {'dateTime': int(time.time() + 0.5), 'usUnits': weewx.METRIC,
                            'outTemp': temperature, 'outHumidity': humidity}

???

Mike Whimick

unread,
May 6, 2016, 2:40:37 PM5/6/16
to weewx-user
Hi Andrew,

thanks for your suggestion, unfornunatly it does work. see below.


import time
import grovepi
import weewx.drivers

DRIVER_NAME = 'GrovePi'
DRIVER_VERSION = '0.2'


def loader(config_dict, _):
    return GrovePiDriver(**config_dict[DRIVER_NAME])   

class GrovePiDriver(weewx.drivers.AbstractDevice):
    def __init__(self, **stn_dict):
        self.poll_interval = int(stn_dict.get('poll_interval', 10)) # seconds
        self.dht_sensor = 7 # sensor is on port 7
        grovepi.pinMode(self.dht_sensor, 'INPUT')

    def hardware_name(self):
        return DRIVER_NAME

    @property
    def genLoopPackets(self):

    while True:
           [temperature, humidity] = grovepi.dht(self.dht_sensor,0)
            packet = {'dateTime': int(time.time() + 0.5), 'usUnits': weewx.METRIC,
                     'outTemp': temperature, 'outHumidity': humidity}
            yield packet
            time.sleep(self.poll_interval)


Starting weewx (via systemctl): weewx.service.


pi@PiDex3:~ $ sudo tail -f /var/log/syslog
May  6 19:32:40 PiDex3 weewx[26696]:     ****      engine = EngineClass(config_dict)
May  6 19:32:40 PiDex3 weewx[26696]:     ****    File "/usr/share/weewx/weewx/engine.py", line 69, in __in        it__
May  6 19:32:40 PiDex3 weewx[26696]:     ****      self.setupStation(config_dict)
May  6 19:32:40 PiDex3 weewx[26696]:     ****    File "/usr/share/weewx/weewx/engine.py", line 92, in setu        pStation
May  6 19:32:40 PiDex3 weewx[26696]:     ****      __import__(driver)
May  6 19:32:40 PiDex3 weewx[26696]:     ****    File "/usr/share/weewx/user/grovepi.py", line 24
May  6 19:32:40 PiDex3 weewx[26696]:     ****      packet = {'dateTime': int(time.time() + 0.5), 'usUnits'        : weewx.METRIC,
May  6 19:32:40 PiDex3 weewx[26696]:     ****      ^
May  6 19:32:40 PiDex3 weewx[26696]:     ****  IndentationError: unexpected indent
May  6 19:32:40 PiDex3 weewx[26696]:     ****  Exiting.


gjr80

unread,
May 6, 2016, 4:05:54 PM5/6/16
to weewx-user
Hi,

I think you have more fundamental problems. Your grovepi.py that you have posted has an import statement:

import grovepi

Is that not the grovepi.py from Dexter Industries GitHub repo that has all code for interacting with the grovepi? Where is that grovepi.py file? Is it on you system?

I would not be calling my driver file (grovepi.py) the same name as the python library provided to control the device (grovepi.py), you are just asking to trip yourself up. I would be calling my driver file something different, say grove.py, and then I would make sure that grovepi.py from Dexter Industries is somewhere on my system where Python can acces it, It can be in the same folder as your driver. Then get your imports sorted so that the methods you are calling in your driver are available.

Gary

Mike Whimick

unread,
May 6, 2016, 6:38:44 PM5/6/16
to weewx-user
Gary,

Thankyou for your suggestion.

I will rename weewx driver grovepi to something else.

I will try and see what happens.

Michael

Mike Whimick

unread,
May 7, 2016, 6:11:31 PM5/7/16
to weewx-user
Hi Gary,

It looks like your suggestion has solved my problem it has connects and collects Temperature and humidity data.

My next Data set will be pressure from a grove_i2c_barometic_sensor BMP085,   I have a vague idea how to go about it, I will try to write some python code tomorrow and test.

Based how the Temp and Hum.. sensors work I have came up with this

#!/usr/bin/env python
import time
from grovepi import *
import grovepi
import smbus
import RPi.GPIO as GPIO
from grove_i2c_barometic_sensor import BMP085
import weewx.drivers

DRIVER_NAME = 'WhimickPi'
DRIVER_VERSION = '0.2'
DEBUG_RAW = 0

def loader(config_dict, _):
    return WhimickPiDriver(**config_dict[DRIVER_NAME])   

class WhimickPiDriver(weewx.drivers.AbstractDevice):

    def __init__(self, **stn_dict):
        self.poll_interval = int(stn_dict.get('poll_interval', 10)) # seconds
        self.dht_sensor = 7 # sensor is on port 7
        grovepi.pinMode(self.dht_sensor, 'INPUT')
        self.bmp_pressure = BMP085(0x77, 1)
        grovepi.pinMode(self.bmp_pressure, 'INPUT')

    def hardware_name(self):
        return DRIVER_NAME

    def genLoopPackets(self):
        while True:
            packet = {'dateTime': int(time.time() + 0.5), 'usUnits': weewx.METRIC}
            [packet['outTemp'], packet['outHumidity']] = grovepi.dht(self.dht_sensor, 0)
            [packet['pressure']] = grovepi.bmp_pressure(bmp_readPressure() / 100.00)
             yield packet
            time.sleep(self.poll_interval)

Before I try it are there any suggestion please?

Would it be better to define a pressure fuction, I have started to try and learn how the def function works.

Michael

gjr80

unread,
May 7, 2016, 6:33:28 PM5/7/16
to weewx-user
Hi Michael,

Thank is good progress. I think you will get far better input on developing a driver from Matthew. If you haven't already looked at them have a look at some of the other weewx drivers in /usr/share/weewx/drivers, they may give you some good pointers as to how you might structure you code. You may find some of the more complex drivers more daunting, file size is a fair indicator of complexity, but as your Python knowledge increases they should make more sense.

The statements import grovepi and from grovepi import * are sort of doing the same thing; both are letting you use the resources in the grovepi library, the first means you need to prefix and resources with grovepi. eg grovepi.pinMode() whereas the second means you can just use the resource name eg pinMode(). Really is a personal preference, first can be easier to see where resources are coming from but leads to longer lines of code, second hides where resources are coming from but gives more compact code. Doesn't hurt having them both there though.

As for using a seperate function, really a personal preference I think, I would be just getting some code to work to start off with, then once it is working and again as your Python knowledge increases, look at how it can be tidied up/improved/made more readable/robust etc.

Good luck.

Gary

Mike Whimick

unread,
May 8, 2016, 5:25:11 PM5/8/16
to weewx-user
Hi All
I finally have a working Grovepi Driver, and I would like to thank every one who helped with my project.

The code is attatched:

Sadly it does suddenly exit with not iterable error.

I have put an error trap in the code, but it my not be good enough, "as not iterable" error crops up possibly caused by the dht sensor nan error.


May  8 21:10:27 dex weewx[6625]: reportengine: copied 0 files to /var/www/weewx
May  8 21:10:48 dex weewx[6625]: engine: Shutting down StdReport thread
May  8 21:10:48 dex weewx[6625]: engine: Caught unrecoverable exception in engine:
May  8 21:10:48 dex weewx[6625]:     ****  'int' object is not iterable
May  8 21:10:48 dex weewx[6625]:     ****  Traceback (most recent call last):
May  8 21:10:48 dex weewx[6625]:     ****    File "/usr/share/weewx/weewx/engine.py", line 859, in main
May  8 21:10:48 dex weewx[6625]:     ****      engine.run()
May  8 21:10:48 dex weewx[6625]:     ****    File "/usr/share/weewx/weewx/engine.py", line 182, in run
May  8 21:10:48 dex weewx[6625]:     ****      for packet in self.console.genLoopPackets():
May  8 21:10:48 dex weewx[6625]:     ****    File "/usr/share/weewx/user/whimickpi3.py", line 62, in genLoopPackets
May  8 21:10:48 dex weewx[6625]:     ****      [packet['outTemp'], packet['outHumidity']] = grovepi.dht(self.dht_sensor, 0)
May  8 21:10:48 dex weewx[6625]:     ****  TypeError: 'int' object is not iterable
May  8 21:10:48 dex weewx[6625]:     ****  Exiting.

Does any one have any suggestion so to prevent weewx suddenly exiting.

Can Weewx support data fron a Grove analog light sensor?

Once again thankyou your help

Michael
 
whimickpi3.py

gjr80

unread,
May 8, 2016, 7:28:32 PM5/8/16
to weewx-user
Hi Michael,

Have a look at dht() in grovepi.py, you will see that it can return either a python list containing temperature and humidity or, under certain conditions, it can return the value -1. A python list is iterable whereas a number is not, hence the line

[packet['outTemp'], packet['outHumidity']] = grovepi.dht(self.dht_sensor, 0)

will fail when -1 is returned by grovepi.dht(). You need to beef up you code to handle both cases. Probably a number of ways you could do it, one way is putting a try .. except around the above line and then catch the TypeError when it is not iterable.

Gary

mwall

unread,
May 8, 2016, 7:43:47 PM5/8/16
to weewx-user
On Sunday, May 8, 2016 at 5:25:11 PM UTC-4, Mike Whimick wrote:
May  8 21:10:48 dex weewx[6625]:     ****    File "/usr/share/weewx/user/whimickpi3.py", line 62, in genLoopPackets
May  8 21:10:48 dex weewx[6625]:     ****      [packet['outTemp'], packet['outHumidity']] = grovepi.dht(self.dht_sensor, 0)
May  8 21:10:48 dex weewx[6625]:     ****  TypeError: 'int' object is not iterable
May  8 21:10:48 dex weewx[6625]:     ****  Exiting.

Does any one have any suggestion so to prevent weewx suddenly exiting.

gary has it right.  try something like this:

class WhimickPiDriver(weewx.drivers.AbstractDevice):
    def __init__(self, **stn_dict):
        self.poll_interval = int(stn_dict.get('poll_interval', 10))  # seconds
        self.dht_sensor = 7  # sensor is on port 7
        grovepi.pinMode(self.dht_sensor, 'INPUT')
        self.bmp = BMP085(0x77, 1)

       
    def hardware_name(self):
        return DRIVER_NAME

    def genLoopPackets(self):
        while True:
            packet = {'dateTime': int(time.time() + 0.5), 'usUnits': weewx.METRIC}
            try:

                [packet['outTemp'], packet['outHumidity']] = grovepi.dht(self.dht_sensor, 0)
                packet['pressure'] = self.bmp.readPressure()/100.0
                yield packet
            except Exception, e:
                syslog.syslog(syslog.LOG_ERR, "read sensors failed: %s" % e)
            time.sleep(self.poll_interval)

a few things to note:
- if the call to pinMode fails, then comment it out
- you should read the pressure value in genLoopPackets, not __init__.  if you do it in __init__ then you get it only once.

m

Andrew Milner

unread,
May 8, 2016, 9:58:01 PM5/8/16
to weewx-user
What do you mean by "can weewx support data from a Grove analog light sensor"??  What exactly do you want weewx to do with the data??  The data can be read if you write the driver to fill the loop packets - as you have already found out.  The data can be stored in either an existing database field which you re-purpose or in additional fields if you redefine the schema (|see customisation guide).  The data once in the database can be reported (see customisation guide) and so on.  The sky is the limit depending on the amount of work and effort you want to put in, and what you are trying to achieve.  The general answer is therefore 'yes' - but you will more than likely have to put in the effort to make it deliver exactly what you want.  How do you plan on using the optical sensor - what data will it actually provide??

Mike Whimick

unread,
May 9, 2016, 6:25:56 PM5/9/16
to weewx-user
Thanks for the replies,

the script will run but will crash after a few minutes producing this error.

May  9 22:03:45 dex weewx[9630]: engine: Caught unrecoverable exception in engine:
May  9 22:03:45 dex weewx[9630]:     ****  global name 'syslog' is not defined
May  9 22:03:45 dex weewx[9630]:     ****  Traceback (most recent call last):
May  9 22:03:45 dex weewx[9630]:     ****    File "/usr/share/weewx/weewx/engine.py", line 859, in main
May  9 22:03:45 dex weewx[9630]:     ****      engine.run()
May  9 22:03:45 dex weewx[9630]:     ****    File "/usr/share/weewx/weewx/engine.py", line 182, in run
May  9 22:03:45 dex weewx[9630]:     ****      for packet in self.console.genLoopPackets():
May  9 22:03:45 dex weewx[9630]:     ****    File "/usr/share/weewx/user/whimickpi6.py", line 84, in genLoopPackets
May  9 22:03:45 dex weewx[9630]:     ****      syslog.syslog(syslog.LOG_ERR, "read sensors failed: %s" % e)
May  9 22:03:45 dex weewx[9630]:     ****  NameError: global name 'syslog' is not defined
May  9 22:03:45 dex weewx[9630]:     ****  Exiting.

I have placed an led off command so an led flashes when the data is updated

                yield packet
        digitalWrite(led, 0)
            except Exception, e:

would this be causing any problems.

I notice that this code is what Grove recomend for collecting data from the dht sensor
[temp, hum] = dht(dht_sensor_port, dht_sensor_type)  # Get the temperature and Humidity from the DHT sensor

would this be a better option?

As for the light sensor the aim would be to use it to measure sunlight.   And at this stage I think I will leave that for later

I have attatched the code, not I have also been playing with an OLED, which I have commented out.

Learning python is a bit hard going, I'm slowing getting there.

Michael

whimickpi6.py

mwall

unread,
May 9, 2016, 7:19:07 PM5/9/16
to weewx-user
On Monday, May 9, 2016 at 6:25:56 PM UTC-4, Mike Whimick wrote:
May  9 22:03:45 dex weewx[9630]:     ****    File "/usr/share/weewx/user/whimickpi6.py", line 84, in genLoopPackets
May  9 22:03:45 dex weewx[9630]:     ****      syslog.syslog(syslog.LOG_ERR, "read sensors failed: %s" % e)
May  9 22:03:45 dex weewx[9630]:     ****  NameError: global name 'syslog' is not defined
May  9 22:03:45 dex weewx[9630]:     ****  Exiting.

mike, the stack trace tells you where to look: line 84 in your code.  did you import syslog somewhere before you used it at line 84?

 
I have placed an led off command so an led flashes when the data is updated

                yield packet
        digitalWrite(led, 0)
            except Exception, e:

would this be causing any problems.

what do you think?  what does your experience tell you from running the code?

 
I notice that this code is what Grove recomend for collecting data from the dht sensor
[temp, hum] = dht(dht_sensor_port, dht_sensor_type)  # Get the temperature and Humidity from the DHT sensor

would this be a better option?

why do you think it would be any different?

 
As for the light sensor the aim would be to use it to measure sunlight.   And at this stage I think I will leave that for later

I have attatched the code, not I have also been playing with an OLED, which I have commented out.

Learning python is a bit hard going, I'm slowing getting there.

you might want to take a python tutorial.

as you learn, try running little bits of python code directly in the python interpreter.

when you get a bit of code to work, then add it to the driver.

don't add any code until you understand exactly what it does and why it is written the way it is written.

m

Mike Whimick

unread,
May 10, 2016, 6:36:05 PM5/10/16
to weewx-user
Thanks for your comments.

As I said earlier I have puchased some books about python, and researched useful items on the net.
I have also been using some of the tutorials, to try and make sense of things.

An example how to use the def function, which I'm still finding hard to grasp, how ever I will keep trying.

I have also started to use pycharm communtity, which I have found useful to help solve issues.

Tomorrow I will be taking the day off, as I vollenteer at a charity and help run a Cub Scout Pack, which I have been doing for many years.   It is also my intention to use this project with in the Cub Pack, as part of a technology badge.

Michael

vince

unread,
May 10, 2016, 7:06:43 PM5/10/16
to weewx-user
Mike - if you have a couple bucks try https://www.udemy.com/complete-python-bootcamp/ or one of the other udemy python classes, look like there a lot of highly rated ones.  Another place is edx.org - one class is https://www.edx.org/course/learn-program-using-python-utarlingtonx-cse1309x as an example, the other online place is coursears - one example class is https://www.coursera.org/learn/python/home/info?source=cdpv2

I haven't done any of these, but have done edx and udemy classes in the past and had pretty good luck.  Probably worth a look.

Mike Whimick

unread,
May 21, 2016, 7:38:11 AM5/21/16
to weewx-user
Hi All,

I have been playing with my Grovepi for some days now.
And all is going well but for
number = bus.read_i2c_block_data(address, 1)
IOError: [Errno 5] Input/output error
Exiting.

Weewx will some time run for a hour or more before exiting with 12c or dht error.

I use this code

except TypeError:
    pass
time.sleep(self.poll_interval)

can any one suggest a better error trap.

Thanks

Mike Whimick

unread,
May 24, 2016, 3:20:33 PM5/24/16
to weewx-user


Hi All,

Having played with my GrovePi and weewx, I decided that I would try to import data using a csv file and the wx fileparse extention.
I have adapted from sbcWeather-master.
how ever I am getting these errors

May 24 20:14:34 dex weewx[30376]: fileparse: cannot read value for 'datetime': invalid literal for float(): 2016-05-24 20:14:33
May 24 20:14:34 dex weewx[30376]: engine: 2016-05-24 20:14:35 BST (1464117275) LOOP value 'pressure' 1013.91 outside limits (24.0, 34.5)

using date from this weewx.csv.

I have tried to fing out what the problem is without any luck.

Can any one please help
RaspGrove_csv.py
wxdata.csv

gjr80

unread,
May 24, 2016, 6:13:46 PM5/24/16
to weewx-user
Hi Mike,

The first error is because you are writing a human readable date/time to the file whereas the file parse is expecting to read a Unix timestamp (ie a number; the number of seconds since midnight 1 January 1970).

The second error will be due to StdQC min/max settings in weewx.conf. I suspect that fileparse is expecting obs with units the same as used in the weewx database, sorry but not in front of my PC so can't check. Have a read of any comments in the fileparse code. Weewx is interpreting you hPa value as inHg and of course believes it to be invalid so hence ignores it. The solution may be to provide pressure in inHg in your csv file, or you may be able to tell fileparse what units/unit system to expect.

Gary

gjr80

unread,
May 25, 2016, 2:18:25 AM5/25/16
to weewx-user
Found time to have a read of fileparse.py and its all in the comments; lines 25-26 say you need to use US customary units. Alternatively, if you were prepared to deviate from the norm it would a very simple matter to get fileparse.py to accept metric input.

Gary

Mike Whimick

unread,
May 25, 2016, 3:33:42 PM5/25/16
to weewx-user
Thanks for your replies.

I was playing the fileParse driver to see if could understand that better than the driver I was working on.

I have decided that with the file Parse drivewr I have most likely bitten off more than I can chew.   So I think I will continue learning on my current driver which at least works with Temperature, humidy, and light(solar), my next sensor will be to add a rain(bucket)sensor based around a magnetic switch.
so I need to find the right approach, by learing from other people's drivers, and adapting code to work with my GrovePi..
I would be greatfull for any thoughts.

Mike Whimick

unread,
Jun 10, 2016, 12:29:13 PM6/10/16
to weewx-user
Hi All,

I have been making  some progress with a Grovepi Driver, and have these sensors working

DTH, Light,Barometer, 96x96 oled, and a led to tell me its working.

I am now working on trying to get a magnetic switch, whiich I will use as the basis of a rain-tipper guage.

and writing and adapting some code, I have treid to intergrate it using multiprocessing, but can get it to work.

I am most likely going about it the wrong way.

Can any kind programmer help, the grove pi switch scrpit is below, and my driver file is attatched.

Thanks for any help.

#! /usr/bin/env python

import time
import grovepi
import RPi.GPIO as GPIO
from grovepi import *

# Connect the Grove Tilt Switch to digital port D3
# SIG,NC,VCC,GND
tilt_switch = 3

grovepi.pinMode(tilt_switch,"INPUT")

while True:
try:
print grovepi.digitalRead(tilt_switch)
time.sleep(.5)

except IOError:
print "Error"




RaspGrove_switch.py

Andrew Milner

unread,
Jun 10, 2016, 1:01:48 PM6/10/16
to weewx-user
Don't you think these Grovepi driver development issues are more suited to the weewx-development forum rather than the weewx-user forum? 

gjr80

unread,
Jun 10, 2016, 6:40:55 PM6/10/16
to weewx-user
Hi Mike,

Can't say i'll be much help but what error do you get? The except statement will be swallowing any error, what trace do you get without the try..except.

Gary

Mike Whimick

unread,
Jun 11, 2016, 6:33:41 AM6/11/16
to weewx-user
Thank for the reply I have re-poseted it to weewx-developopment.



On Thursday, April 28, 2016 at 10:36:05 PM UTC+1, Mike Whimick wrote:
Hello everyone

I am very new to to weewx and was wondering if I con use my Grovepi to send data to weewx.

If I can how do this?

I have searched but not found any information

Please note I only know a  little about programming

thanks
Reply all
Reply to author
Forward
0 new messages