Author Topic: Homemade Weather Station using a Raspberry Pi  (Read 47379 times)

0 Members and 1 Guest are viewing this topic.

Offline TejasBob

  • Member
  • *
  • Posts: 6
Re: Homemade Weather Station using a Raspberry Pi
« Reply #150 on: June 06, 2017, 02:51:24 PM »

Second you will need to create a weewx driver that takes the ascii file and transfers it to weewx. At this point weewx takes over and creates the webpage and transfers your data to wunderground and CWOP. I have included my driver, feel free to use it but it is very simple at this point.

Code: [Select]
#
#    $Revision: 1 $
#    $Author: Nickolas McColl $
#    $Date: 2014-08-16 $
#
"""Raspberry Pi driver for the weewx weather system"""

from __future__ import with_statement
# import math
import time
#import weedb
#import weeutil.weeutil
import weewx.abstractstation
import weewx.wxformulas


def loader(config_dict, engine):
    import weewx.units
    altitude_m = weewx.units.getAltitudeM(config_dict)

    station = Raspberry_pi(altitude = altitude_m, **config_dict['Raspberry_pi'])
   
    return station
       
class Raspberry_pi(weewx.abstractstation.AbstractStation):
    """Station using Raspberry Pi"""

    def __init__(self, **stn_dict):
        self.altitude = stn_dict['altitude']
        self.loop_interval = float(stn_dict.get('loop_interval'))

    def genLoopPackets(self):
        import weewx.units

        while True:
            start_time = time.time()

            # Create Loop packet
            f = open('/home/weewx/bin/wxdata.csv')
            input = f.readline()
            f.close()   
            data = input.split(',')
            if len(data) == 13: # data line is complete, process
                for i in range(1, (len(data))):
                    try:
                        data[i] = float(data[i])
                    except ValueError:
                        data[i] = None     
           
                raw_time =time.strptime(data[0], "%Y-%m-%d %H:%M:%S")
           
                _packet = {'dateTime': int(time.mktime(raw_time)),
                           'usUnits' : weewx.METRIC,
                           'pressure' : data[1],
                           'windSpeed' : data[12], #use 3 second average
                           'windGust' : data[12], #use 3 second average
                           'windDir' : data[3],
                           'windGustDir' : data[3],
                           'outTemp' : data[4],
                           'outHumidity' : data[5],
                           'rain': data[6],
                           'radiation' :data[9],
                           'inTemp' : data[11]}
           
                _packet['dewpoint']  = weewx.wxformulas.dewpointC(_packet['outTemp'], _packet['outHumidity'])
                _packet['barometer'] = weewx.wxformulas.sealevel_pressure_Metric(_packet['pressure'], self.altitude, _packet['outTemp'])
                _packet['altimeter'] = weewx.wxformulas.altimeter_pressure_Metric(_packet['pressure'], self.altitude)
                _packet['heatdeg'] = weewx.wxformulas.heating_degrees(_packet['outTemp'], 18.333)
                _packet['cooldeg'] = weewx.wxformulas.cooling_degrees(_packet['outTemp'], 18.333)
                _packet['heatindex'] = weewx.wxformulas.heatindexC(_packet['outTemp'], _packet['outHumidity'])
                 
                yield _packet
     
            sleep_time = (start_time - time.time()) + self.loop_interval
            if sleep_time > 0:
                  time.sleep(sleep_time)
   
    def hardware_name(self):
        return "raspberry_pi"
           
   

Enjoy,

The missing part of the puzzle! One step closer. :)  Thanks!!!

I see you abandoned the lightning detector.  Any particular reason?  Been thinking about how to feel that to weewx.

Offline weathernick

  • Senior Member
  • **
  • Posts: 89
Re: Homemade Weather Station using a Raspberry Pi
« Reply #151 on: June 06, 2017, 04:51:03 PM »
I could never get the lightning sensor to work to my liking...Ended up spending too much time with it so I focused on the core sensors and my wxcams. I did noticed that future versions of WEEWX does have native support for that sensor. So ultimately we don't need code for that.

Nickolas
PWS: Custom built with Raspberry Pi collecting the data from the sensors.
CWOP: EW5462
Wunderground: KAZYUMA27
Personal WX page: http://mccolls.weewx.s3-website-us-east-1.amazonaws.com/

Offline TejasBob

  • Member
  • *
  • Posts: 6
Re: Homemade Weather Station using a Raspberry Pi
« Reply #152 on: June 06, 2017, 07:17:35 PM »
I could never get the lightning sensor to work to my liking...Ended up spending too much time with it so I focused on the core sensors and my wxcams. I did noticed that future versions of WEEWX does have native support for that sensor. So ultimately we don't need code for that.

Nickolas

Did you ever try this? https://github.com/weewx/weewx/wiki/as3935

Offline TejasBob

  • Member
  • *
  • Posts: 6
Re: Homemade Weather Station using a Raspberry Pi
« Reply #153 on: June 21, 2017, 09:22:32 AM »
Nickolas.  Do you have a more recent copy of your raspberry_pi.py driver code?  The one I copied from you looks like it is for weewx v2.x and won't run on 3.  I'm chasing down module import errors.

Offline Crannog

  • Member
  • *
  • Posts: 19
Re: Homemade Weather Station using a Raspberry Pi
« Reply #154 on: June 28, 2017, 05:49:08 AM »
Hi Guys,

Great to see this thread still active. My remote station has been running now for 12 weeks. It originally crashed due to a power failure in Oct after a week of wet and dull weather, the solar controller failing to turn of load when battery ran down. I got a better controller and re-installed the station, with a few features disabled on PI ZERO to reduce power requirements. I fear it will die again next winter with 20W panel.

I have been working on a Arduino mini pro version which requires much less power and has good low power sleep modes. Have ye tried this? I have the sensors working (except wind as I don't have a second anemometer) and a SIM800L breakout uploading to WU. I plan to try and get a cheap VGA camera to upload images via the SIM800L. I think I will need a SD drive added to the assembly to store image prior to upload as memory is limited on Arduino's.


Offline TejasBob

  • Member
  • *
  • Posts: 6
Re: Homemade Weather Station using a Raspberry Pi
« Reply #155 on: June 28, 2017, 08:31:59 AM »
I have been working on a Arduino mini pro version which requires much less power and has good low power sleep modes.

I have thought about this but was considering using it only as a remote sensor package.  I was thinking of transmitting data back via a zigbee interface to a rPi running WeeWx.  I haven't looked at what the power requirements would be however.

Offline henryhunt

  • Member
  • *
  • Posts: 1
Re: Homemade Weather Station using a Raspberry Pi
« Reply #156 on: September 16, 2017, 09:37:27 AM »
Hi guys! Iíve been building a weather station from scratch too (using a raspberry pi and python), and have found this thread great to read when I found it a few months ago. I can do a post about my station at some point if youíd like? I just have a few questions about final things that need to be done before the station can be considered finished.

Nick, Iím using the same wind speed (inspeed - though it's the 1 pulse per rotation one instead of the 8 pulse) and rainfall (rainwise) sensors as you, and youíve said youíre using an RC filter on both of them, based on the diagram at this link http://www.wetter-garching.de/howto.html, to remove noise. What I wanted to know is if you used all of the exact components in the diagram (470 ohm resistor, 1N4148 diode, 10 kohm resistor and 100nf capacitor) in the same setup, because in previous posts you have said that you just need to add a resistor and capacitor to remove the noise.

Also, did you use the same RC filter with the same component values for both rainfall and wind speed or does one have slightly different values?

One other thing: the diagram uses 5 volt power supply, but Iím using the 3.3 volt one on the pi, and was wondering if this would require any changes to the RC filter components?

Please forgive my detailed question. I donít do very much electronics, so I always like to properly check that things are correct and will work before implementing them, as I know how easy it is to completely fry things.

Henry  :grin:
« Last Edit: September 18, 2017, 05:37:58 AM by henryhunt »