Category Archives: content

Bash profile specific ‘on login script’

Edit/Create file

nano ~/.bash_profile

Runs this example script every time you login – handy if you have many SD cards.

Example file contents

echo ''
echo ---------------------------------
echo '| RaspberryPI - Weather Station |'
echo ---------------------------------
echo 'Login: '$USER
echo ''
echo ''

Connecting to a Raspberry Pi via USB/TTL-Serial with Ubuntu Linux

HT –

ls -l /dev/ttyUSB0 #verify device is attached
sudo adduser [the user you want to add] dialout


sudo reboot now


screen /dev/ttyUSB0 115200

From Linux (Ubuntu) you can remote forward the x-windows GUI apps

ssh -YC user@ip

then run a gui app, ie: lxpanel, lxsession, wpa_gui

My #RaspberryPi #Python code for tweeting the MetOffice weather for #BrizeNorton #Stornoway #BurnhamOnSea & #Newquay

I have been developing this python code and I found a great way of sharing my code but not my API keys! I also made a Python ‘function’ so that new locations can simply be added by defining a name and the longitude and latitude coordinates (the Met office API does the hard work is finding the nearest weather station to these coordinates) and calling this function with the 3 parameters.

For updates see this repository –

#!/usr/bin/env python
# Tweet some weather data!

import time
import sys
import metoffer
from twython import Twython

# Define location of api files - recorded in a file - avoids a GitHub slurp for API keys!

# Read API keys from file
with open(keys_file) as f:
    CONSUMER_KEY = f.readline().strip("\n")
    CONSUMER_SECRET = f.readline().strip("\n")
    ACCESS_KEY = f.readline().strip("\n")
    ACCESS_SECRET = f.readline().strip("\n")

with open(metkeys_file) as f:
    met_api_key = f.readline().strip("\n")
# Setup API calls
met = metoffer.MetOffer(met_api_key)
# get local weather
def LookupObs( locationdescription, longitude, latitude ):
   weather_observations = met.nearest_loc_obs(float(longitude),float(latitude)) 
   weather_report = metoffer.parse_val(weather_observations)
   weather_data =[len(]
   wind_info = weather_data['Wind Speed']
   wind_direction = weather_data['Wind Direction']
   print (time.strftime("%d/%m/%Y"))+"@"+(time.strftime("%H:%M:%S")) + " - " +locationdescription+": "+str((weather_data['Temperature'][0]))+"c/"+str(tmpf)+"f, Wind speed: "+str(wind_info[0])+wind_info[1]+" "+wind_direction[0]
   api.update_status(status=str(time.strftime("%d/%m/%Y"))+"@"+str(time.strftime("%H:%M:%S")) + " - " +locationdescription+": "+str((weather_data['Temperature'][0]))+"c/"+str(tmpf)+"f, Wind speed: "+str(wind_info[0])+wind_info[1]+" "+wind_direction[0])

LookupObs( locationdescription="#BrizeNorton", longitude=51.7616, latitude=-1.5779 );   #Brize
LookupObs( locationdescription="#Stornoway", longitude=58.1011, latitude=-4.9899 );     #Stornoway
LookupObs( locationdescription="#Burnhamonsea", longitude=51.2430, latitude=-2.9920 );  #BOS
LookupObs( locationdescription="#Newquay", longitude=50.3995, latitude=-5.1379 );       #Newquay

And we are back!

Learnt the hard way with hosting providers, self hosted blogs and back ups (or the lack of them!) posts will be restored* and ‘normal’ service should resume! happy new year!

*from posts cached in the IOS WordPress app.