Inky PHAT - new location


#1

Hi,
I want to change the default location from oop North ‘Sheffield-on-Sea’ for an InkyPHAT weather display.

I found the weather-phat.py file (home/pi/Pimoroni/inky/examples/phat) and opened it in Thonny where it displays as:

CITY = "Sheffield"
COUNTRYCODE = "GB"
WARNING_TEMP = "25"

Firstly, can I just change “Sheffield” here the once to a more appropriate location, or does it need changing elsewhere?
Secondly, What are the options on selecting a location? Post Code, City, Town, Village or Hamlet providing they are relatively unique and not open to confusion such as “Newport” (Shropshire or Wales for example).

This section follows on from above,

#You can use this function to automatically find your location
# based on your IP address
def get_location():
    res = requests.get('http://ipinfo.io')
    if(res.status_code == 200):
        json_data = json.loads(res.text)
        return json_data
    return {}

I’ve tried various ways to run this in terminal but without success, any hints?

TIA
BB


#2

Just go here, https://ipinfo.io/
It should list everything you need, it did for me. My country code is “CA” for Canada. It also listed my City and Region etc.


#3

I think that code you posted is Python maybe? Which you’d have to run from idle?
You need the correct original formatting though, indents etc to copy and past and run it without any errors.


#4

Thanks
I ran https://ipinfo.io/ off my iPhone and it provides a fair bit of information. Location is way off but I think I’ll opt for a reasonably sized, close and unique location and see what happens, I can always revert back to Sheffield.
The code probably is Python I don’t know enough yet to even guess.
Thanks


#5

It uses your IP address to get the info. Your WAN IP address. Access that site from a PC on your home network and it will reference the public WAN IP your ISP gave you for the info. That should get you the correct Country, City info etc to use on the PI on that network.


#6

Probably a bit late to the party on this one.

I have a static IP, courtesy of my ISP.

They are based in the Pimoroni hometown of Sheffied, which is where any IP location service will resolve too.

It’s 230 miles from my house.

:-)


#7

Ah, Ok, that puts a wrinkle in things, lol. My ISP is located in the same city I live in so my info is good, as near as I can tell anyway.


#8

You should be able to find your alpha-2 ISO country code here at Wikipedia, and then use the nearest decent-sized city or town as the city.


#9

230m! Not quite that far but too far to be of any good.
I tried changing from Sheffield to the ISP location (still 30+ miles out) and to a more local city but running the example code just threw a wobbly. Surely it can’t be that hard to change the physical location?
BB


#10

If I had a normal, dynamically ISP assigned IP, then it would probably resolve my location to somewhere in London, where the internet backbone and my ISP’s routers are.

That’s a mere 90 (ish) miles

Probably best to hard-code it.

;-)


#11

When you say it threw a wobbly, what did it do? Was there a useful error?


#12

OK, so delving into geolocation a little bit…

The reason people like Google know where you are, is because they:

  • Know when you have connected to them via you router and its MAC address.
  • Know when others have done the same via their routers.
  • Nearby routers and MAC address (although unconnected, but broadcasting) + signal strength = distance from them.
  • Map all of that out.

If that sounds far fetched you can make calls yourself to the Google Geolocation API using Python.

Not done this myself but it looks interesting.

Simon.


#13

Not sure how the Yahoo weather API works, but it probably looks here (or something similar):

https://www.metoffice.gov.uk/public/weather/climate-network/#?tab=climateNetwork

So, I would chose the nearest place with a weather station, which is not necessarily the nearest town.

Cheers,

Simon.


#14

I changed “Sheffield” to “Worcester”
here:
CITY = “Worcester”
COUNTRYCODE = “GB”
WARNING_TEMP = “25”

And this was the result:

pi@raspberrypi:~ cd /home/pi/Pimoroni/inky/examples pi@raspberrypi:~/Pimoroni/inky/examples python weather-phat.py --colour “black”
python: can’t open file ‘weather-phat.py’: [Errno 2] No such file or directory

But I notice this line further up:

print("""Inky pHAT: Weather

Displays weather information for a given location. The default location is Sheffield-on-Sea.

Do both need changing?
BB


#15

It looks like this is because Yahoo have “retired” their free weather API and replaced it with an RSS feed API to which you have to sign up for access. :-(

https://developer.yahoo.com/weather/?guccounter=1

We’ll look into alternatives to get this working again.


Inkyphat weather.py no longer working
#16

I should have this fixed in the morning. I’ve re-implemented it by scraping the data straight from Dark Sky. :-)


#17

This branch of the Inky library should fix the problem. It’ll be merged in sometime today, hopefully, but you can give it a try now, if you like, by doing the following in the terminal:

sudo apt-get install libxml2-dev libxslt-dev python-dev python3-lxml python-lxml
sudo pip install geocoder beautifulsoup4
git clone https://github.com/pimoroni/inky.git
cd inky
git checkout weather-fix
cd library
sudo python setup.py install
cd ../examples/phat
./weather-phat.py -c red

Or, y’know, just wait a little while and then use the one-line installer :-D


Inkyphat weather.py no longer working
#19

Hmm, I get :

Traceback (most recent call last):
File “./weather-phat.py”, line 9, in
from font_fredoka_one import FredokaOne
ImportError: No module named font_fredoka_one


#20

pip install font-fredoka-one
;-)