I am very new to to weewx and was wondering if I con use my Grovepi to send data to weewx.
Please note I only know a little about programming
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?
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
I have just tried to run weewx after pling drivers in /usr/share/weewx/weewx/drivers/grovepi.py
and I get this error
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!
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?
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
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')
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?
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
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
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
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.
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.
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
Gary
#! /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"
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