Raspberry Pi Weather Station
I considered setting up a static IP address for the Pi and essentially having it act like a server, but I was afraid that the extra network traffic (both intended and unintended) could hamper the Pi’s performance. I also thought of building a website where the Pi could send its data and then be viewed by anyone online, but I didn’t want to pay for the domain, hosting services, etc. For now, I’d just rather have some 3rd party website manage and disseminate my data. That’s where Twitter comes in.
I found Twython, which is a Python library for managing a Twitter account. It allows you to post text, pictures, and videos and probably do a bunch of other things that I didn’t take time to learn about since I will be just posting text (maybe a webcam later though…). I signed up for a new Twitter account so that I don’t spam my current followers. Twython requires you to set up a new Twitter application at dev.twitter.com and record the consumer and access keys in your script. There is a good tutorial HERE. After that, you can compose a Tweet with a single Python command.
The tweet.py script that I wrote ingests the current conditions from current.txt and outputs them (nicely formatted) to Twitter. It serve a few other functions like converting to Fahrenheit, calculating relative humidity, converting to sea-level pressure, and converting wind speeds from rpm to mph. The script is run every 10 minutes with Cron.
- 4 Python scripts to query each sensor once per second (1Hz) and write the output to a temporary text file for later analysis
- TempHumi.py (relies on rpiSht1x python library)
- PresTemp.py (relies on Adafruit I2C libraries)
- wdir.py (relies on Adafruit software-level SPI implementation)
- wspd.py (uses RPi.GPIO to interrupt and count each pulse)
- A Fortran (used because of speed and familiarity) program to analyze each of the temporary text files every minute
- Finds average temperature, dewpoint, pressure, and windspped
- Finds the maximum 3-second wind gust
- Uses the Yamartino Method to calculate average wind direction and standard deviation
- Generates summary each minute and writes it into the appropriate text file for the day/month/year
- Generates current.txt which will be used for future projects (updating websites, Twitter, etc.)
- A scheduling python script to call the Fortran program at XX:XX:00 (better sleep functions than Fortran
- Cron tasks to call each of the Python scripts at reboot