Auto-Running the Weather Station at Startup

So, you want to run the Weather Station automatically when your Pi boots up? There are two options here -if you want to use your Pi at the same time, go to Step 1. If you only want your Pi to function as a weather station, then skip Step 1 and go straight to Step 2.

1. Make your Pi boot straight to the desktop

In LXTerminal, run:

sudo raspi-config

The screen should change to this:

raspi-config

Use the keyboard keys to scroll down and press enter when “Enable Boot to Desktop/Scratch” is selected. Navigate to “Desktop Login” and press enter to select it.

config

You should be back on the original raspi-config screen now. Use the keyboard keys to go right to “finish” and press enter to go back to the normal LXTerminal screen. Now you can reboot the Pi – it may ask you if you want to do this, but if not you can use sudo reboot – and check that it boots to the desktop screen properly

2. Check that your details are available

Like Thermo_Station.py, Autorun_Station.py (the run-at-start weather station script) automatically accesses your saved user data (such as AWS Key, Plot.ly username, and WOW Site ID. Unlike Thermo_Station.py, though, it will not check and prompt for input if user details are missing. You will need to check if they are there and correct, either by going to the details.ini file in the Sheffield-Pi-Weather-Station folder in your file manager (as shown in the picture below), or by running:

sudo python Thermo_Station.py

If you have run Thermo_Station.py already there is no need to do this step, as your details should already be saved.

If you open the details.ini file from the File Manager window, you should see your user details already inputted

If you open the details.ini file from the File Manager window, you should see your user details already inputted

3. Copy the Autorun_Station daemon to init.d

A “daemon” is just a background process that handles requests for services and then is dormant when not needed. In this case the file Autorun_Station.sh is the daemon that will start up the weather station in the background. The following code should be on one line:

sudo cp /home/pi/Sheffield-Pi-Weather-Station/Autorun_Station.sh /etc/init.d

The sudo lets the Pi know that it should run this with root privileges, the cp is telling the Pi to copy the file, the next part is the place where the file is (called the “path”), and the last part is the place where the file is to be copied to.

copyfile

4. Make the Weather Station auto-run file and daemon file executable

This is done by running this code:

sudo chmod 755 /etc/init.d/Autorun_Station.sh

chmod

5. Make the script run at boot.

This can be done by running this code, which puts the Autorun_Station daemon into folders which the Pi checks at boot and shut down to see if jobs need to be done.

sudo update-rc.d Autorun_Station.sh defaults

6. Start and Stopping the process

As we’re running it at boot via a daemon, it should automatically start when power is plugged in, without needing to plug the Pi into a monitor. However, if you need to stop or start it while the Pi is on, you can use the relevant line of code below:

sudo /etc/init.d/Autorun_Station.sh start

Or:

sudo /etc/init.d/Autorun_Station.sh stop

These result in the following outcomes:

autostart

autostop

7. Check if your station runs automatically

Now use sudo reboot to check if your weather station will run. You can look at the Plot.ly site or Weather Observations Website to see if your data uploads. Alternatively (and this method only checks to see if the script is running, not if your data is being uploaded.:

ps axu | grep python

This code checks to see Python processes that are running. If your weather station is working then it should be shown, like this:

grep

As you can see, the Autorun_Station script is running and, hopefully, uploading your data!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s