[weewx-user] Re: Problems updating my Driver

2017-11-11 Thread 'Mike Whimick' via weewx-user

>
> Thank you for replying
>

Here are the logs as requested.
I hope it helps solve my problem

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 weewx-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
#!/usr/bin/python
#
#   $ Revision2B: beta 003 $
#   $ Author: WhimickRH $
#   $ US - UK $
#   $ Date: 2017-11-10
#   $
#   $ Raspi_Met Version 2B WEEWX Beta 003 $
#   $ For For GrovePi Weather Station $
#   $ And weather Display CSV output$
#\

# ---IMPORT DEPENDENCIES-

from __future__ import with_statement
import os
import os.path
import sys
import syslog
import numpy as np
import time
import datetime
import cPickle
import logging
import random
import threading
import multiprocessing
import csv
import shutil

# ---GROVEPI BOARD AND SENSORS---

import smbus
import RPi.GPIO as GPIO
import grovepi
from grovepi import *
import BMP280.BMP280 as BMP280

# ---WEEWX DRIVERS---

import weeutil.weeutil
import weewx.drivers
import weewx.wxformulas

# ---PATH AND MODULES

sys.path.append('/home/pi/Weather_Sensors')
import Air_Sensors
import SDL_Pi_SI1145
import SI1145Lux
from grove_i2c_temp_hum_hdc1000 import HDC1000
import SDL_DS3231
import Wind_Rain6

# ---GROVEPI BOARD & SENSOR SET UP---

rev = GPIO.RPI_REVISION
if rev == 2 or rev == 3:
	bus = smbus.SMBus(1)
else:
	bus = smbus.SMBus(0)

GPIO.setwarnings(False)

# ---RESET LEDS--

green_led = 4
digitalWrite(green_led, 0)

red_led = 3
digitalWrite(red_led, 0)

# ---ANALOG SENSORS--

Water = 0		# Pin 15 is A0 Port. Grove - Water_Sensor(LeafWetness)
Moisture = 1# Pin 16 is A1 Port. Grove - Moisture_Sensor(PlantPot)

grovepi.pinMode(Water, "INPUT")  # Grove - Water_Sensor(LeafWetness)
grovepi.pinMode(Moisture, "INPUT")   # Grove - Moisture Sensor(PlantPot)

# ---SUNLIGHT SENSOR Si1145--

# sunsensor = SI1145.SI1145()
sunsensor = SDL_Pi_SI1145.SDL_Pi_SI1145()

# ---12C SENSORS-

BMP_sensor = BMP280.BMP280()  # GROVE 12C TEMPERATURE-HUMID-BAROMOMETER

hdc = HDC1000()
hdc.Config()

# ---RTL DS3231 RTC--

ds3231 = SDL_DS3231.SDL_DS3231(1, 0x68)

# ---VARIABLES---

record_no = 0
water_sensor = 0
moisture_sensor = 0
ws = 0
rain_mm = 0

# ---ERROR LOGGING---

logging.basicConfig(filename='/home/pi/WxRam/Raspi_Met2WX_Error.txt', filemode='a', level=logging.ERROR,
	format='%(asctime)s %(levelname)s %(name)s %(message)s')
logger=logging.getLogger(__name__)

# ---GROVEPI WEATHER STATION-

DRIVER_NAME = 'Raspi_Met2WX'
DRIVER_VERSION = '003'

def loader(config_dict, engine):
	return Raspi_Met2WXDriver(**config_dict[DRIVER_NAME])
	
def confeditor_loader():
	return Raspi_Met2WXConfEditor()

def logmsg(level, msg):
	syslog.syslog(level, 'Raspi_Met2WX: %s' % msg)

def logdbg(msg):
	logmsg(syslog.LOG_DEBUG, msg)

def loginf(msg):
	logmsg(syslog.LOG_INFO, msg)

def logerr(msg):
	logmsg(syslog.LOG_ERR, msg)

class Raspi_Met2WXDriver(weewx.drivers.AbstractDevice):
	
	def __init__(self, **stn_dict):
		
		loginf('driver version is %s' % DRIVER_VERSION)
		
		self.loop_interval = float(stn_dict.get('loop_interval', 5))
		self.Software_Version = "Raspi_Met Version 2B Beta 003"
		
		self.starttime = time.time()
		self.start_hour = int(time.strftime("%H"))
		
		self.record_no = record_no
		self.na = ""
		
		self.system_temp_C = 0
		self.system_temp_F = 0
		
		self.outTemp_C = 0
		self.outTemp_F = 0
		self.inTemp_C = 0
		self.inTemp_F = 0
		
		self.barometer = 0
		self.inHg = 0
		self.mspl = 0
		self.mspl_inHg = 0
		self.altitude = 0
		
	def hardware_name(self):
		return DRIVER_NAME
		
# ---READ SDL_DS3231 TIME
	"""
	def ds3231_time(self):
		
		self.rtc_time = "%s" % ds3231.read_datetime()
		self.rtc_temp = ds3231.getTemp()
		ds3231_t = ds3231.read_datetime()
		self.epoch_dt = int(time.mktime(time.strptime(ds3231_t.strftime("%Y-%m-%d %H:%M:%S"), "%Y-%m-%d %H:%M:%S")))
		GPIO.cleanup()
		# print("Times",self.rtc_time, self.rtc_time, self.epoch)
		# 

[weewx-user] Problems updating my Driver

2017-11-09 Thread 'Mike Whimick' via weewx-user
Hi All,

Over the past week I have been trying to update my Driver that I use with 
my Raspberry Pi3 and GrovePi board.

The problem I have is that it appears to load up and then stops and shows:

Nov  9 23:10:07 RaspiDexmet2 weewx[3252]: engine: Starting up weewx version 
3.7.1
Nov  9 23:10:07 RaspiDexmet2 weewx[3252]: engine: Starting main packet loop.


Can anyone please advise as to what I am doing wrong?
I have uploaded at shortened version of my driver,, hope someone may help 
solve the problem

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 weewx-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
#!/usr/bin/python
#
#   $ Revision2B: beta 001 $
#   $ Author: WhimickRH $
#   $ US - UK $
#   $ Date: 2017-11-09
#   $
#   $ Raspi_Met Version 2B WEEWX Beta 001 $
#   $ For For GrovePi Weather Station $
#   $ And weather Display CSV output$
#

# ---IMPORT DEPENDENCIES-

from __future__ import with_statement
import os
import os.path
import sys
import syslog
import numpy as np
import time
import datetime
import cPickle
import logging
import random
import threading
import multiprocessing
import csv
import shutil

# ---GROVEPI BOARD AND SENSORS---

import smbus
import RPi.GPIO as GPIO
import grovepi
from grovepi import *
# import BMP280.BMP280 as BMP280

# ---WEEWX DRIVERS---

import weeutil.weeutil
import weewx.drivers
import weewx.wxformulas

# ---PATH AND MODULES
"""
sys.path.append('/home/pi/Weather_Sensors')
import Air_Sensors
import SDL_Pi_SI1145
import SI1145Lux
from grove_i2c_temp_hum_hdc1000 import HDC1000
import SDL_DS3231
import Wind_Rain6
"""
# ---GROVEPI BOARD & SENSOR SET UP---

rev = GPIO.RPI_REVISION
if rev == 2 or rev == 3:
	bus = smbus.SMBus(1)
else:
	bus = smbus.SMBus(0)

GPIO.setwarnings(False)

"""
# ---RESET LEDS--

green_led = 4
digitalWrite(green_led, 0)

red_led = 3
digitalWrite(red_led, 0)

# ---ANALOG SENSORS--

Water = 0		# Pin 15 is A0 Port. Grove - Water_Sensor(LeafWetness)
Moisture = 1# Pin 16 is A1 Port. Grove - Moisture_Sensor(PlantPot)

grovepi.pinMode(Water, "INPUT")  # Grove - Water_Sensor(LeafWetness)
grovepi.pinMode(Moisture, "INPUT")   # Grove - Moisture Sensor(PlantPot)

# ---SUNLIGHT SENSOR Si1145--

# sunsensor = SI1145.SI1145()
sunsensor = SDL_Pi_SI1145.SDL_Pi_SI1145()

# ---12C SENSORS-

bmp280 = BMP280.BMP280()  # GROVE 12C TEMPERATURE-HUMID-BAROMOMETER
hdc = HDC1000()
hdc.Config()
"""
# ---RTL DS3231 RTC--

# ds3231 = SDL_DS3231.SDL_DS3231(1, 0x68)

# ---VARIABLES---

record_no = 0
water_sensor = 0
moisture_sensor = 0
ws = 0
rain_mm = 0

# ---ERROR LOGGING---


# ---GROVEPI WEATHER STATION-

DRIVER_NAME = 'Raspi_Met2WX'
DRIVER_VERSION = '001'

def loader(config_dict, engine):
	return Raspi_Met2WXDriver(**config_dict[DRIVER_NAME])
	
def confeditor_loader():
	return Raspi_Met2WXConfEditor()

class Raspi_Met2WXDriver(weewx.drivers.AbstractDevice):
	
	def __init__(self, **stn_dict):
		self.loop_interval = float(stn_dict.get('loop_interval', 5))
		self.Software_Version = "Raspi_Met Version 2B Beta 001"
		
		self.starttime = time.time()
		self.start_hour = int(time.strftime("%H"))
		
		self.record_no = record_no
		self.na = ""
		
		self.system_temp_C = 0
		self.system_temp_F = 0
		
		self.outTemp_C = 0
		self.outTemp_F = 0
		self.inTemp_C = 0
		self.inTemp_F = 0
		
		self.barometer = 0
		self.inHg = 0
		self.mspl = 0
		self.mspl_inHg = 0
		self.altitude = 0
		
	def hardware_name(self):
		return DRIVER_NAME
		
		
# ---READ SDL_DS3231 TIME
	"""
	def ds3231_time(self):
		self.rtc_time = "%s" % ds3231.read_datetime()
		self.rtc_temp = ds3231.getTemp()
		ds3231_t = ds3231.read_datetime()
		self.epoch = int(time.mktime(time.strptime(ds3231_t.strftime("%Y-%m-%d %H:%M:%S"), "%Y-%m-%d %H:%M:%S")))
		GPIO.cleanup()
		# print("Times",self.rtc_time, self.rtc_time, self.epoch)
		# DATE TIME---
		

[weewx-user] Re: Forcast Problem

2017-01-08 Thread 'Mike Whimick' via weewx-user
Thankyou for replying.

I think that I may have forecat working now, how ever I have not been able 
to add it to the standard skin, despite following instructions on the wilki 
page and searching this group.

Can some kind person post some example code so I may do it.   Or better 
still a complete Standard skin folder with forcast correctly setup.

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 weewx-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[weewx-user] Re: Forcast Problem

2017-01-02 Thread 'Mike Whimick' via weewx-user
Thanks for replying,

Sadley I'm still not able to get it to work.

I have installed the latest version today.

Has any one managed to get to work from the UK metoffice if so please can 
the post how the set it up.

My API key works and I tried it using the web page suggest. I also copied 
it into the config, so it looks as below. 

[[UKMO]]
enable = true
# An API key is required to access the UK Met Office forecasts.
# Create an account and obtain datapoint access here:


http://datapoint.metoffice.gov.uk/public/data/val/wxfcs/all/json/03772?res=3hourly=##
# The location is one of the 5,000 or so locationIDs in the UK
# location = London

# How often to download the forecast, in seconds
interval = 10800

This brings up HEATHROW

but throw many error.

-- 
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 weewx-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[weewx-user] Re: Weewx to weatherdisplay

2016-11-27 Thread 'Mike Whimick' via weewx-user

Hi Topher,

At this moment in time I am not using weewx-wd.

What I have done is to add this function to my weewx driver.

Which creates a clientraw_wx.txt to tme ramdisk I have on my pi3.

The # 
01-2-34567-8-9-101112--13
  
is just so I can keep track of the variables I have used so far.

There order and I took from WD's clientrawdescription.txt in WD for windows 
folder,   I also search the internet for more details,
its far from perfect, but seem to work(ish).

Sadly my programming skills are very limited and the py code could well be 
improved by some one with more skills than mine

The code is called by using self.clientraw().

My driver uses a GrovePi Board and Grove sensors and a Switchdocs Labs 
GroveWeatherPi, and Maplin Wind and Rain sensors, which are called by using 
a modified version of the weather rack code.

def clientraw(self):
ID_code = 12345
null = "--"
d_m = time.strftime("%d %m")
wd_time = time.strftime("%H:%M:%S")
st_name = "Whimick Met"
# eor = "!!EOR!!"
eor = "!!C10.37S28!!"
# 
01-2-34567-8-9-101112--13
wxdat = [ID_code, knot, knot, degrees, outTemp, outHumidity, hPa, 
rain, null, null, null, null, inTemp, null,
null, null, null, null, null, null, system_temp, null, 
null, null, null, null, null, null, null,
wd_time, st_name, null, radiation, d_m, eor]
# 
-141516171819---20---212223242526272829
# -3132

cl_raw = open('/home/weewx/wxram/clientraw_wx.txt', 'w')
for wxdat in wxdat:
# print "%s" % wxdat,
client = "%s " % wxdat
cl_raw.write(client)

else:
cl_raw.close()
return

I hope this helps
regards 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 weewx-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
#!/usr/bin/python
#
#   $Revision: 1.2$
#   $Author: WhimickRH $
#   $Date: 2016-11-09 $
#   $Whimick_Met
#   $Weewx, OLED & CSV

# --IMPORT DEPENDENCIES---

import RPi.GPIO as GPIO
from grovepi import *
import grovepi
import Adafruit_BMP.BMP280 as BMP280
import grove_oled
import weewx.drivers
import weewx.wxformulas
import smbus
import time
from datetime import datetime
from time import sleep
import random
import sys

sys.path.append('/home/pi/WxDrivers')

# import Adafruit_BMP.BMP280 as BMP280
from grove_i2c_temp_hum_hdc1000 import HDC1000
import SDL_DS3231
import Wind_Rain as Wind_Rain

# --SETTINGS---

rev = GPIO.RPI_REVISION
if rev == 2 or rev == 3:
	bus = smbus.SMBus(1)
else:
	bus = smbus.SMBus(0)

# GPIO Numbering Mode GPIO.BCM
anenometerPin = 18
rainPin = 17

# constants
SDL_MODE_INTERNAL_AD = 0
SDL_MODE_I2C_ADS1015 = 1

# sample mode means return immediately.  THe wind speed is averaged at sampleTime or when you ask, whichever is longer
SDL_MODE_SAMPLE = 0
# Delay mode means to wait for sampleTime and the average after that time.
SDL_MODE_DELAY = 1

weathervane = Wind_Rain.Wind_Rain(anenometerPin, rainPin, 0, 0, SDL_MODE_I2C_ADS1015)

weathervane.setWindMode(SDL_MODE_SAMPLE, 5.0)
# weathervane.setWindMode(SDL_MODE_DELAY, 5.0)

# -Initialize the OLED 

grove_oled.oled_init()
grove_oled.oled_clearDisplay()
grove_oled.oled_setNormalDisplay()
grove_oled.oled_setVerticalMode()
time.sleep(.1)

# -VAIRIABLES-

outTemp = 0
outHumidity = 0

degrees = 0
volts = 0

rain = 0

inTemp = 0
hPa = 0
sealevel = 0
altitude = 0

radiation = 0
leafWet1 = 0

system_temp = 0

# -UPDATE DS3231--

current_time = time.time()

# DS3231/AT24C32 Setup
filename = time.strftime("%Y-%m-%d%H:%M:%SRTCTest") + ".txt"
starttime = datetime.utcnow()
ds3231 = SDL_DS3231.SDL_DS3231(1, 0x68)

try:
	# comment out the next line after the clock has been initialized
	# ds3231.write_now()
	print "DS3231=\t\t%s" % ds3231.read_datetime()
	for x in range(0, 4):
		value = random.randint(0, 255)
		print "address = %i writing value=%i" % (x, value)
		ds3231.write_AT24C32_byte(x, value)
		print "reading first 4 addresses"
	for x in range(0, 4):
		print "address = %i value = %i" % (x, ds3231.read_AT24C32_byte(x))
	print "- "
except IOError as e:
	# print "I/O error({0}): {1}".format(e.errno, e.strerror)
	pass
# do the AT24C32 eeprom

# -SETUP SENSORS---

blue_led = 4
bmp280 = BMP280.BMP280()

[weewx-user] Re: Weewx to weatherdisplay

2016-11-13 Thread 'Mike Whimick' via weewx-user
Hi All,
I am still playing with weewxwd and have foud that looking at the log for 
Weather Display it show an error
'--' is not a valid integer value.

Does any one know how this could be fixed, it looks like a error created by 
weewxwd

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 weewx-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[weewx-user] Weewx to weatherdisplay

2016-10-27 Thread 'Mike Whimick' via weewx-user
Hi All,

Has any one managed to conect Weatherdisplay windows version to weewx, so 
WD recieves it's data from weewx through a home network.

I have installed and have running the weewxwd-1.0.0 extention, but so fare 
not been able to work how to connect WD to the clientraw.txt in my 
Raspberry Pi

If you can please can please can you explain how to do it.
Regards Whimick

-- 
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 weewx-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[weewx-user] Try to create a new driver

2016-10-20 Thread 'Mike Whimick' via weewx-user
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 weewx-user+unsubscr...@googlegroups.com.
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)


[weewx-user] Please help progamming a Maplin Anemometer

2016-08-01 Thread 'Mike Whimick' via weewx-user
Hello again,

During the past few days I have been trying to write code so to use a 
Maplin Anemometer, which uses a magentic switch to send pulses as it 
rotates.

Which is connected to my GrovePi.

I have been trying to adapt ppm_counter.py that was posted earlier in this 
group.  The code uses GPIO.inputs, and the Grovepi uses 
grovepi.digitalRead(2) to read the sensor.

I have been trying to adapt the code so it will work with my GrovePi D2 
input, and so far I have not been able to get a wind speed reading.

I have included both ppm_counter.py, and my attempt, in the hope someone 
make some suggestions

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 weewx-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
#!/usr/bin/python

#  ppm_counter.py
#
#  This was written to use the Raspberry Pi as a weather station. Using
#  Argent Data systems wind instruments, we connect on one of the Pi's
#  GPIO inputs and then loop for a set time (sample) and watch the GPIO
#  pin for pulses (counter).  We then take the number of pulses and average them,
#  then we multiply them by the speed correction factor (cfactor) to find
#  the speed in MPH. 
#
#  This is a 5 second average as originally written.  This could be then
#  Put into an array and then a 2 minute average could be calculated for 
#  display as a sustained speed, and the highest reading in a 5 minute set
#  could be used as a gust, with a high speed greater than 10 knots above the
#  lowest lull in a 10 minute period as the Peak Wind.
#  
#  Copyright 2013 cmcdonald 
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#  
#  
from time import sleep
import time 
import RPi.GPIO as GPIO

DEBUG = 0
counter = 0
finishtime = 0
# This is the correction factor for the Argent Data anemeometor
# one RPS = 1.492 MPH of wind.  RPS not RPM
# if using another instrument, change cfactore to manufactures setting 
cfactor = 1.492
sample = 5
speed = 0
pinin = 17  # This is the GPIO pin we will listen on
state = False

# Setup which GPIO Pin as pin to watch for counter
GPIO.setmode(GPIO.BCM)
GPIO.setup(pinin, GPIO.IN)

def ppm_counter():
#Loop through for a few seconds (sample) and watch for 
# 	pulses.  (sample) is the time in seconds, then average it by
# 	(sample) for an average of pulses per second, then multiply by
# 	correction factor (cfactor) for speed in MPH
	counter = 0
	# finishtime is right now (clock time) + 5 real seconds, not 
	# CPU seconds
	finishtime = (int(time.time()) + sample)
	#We are going to assume the switch is open, so state = false
	state = False
	while (int(time.time()) < finishtime):
		if DEBUG > 0:
			print (int(time.time()))
		# Check to see if the pin goes Low (switch closed)
		if ( GPIO.input(pinin) == True ):
			# State was false, now set that the switch closed and 
			# watch for it to open
			state = True
		# We see that the switch closed, now wait until it opens
		if ((state == True) and (GPIO.input(pinin) == False)):
			# Reset State to open
			state = False
			#  Increment the counter
			counter = counter + 1
	if DEBUG > 0:
		print counter
#	counter is the total number of pulses during the sample time
#	We need to then calculate the speed at pps*cfactor=speed in MPH
	speed = ((counter / sample)  * cfactor)
	if DEBUG > 0:
		print speed
	return (speed)
		
		
def main():
while True:
	speed = ppm_counter()
	print speed
return 0

if __name__ == '__main__':
	main()
	#! /usr/bin/env python
#$Revision: 1 $
#$Edited: WhimickRH $
#$Date: 2016-08-01 $
#$Anemometer & Wind Direction

import grovepi
import RPi.GPIO as GPIO
from grovepi import *
import math
import time
from time import sleep
from time import strftime, localtime


# --Global variables--
DEBUG = 0
counter = 0
finishtime = 0
# This is the correction factor for the Argent Data anemeometor
# one RPS = 1.492 MPH of wind.  RPS not RPM
# if using another instrument, change cfactore to manufactures setting
cfactor = 1.492
sample = 5
speed = 0
pulse = 0
state = 0
wind_speed = 0
winddir = 0

# 

[weewx-user] Re: Why is my csv rain data not being reported

2016-07-29 Thread 'Mike Whimick' via weewx-user
Thanyou for replying

I have now started to work out how to add wind speed and dirrection, using 
Maplin's Anemometer and wind direction sensor, both of which send a pulse 
as they move.

Connecting it to my Grovepi is part.
However working out to to count the pulses, and use them, will require some 
search to find out to do it. FUN!!!
So I will be spending some time playing.

At some point I hope to use the python code and use it to send packets, 
staht is for another day though.

I do hope my efforts may help others and to thank who have helped by 
posting their code.

I would be greatfull for any suggestions.

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 weewx-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.