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?
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.
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.
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
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.
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
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.
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.
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. :-(
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
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
Just tried the above to fix this issue on a yellow inkyphat and this is what i get when running “./weather-phat.py -c yellow”
Inky pHAT: Weather
Displays weather information for a given location. The default location is Sheffield-on-Sea.
Traceback (most recent call last):
File "./weather-phat.py", line 42, in <module>
inky_display = InkyPHAT(colour)
File "/usr/local/lib/python2.7/dist-packages/inky/phat.py", line 27, in __init__
v_flip=False)
File "/usr/local/lib/python2.7/dist-packages/inky/inky.py", line 74, in __init__
self.eeprom = eeprom.read_eeprom()
File "/usr/local/lib/python2.7/dist-packages/inky/eeprom.py", line 103, in read_eeprom
i2c = SMBus(1)
File "/usr/local/lib/python2.7/dist-packages/smbus2/smbus2.py", line 253, in __init__
self.open(bus)
File "/usr/local/lib/python2.7/dist-packages/smbus2/smbus2.py", line 265, in open
self.fd = os.open("/dev/i2c-{}".format(bus), os.O_RDWR)
OSError: [Errno 2] No such file or directory: '/dev/i2c-1'