💾 Archived View for benjaminja.info › log › 2018 › 05 › 18-weatherstation_lots_happening captured on 2024-05-10 at 10:49:41. Gemini links have been rewritten to link to archived content

View Raw

More Information

➡️ Next capture (2024-06-20)

-=-=-=-=-=-=-

Weatherstation: Lots Happening

2018-05-18

#Wordpress

#Weather-Station

Starting in April, I have started working on the weather station project again, and I have failed to make any updates since.  So I’m going to try to write everything I have done in this past month and a half.

Weather Station

First, I created a new repository for the project on [Github].  In this, I have migrated my weather station from an Arduino project to a [PlatformIO] project.  This is significant since the Arduino editor works only as a text editor and compiler, while PlatformIO on VSCode acts as a full IDE with code completion along with support for the old Arduino libraries.

Github

PlatformIO

Rather than waiting for commands, the weather station waits for 30 seconds then turns on the radio, and sends the weather packet.  This is done for power saving.  Before, the weather station had the radio turned on and listening 100% of the time.  This wasted a relatively large amount of power.

The weather station now accepts commands after sending the weather update: Set Value, Get Value, Set EEPROM, Load EEPROM, Get Status, and Reset.  These commands can be bunched together in packets.  Some commands send replies which are sent in order after all the commands are sent.

Base Station

The base station is the raspberry pi device that receives the raw weather data from the weather station through the rf24 chip.  It receives the weather, processes the data into human-readable units, then uploads the data to Weather Underground.  Most of the work done this past month is for the base station.

I have done a little bit of work in the past on the base station, but very limited.  Then I planned to have the program run primarily in python, running a c++ script to get the weather from the radio chip.  Now, most of the work done is in a C++ program, running a python script that uploads the weather to [wunderground.com].

wunderground.com

Program Loop

It runs in a 30-second loop that is synchronized with the weather station.  To get synchronized, it will leave the radio on and wait until a transmission is received before beginning the loop again.   One problem I found with this system is that the Arduino and raspberry pi clocks aren’t the same.  Even though they both wait 30 seconds, one seems to be slightly faster than the other.  The problem is solved—too complicated to explain—by the following code snippet.

//wait for an available packet
time_point t = Clock::now();
while(!successfull &amp;&amp; timeDiff(t, Clock::now()) < eeprom::listenTime) {
    sleep_for(500ms);
    successfull = checkForPacket();
    count++;
}
//If we are desyncing, compensate.
count -= (eeprom::listenTime /500) /2;
if(count !=0) {
    reloadTime += (count *500);
    cout <<"Desynced by "<< count *500<<"ms, adjusting"<< endl;
}

Every time the weather station successfully sends a packet: the program will process the data. Upload the weather. And send any commands.  Since I have a website to check the current weather/station status;  I need to have some way of getting that data to the website.  So I decided to use MySQL for data storage and transfer.

MySQL

I am not very skilled in MySQL; after all, I’ve only just learned it.  My plan for the database is to hold the weather for 24 hours to display on the website and to move information from one program to another without the hassle of parsing individual files.  Here are the tables I have made, displayed in a table.

Website

The website I’m making is designed to be for me only: to get information about the station without SSHing into the baseStation.  If I wanted to get the weather, I would use Weather Underground.  Also, I don’t think a Raspberry Pi Zero is equipped to handle more traffic than my immediate family.

The website is fairly straightforward, I’m using the [SB Admin] Bootstrap template.  A few pages: One displaying the status, and other useful information.  Another with the current weather with a 24-hour graph of previous temperatures, pressure, humidity, rain, and wind.  I’m using PHP to connect to the MySQL database to get the weather/status information.

SB Admin

In the future, I want to have a page for configuring the weather station from the website.  Such as setting EEPROM variables on the weatherStation, or resetting the system remotely.  One worry I have is permissions.  I want the website unable to process these commands unless I am logged in.  However I have never done anything like that before, so could be more difficult than I think.  Of course, it could also be much easier than I think as well.

Conclusion

As I continue to work on this project, I want to post once a week, or whenever I work on the weatherStation.  That way I could give more detail, and include more code snippets to help anyone who might find this website who is also building their own weather station.  I hope to get this project done in the next month;  I also was planning to get it done a year ago so don’t expect too much.

🔼 Log - 2018

📭 Message me

📝Or mention this post