Monday, March 7, 2016

The Evolution of Pi - Part III

Wouldn't it be nice if you can know the weather, without doing ANYTHING?

This may sound overly lazy. You can pick up your phone and know all the weather(s) to your heart's content. Or just pop out of the front door to know exactly how you feel, and decide how to dress accordingly. Or turn on the TV. But in the moment of morning rush, every second counts, and every activity is extra work -- especially if you need to do it on a daily basis (count the accumulated time waste in the span of a person's life).

We have come up with such a solution, with the Pi.

The proposition is, we all go to the kitchen area before heading out, though at different but nonetheless predictable times. By using the (wonderful) Pi, weather could come to us -- without pushing any buttons, flipping any switches, picking up anything, looking at anything. The only thing necessary are functional ears. The following Python script does exactly that:

  • It queries weather underground for the location you care about. Weather Underground API is great that you can play inside the browser. All modern API's should be done this way.
  • Then parses the json object. 
  • Picks up the "current_observation", plus 2 or 3 forecast periods. If this is done in the morning, 2 periods gives the day and evening. If in the afternoon, we use 3 periods, the rest of the day, evening, and next day. After playing with the API, we decided to use the forecast txt, instead of the individual fields.
  • Why did we write everything to the standard out? So we can pipe the output to the Yamaha script, and have the weather announced on the audio receiver. Details covered in Part I.



The last thing is to define the schedule using cron when the weather is announced:

pi@raspberrypi /usr/local/bin $ crontab -l
# Edit this file to introduce tasks to be run by cron.
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# m h  dom mon dow   command
33  6  *   *   1-5   /usr/local/bin/announce_weatehr_wrap.bash
#........... for person 2
#................ for person 3
#................... for person 4
50  19 *   *   *     /usr/local/bin/announce_weatehr_wrap.bash

The 1st line is normally when I sit down for breakfast; then one line for each family member; and the last line is when we are about to be done with diner and knowing tomorrow's weather sounds nice.

The "announce_weatehr_wrap.bash" is just a wrapper with the early script, piping output to the Yamaha script. Misspelling is fine -- the computer doesn't care.

No comments:

Post a Comment