Join the IOT with your Raspberry Pi Weather Station in Python

Join the IOT with your Raspberry Pi Weather Station inScreen Shot 2015-08-05 at 3.41.42 PM Python

CWOP Do-Wop, Do-Wop the CWOP….

Join the IOT (Internet Of Things) for weather stations.  CWOP is the data sharing system for doing this.   The below software is written in Pure Python for the Raspberry Pi.

In this posting:

  1. What is CWOP (Citizens Weather Observation Program)
  2. How to connect a Raspberry Pi based Weather Station to CWOP
  3. What Software Do You Need?
  4. How to Register at CWOP
  5. How to See Your CWOP Results

What is CWOP?

IMG_3417The Citizen Weather Observer Program (CWOP) is a network of privately owned electronic weather stations concentrated in the United States but also located in over 150 countries. Being in this network allows volunteers with computerized weather stations (like the WeatherPi – https://www.instructables.com/id/Create-Your-Own-Solar-Powered-Raspberry-Pi-Weather/) to send automated surface weather observations to the National Weather Service.

This data is then used by the Rapid Refresh forecast model to produce short term forecasts (3 to 12 hours into the future) of conditions across the United States’ lower 48 states.

CWOP Observations are also re-distributed to the public. There is an extensive set of quality control software that puts your data through the ringer, assigns your data a quality rating and makes suggestions before the data is taken into the system.

The CWOP was originally set up by amateur radio operators experimenting with packet radio, but now contains a majority of Internet-only connected stations. As of July 2015, more than 10,000 stations worldwide report regularly to the CWOP network.

Signing Up For CWOP Signing up for CWOP is fairly simple

1) Follow the directions to get your DW designation number on https://wxqa.com/SIGN-UP.html

2) Set up the values in the configuration file in WeatherPi (see below for values) 

3) Get your station up and running with the software given in the next steps of this posting.

Here are a set of handy links for CWOP checking, display and other information:

What is the Solar Powered WeatherPi?

Recently, SwitchDoc Labs produced a complete instructable to build a solar powered Raspberry Pi Weather Station.IMG_3419footer-robot

WeatherPi is a solar powered Raspberry Pi WiFi connected weather station designed for Makers by SwitchDoc Labs. This is a great system to build and tinker with. All of it is modifiable and all source code is included. The most important functions are:

 

  • Senses 20 different environmental values
  • Completely Solar Powered
  • Has a full database containing history of the environment (MySQL)
  • Monitors and reports lots of data on the solar powered system – great for education! Self contained and monitored for brownouts and power issues
  • Can be modified remotely
  • Download your data to crunch it on your PC
  • Can be modified to do SMS (Text) messaging, Twitters, webpages and more
  • Has an iPad Based Control Panel
  • Easy to connect to Twitter, WeatherUnderground, etc

IMG_4129

The Instructable will show you how to build a WiFi Solar Powered Raspberry Pi Weather Station. This project grew out of a number of other projects, including the massive Project Curacao, a solar powered environmental monitoring system deployed on the Caribbean tropical island of Curacao. Project Curacao was written up in an extensive set of articles in MagPi magazine (starting in Issue 18 and continuing through Issue 22).

The WeatherPi Solar Powered Weather Station is an excellent education project. There are many aspects of this project that can be looked at and analyzed for educational purposes.

Configuration Values for CWOP

#CWOP / APRS Parameters
APRS_HOST = 'cwop.aprs.net'
APRS_PORT = 14580
APRS_USER = 'your DW ID (like EW7667 for our station)'
APRS_PASS = '-1'
CALLSIGN = 'your DW ID (like EW7667 for our station)'
STATION_TYPE = 'IOTWeatherPi'
ELEVATION = 630 # meters above sea-level
#The format is "ddmm.hhN/dddmm.hhW" without the quotation marks, where d is degrees, m is minutes and h is hundredths of minutes.
STATIONLATITUDE = '4739.22N'
STATIONLONGITUDE ='11705.11W'

The CWOP Interface to WeatherPi

When you talk to the CWOP server, you use a protocol called APRS (Automatic Packet Reporting System).

APRS was originally an amateur radio-based system for real time communications of information of immediate value in the local area. Now it is used in a number of applications where data packets need to be disseminated to multiple locations.

The software that we are using in this project is based on the excellent work of Tom Hayward and his pywxtd project . We have removed the weather station parsing code and the daemon code and are just using the APRS libraries to send the data to CWOP.

The CWOP software reads data from the WeatherPi station and sends an APRS packet to the CWOP servers with our current weather data.

First is the post_CWOP code used to send the packet to the CWOP servers:

We install the CWOP code in the main WeatherPi Python loop to fire every 15 minutes.

       # every 15 minutes, build new graphs

        if ((secondCount % (15*60)) == 0):
                # print every 900 seconds
                sampleWeather()
                sampleSunAirPlus()
                doAllGraphs.doAllGraphs()
                # send our CWOP data

                # wind direction - degrees from true north
                # wind speed - integer MPH
                # wind gust - integer MPH
                # temperature - degrees F
                # rain since midnight - hundredths of inches
                # humidity - % where 100% = 00
                # pressure - 5 numbers in tenths of millibars

                CWOP.post_CWOP(wind_dir=currentWindDirection, wind_speed=currentWindSpeed, wind_gust=currentWindGust, temperature=CtoFInteger(outsideTemperature), rain_since_midnight=0, humidity=convertHumidity(outsideHumidity), pressure=int(bmp180SeaLevel*100+0.5))

Sending the CWOP APRS Packets

Next, we have the code we use to construct the CWOP APRS packets.

#!/usr/bin/env python

# SwitchDoc Labs
# July 24, 2015
# Version 1.0

"""
initially from Tom Hayward
builds and submits an
APRS weather packet to the APRS-IS/CWOP.
BSD License and stuff
Copyright 2010 Tom Hayward <tom@tomh.us>
"""
import sys, os, time
from datetime import datetime, timedelta

from socket import *

sys.path.append('..')

# Check for user imports
try:
        import conflocal as conf
except ImportError:
        import conf




def make_aprs_wx(wind_dir=None, wind_speed=None, wind_gust=None, temperature=None, rain_since_midnight=None, humidity=None, pressure=None):
    """
    Assembles the payload of the APRS weather packet.
    """
    def str_or_dots(number, length):
        """
        If parameter is None, fill space with dots. Else, zero-pad.
        """
        if number is None:
            return '.'*length
        else:
            format_type = {
                'int': 'd',
                'float': '.0f',
            }[type(number).__name__]
            return ''.join(('%0',str(length),format_type)) % number

    timeStringZulu = time.strftime("%d%H%M")
    return '@%sz%s/%s_%s/%sg%st%sP%sh%sb%s%s' % (
        timeStringZulu,
        conf.STATIONLATITUDE,
        conf.STATIONLONGITUDE,
        str_or_dots(wind_dir, 3),
        str_or_dots(wind_speed, 3),
        str_or_dots(wind_gust, 3),
        str_or_dots(temperature, 3),
        str_or_dots(rain_since_midnight, 3),
        str_or_dots(humidity, 2),
        str_or_dots(pressure, 5),
        conf.STATION_TYPE
    )

def post_CWOP(wind_dir=None, wind_speed=None, wind_gust=None, temperature=None, rain_since_midnight=None, humidity=None, pressure=None):


        # post to aprs
        wx = make_aprs_wx(wind_dir=wind_dir, wind_speed=wind_speed, wind_gust=wind_gust, temperature=temperature, rain_since_midnight=rain_since_midnight, humidity=humidity, pressure=pressure)

        print time.strftime("%Y-%m-%d %H:%M:%S"), wx


        send_aprs(conf.APRS_HOST, conf.APRS_PORT, conf.APRS_USER, conf.APRS_PASS, conf.CALLSIGN, wx)


        return

Example CWOP Packet

We had a difficult time figuring out exactly what format of APRS to send. Here is an example of the actual packets we send:

EW7667>APRS,TCPIP:@251954z4739.22N/11705.11W_158/004g006t076P000h49b01015IOTWeatherPi


CWOP Results

Here is the packet and data as received by the CWOP server rom WeatherPi (our CWOP registration number is EW7667). Now we are connected to the IOT for weather stations!Screen Shot 2015-08-05 at 4.33.58 PM

Here are some of the recorded packets from findu.com:

EW7667>APRS,TCPXX*,qAX,CWOP-3:@252056z4739.22N/11705.11W_045/009g013t075P000h46b10147IOTWeatherPi

EW7667>APRS,TCPXX*,qAX,CWOP-3:@252116z4739.22N/11705.11W_045/010g036t077P000h44b10146IOTWeatherPi

EW7667>APRS,TCPXX*,qAX,CWOP-3:@252135z4739.22N/11705.11W_045/008g006t077P000h42b10143IOTWeatherPi

When you have collected a lot of data, findu.com will display some cool graphs as shown in the findu.com display for EW7667.

Screen Shot 2015-08-05 at 4.09.31 PM