Blog 09

From BitWizard WIKI
Revision as of 12:58, 21 September 2015 by Cartridge1987 (talk | contribs) (Wind Station)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

BETA! Missing other extra information you can get

Temperature Station

First look at outside temperature:

First you need to install:

sudo apt-get install weather-util

you can type:

weather 'your city/country' 

Sadly, it mostly will give a result that is saying that it is ambiguous. It will then give you the option to choose one of the results. Example:

weather rotterdam: 
Searching via name... 
Your search is ambiguous, returning 3 matches: 
   [ehrd] Rotterdam Airport Zestienhoven, Netherlands 
   [fips3609363935] Rotterdam town, NY 
   [fips3663924] Rotterdam CDP, NY 

If you choose the first one you have to type the code between the: [ ] So if I would choose the first one I should type:

weather ehrd

You can also type the full name of the place if you put it in quotation marks:

'Rotterdam town, NY'

That should also work.

The result with searching a station should look like this( some have extra information. ):
Searching via station... 
[caching result Rotterdam Airport Zestienhoven, Netherlands] 
Current conditions at Rotterdam Airport Zestienhoven, Netherlands (EHRD) 51-57N 004-27E -4M 
Last updated Sep 14, 2015 - 05:25 AM EDT / 2015.09.14 0925 UTC 
   Temperature: 62 F (17 C) 
   Relative Humidity: 82% 
   Wind: from the S (170 degrees) at 12 MPH (10 KT) (direction variable) 
   Sky conditions: overcast  

You can also find out which code to type by going to this website:

https://en.wikipedia.org/wiki/International_Civil_Aviation_Organization_airport_code 

On the site if you scroll down you can see the beginning code of every country. Look in which section your country is. Well you click on the beginning letters. Like for France:

LF

There you can find the full 4 letter code which you than can type in the line. So if you want to know the weather in avord(France):

LFOA

Than on the site you will get a list of all the place in France who can give the weather. If it is for yourself try to find a station as close in your environment.

Note: When I tested it out. I found out that some weather stations aren't supported any more. (and don't update any more )

As you maybe already figured out loading a temperature form a certain country can become a really long wait. Because it has to go trough a big list of stations until it finds the station you are searching for.

You can save your country as name in the system to make it faster. I will now take the temperature from: Domodedovo International Airport – Moscow

UUDD

Do:

nano ~/.weatherrc

To go to the weather rc ( the title and description can both be random names the other lines shouldn't be changed. You can also remove the description of course, but takes makes it of course . )

[DIAMoscow]
description = Domodedovo International Airport - Moscow
metar = http://weather.noaa.gov/pub/data/observations/metar/decoded/UUDD.TXT

After you saved and exit just type:

weather DIAMoscow 

And you will get to see the things you wanted to see in a split-second.

Now to get the Temperature visible on your Rb_ui_board. For this I installed lynx, because if I would read it like previous ways it will print it with ignoring the enter in the file.

apt-get install lynx 
lynx -dump http://weather.noaa.gov/pub/data/observations/metar/decoded/UUDD.TXT

It will directly print the result:

Moscow / Domodedovo, Russia (UUDD) 55-24N 037-54E
Sep 18, 2015 - 09:00 AM EDT / 2015.09.18 1300 UTC
Wind: from the SSW (200 degrees) at 18 MPH (16 KT):0
Visibility: greater than 7 mile(s):0
Temperature: 78 F (26 C)
Dew Point: 50 F (10 C)
Relative Humidity: 36%
Pressure (altimeter): 29.97 in. Hg (1015 hPa)
ob: UUDD 181300Z 20008MPS CAVOK 26/10 Q1015 R88/010095 NOSIG
cycle: 13
| grep Temperature

With grep temperature added you want to get the line, where it is showing the temperature:

Temperature: 78 F (26 C)
|  sed -e 's/.*(//' -e 's/ C).*//'

This will remove everything for and after 26

The 2 commands in sed are: first command is:

-e 's/.*(//' 

This command make it happen that it will disappear everything before 26 The result with only this could would then also be:

26 C)

The second command:

-e 's/).*//'

Here is will obviously will make everything disappear after the C from 26 C so if I only would do this command it would be:

Temperature: 75 F (26 C

sed removes everything for or after .*

lynx -dump http://weather.noaa.gov/pub/data/observations/metar/decoded/UUDD.TXT | grep Temperature | sed -e 's/.*(//' -e 's/).*//'

26 C

Now to make a script with it, so we can print it out on the display.

nano DIAMoscow

The script I made:

#!/bin/bash

# What display to use:
DISPL="bw_tool -I -D /dev/i2c-1 -a 94" 

#clean the display
$DISPL -W 10:0:b

while true; do
        $DISPL -W 11:0:b
        $DISPL -t "Out Temp= "`lynx -dump http://weather.noaa.gov/pub/data/observations/metar/decoded/UUDD.TXT | grep Temperature | sed -e 's/.*(//' -e 's/C.*//'` “'C”

        sleep 5
done

What I now only did is printing “Out Temp=” before it and “'C' after it. You can also replace “Out Temp” with “DIAMoscow=” of course or an other place you want to know the temperature from.

When you also have to remove a space you can just press the space bar button several times and after that put the letters, number etc. That you want.

In the image I already added the humidity.

With adding the Humidity I added these 2 lines in the code:

       $DISPL -W 11:20:b
       $DISPL -t "Humidity"`lynx -dump http://weather.noaa.gov/pub/data/observations/metar/decoded/UUDD.TXT | grep Humidity | sed -e 's/.*://'`

Which prints the code in the second line, And removes everything before ':'.

Wind Station

For the Wind Station we can for the most part use the same code.

$DISPL -t "Wind" `lynx -dump http://weather.noaa.gov/pub/data/observations/metar/decoded/UUDD.TXT | grep Wind | sed -e 's/.*the//' -e 's/ degrees.*//'`")"
$DISPL -t "Windspeed" `lynx -dump http://weather.noaa.gov/pub/data/observations/metar/decoded/UUDD.TXT | grep Wind | sed -e 's/.*at //' -e 's/ MPH.*//'`"MPH"

You probably know by now how it all works. And can get maybe also get other information from the weather station. The only thing now I want to do is change the windspeed from MPH to KPH. Because we don't use MPH in my country.

MPH.jpg

1 MPH is around 1.60934 KPH. (Because I for now didn't found out how to work with comma numbers.) I will multiply it with 100000, what makes it: 160934. After that I do the 160934 multiplied the mph result. I will divide it trough 100000 so it can get to it's real number. ( Note: It always wrap up to the first number so: 16.9 and 16.1 will give the same result wrapped up: 16.)


Final code for MPH -> KPH:


#!/bin/bash
DISPL="bw_tool -I -D /dev/i2c-1 -a 94" 
$DISPL -W 10:0:b
while true; do
	 MPH=$(lynx -dump http://weather.noaa.gov/pub/data/observations/metar/decoded/UUDD.TXT | grep Wind | sed -e 's/.*at //' -e 's/ MPH.*//')
	 KPH0=$(($MPH * 160934))
        KPH1=$(($KPH0 / 100000))

        $DISPL -W 11:00:b
        $DISPL -t "Wind" `lynx -dump http://weather.noaa.gov/pub/data/observations/metar/decoded/UUDD.TXT | grep Wind | sed -e 's/.*the//' -e 's/ degrees.*//'`")"

        $DISPL -W 11:20:b
        $DISPL -t "Windspeed" $KPH1"KPH"
sleep 5

done

( You can also change the text with this code: This replaces the first word with the second one given.

echo I like chicken meat | sed -e 's/chicken/dog/'

Result:

I like dog meat

)

KPH.jpg