My retro weather forecast TV channel using NWS (USA) data (pic inside)

First, a picture:

Ever since I saw the old school weather channel posted here, I’ve wanted to do something similar. But I’m not in Canada and I’m not very good at python, so I got stuck. I had a spare raspberry pi zero w laying around and set out to make an always-on, quick access "weather channel" based on NWS data.

I’m going to say up front that there are probably much better ways to do this. I didn’t want to sign up for a dashboard service, and I didn’t want to install a desktop on the zero. Also, I’m not very good at bash or python, so I used php for the guts only because that’s what I know. I’m sure it could be easily converted for someone who has more experience.

How it works:

  1. Every 5 minutes, it goes out to the internet and downloads a text only copy of the forecast.
  2. After the new weather forecast is downloaded, it gets hacked to bits to take out the junk I don’t want and insert my custom formatting and such.
  3. The newly hacked up forecast will get called in a frameset (more on why later) with a command line browser. It’s set up to auto refresh every minute. These numbers are arbitrary, you could adjust for whatever timing you think you’d need.

First, download the things you need:

sudo apt-get update
sudo apt-get install php php-cli elinks

Next, you need to go to, search for local forecast using your zip code (top left). After it opens, scroll down to the bottom and click on "Text Only Forecast". Copy this URL, you’ll need it shortly.

Now for the files we’ll need, this is all going to go into /home/pi:

Now sudo nano /home/pi/, now put this in it and CTRL-X, Y, ENTER to save.

wget --trust-server-names 'PUT_YOUR_TEXT_ONLY_FORECAST_URL_HERE' -O /home/pi/weather.html
php /home/pi/reformat.php

Now sudo nano /home/pi/newframes.html and put this in it and save:

<meta http-equiv="refresh" content="60">
<frameset rows="100%">
<frame src='/home/pi/newweather.html'>

Now sudo nano /home/pi/reformat.php and put this in it and save:

$body = file_get_contents('/home/pi/weather.html');
$newfile = fopen('/home/pi/newweather.html', "w");
$pos = strpos($body, "<table width=");
$pos2 = strrpos($body, "<hr>");
$lpos = $pos2-$pos;
$newhead = "<html><head><style>body { font-weight: bold; color: white; background-color: blue; }</style><title>Weather</title></head><body>";
$newend = "</body></html>";
$newbody = substr($body, $pos, $lpos);
$newdoc = $newhead.$newbody.$newend;
fwrite($newfile, $newdoc);

Now sudo nano /home/pi/ and put this in it and save:

sh /home/pi/
elinks /home/pi/newframes.html

Now sudo crontab -e and put this in it and save:

*/5 * * * * sudo sh /home/pi/

Now sudo nano /etc/rc.local, put this before the "exit 0", then save:

sleep 10
sh /home/pi/
) &

Now sudo nano /boot/config.txt and uncomment and modify these lines as needed and save (see below for more info on these modes):

# uncomment to force a specific HDMI mode (this will force VGA)

Now sudo dpkg-reconfigure console-setup

Guess optimal character set
12×24 (framebuffer only)

I don’t actually know if this is required, but for good measure, let’s make our scripts executable:

chmod +x /home/pi/
chmod +x /home/pi/
chmod +x /home/pi/reformat.php

Now just reboot (sudo reboot). In theory, everything should be working. The very first time elinks boots up it’ll show a welcome message. If you have a keyboard, just press enter, or just force a reboot, it won’t show that message again after that first time.

You’ll probably want to tweak some things, so let me explain what all is happening here.

/home/pi/ this file downloads the text only weather information into the file /home/pi/weather.html. Then it calls some php (reformat.php) to hack it up and make it look better.

/home/pi/newframes.html: this is the actual file that will be shown in the browser. It has to use old school style html frames to make this work. The head refreshes and the frame shows the content. Most command line browsers won’t auto refresh and won’t auto show the content of an iframe, you have to click on it to see that. I didn’t want to have to click anything. I discovered that using elinks with an old frameset html file worked perfectly.

/home/pi/reformat.php: this is probably the file that will take the most work to get right, if you use a different service anyway. Basically it reads in the contents of the downloaded forecast, then chops off a bunch of junk at the top and bottom of the pages, and allows me to insert my own css to enforce the color scheme I wanted. It basically just does this by finding specific things in the source, noting their positions, and making a new string out of it and some of my own html on top and bottom of it.

/home/pi/ finally an easy one, this just calls for a refresh ( and then starts the elinks browser.

The sudo crontab -e entry tells it to refresh ( the weather info every 5 minutes.

The rc.local entry starts it up on reboot, but what’s with the sleep? I found that it starts up the browser too fast while the OS is still booting up and it causes weird stuff on the screen. I put a 10 second sleep on it to let it finish booting up before it starts the browser. Seems to have fixed the issue.

/boot/config.txt changes: I didn’t like how small the text was. I’m old and my eyes are bad and sitting 10 feet away from the screen I couldn’t read the default size. I found that no CSS font changes would fix it, so I needed a way to make it bigger. 720p mode (4) along with group 1 got me most the way there. Consult this page for more:

Lastly the sudo dpkg-reconfigure console-setup piece just makes it a little bit easier to read. It’s a l
ittle bigger and bolder.

You won’t be able to see the
full 7 day forecast in this view without scrolling, so if that’s important you’ll need to tweak the font size or add a usb remote to be able to do that. I was only conncerned with seeing the immediately 1-2 day forecast, since weather change so much anyway, I don’t care about those days I can’t see. I’ll just look again tomorrow and it’ll probably change!

Anyway, that’s my little project for the day. Is it useful? Somewhat. I’m sure most folks will just open their weather app, but I had fun.

submitted by /u/morkzadork
[link] [comments]

Read the Full Article here: >Raspberry Pi – More than just magic mirrors and kodi!

This entry was posted in Rasberry PI and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *