0

pyportal & NASA image viewer
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

pyportal & NASA image viewer

by Mjevans1305 on Sun Apr 14, 2019 10:14 pm

After struggling with the instructional PDF for this project, I finally got the Pyportal to operate. Well, that is to say, there are no errors. When it boots I get the warning about the files system, which is expected. Then it connects to my wifi and I get the NASA splash screen. Then, after a few seconds, I get the expected text/JSON data for the image I expect to see, but no image ever pops up. Just the NASA splash screen.
Pretty sure the NASA Api key is working or I wouldn't be getting the image date and title. However, I've noticed that it is always "Two Black Holes Merge". I've not let it set for 30 minutes yet to see if the image data changes, so I'll do that.
I understand the images must be pulled into Adafruit server for resizing before I get it, so is there something wrong on that end?
What else might I look into?

Mjevans1305
 
Posts: 3
Joined: Sun Apr 14, 2019 8:14 pm

Re: pyportal & NASA image viewer

by jamesmj on Mon Apr 15, 2019 12:10 pm

I am having a similar issue and tracked it down to the image resize service. All requests to the resize service fail with the following error:

Code: Select all | TOGGLE FULL SIZE
{
error: "request failed - failed to load and process image"
}


Here is the resize request URL with my x-aio-key removed for privacy:

https://io.adafruit.com/api/v2/jamesmj/ ... x-aio-key=[MY-AIO-KEY]&width=320&height=240&output=BMP16&url=https://d2s58yb1g1qa3l.cloudfront.net/images/8855a090-5592-11e9-839f-6fe15833a22b.jpg?sign=06ce24&height=800

If you load the source url directly it seems file. It's just a smallish jpg.

https://d2s58yb1g1qa3l.cloudfront.net/i ... 33a22b.jpg

I've tried other images as well and none seem to work :( Are there restrictions on the supported formats or sizes?

@Mjevans1305 If you connect to the serial output of the device, you should be able to see the original and resize urls it's trying to use. I'd be curious to know if your resize urls are failing for the same reason. You should be able to copy it from the serial output and simply paste it into a browser to see the image.

jamesmj
 
Posts: 4
Joined: Thu Nov 19, 2015 11:21 pm

Re: pyportal & NASA image viewer

by schmarty on Mon Apr 15, 2019 12:43 pm

jamesmj wrote:If you load the source url directly it seems file. It's just a smallish jpg.

https://d2s58yb1g1qa3l.cloudfront.net/i ... 33a22b.jpg


Hi jamesmj - I actually see an error from cloudfront when I try to load the above URL:

Code: Select all | TOGGLE FULL SIZE
{"message":"URL sign parameter is invalid"}


Could it be that your browser is logged in or authorized to get this URL but others are not? In this case, the image proxy service is probably having trouble fetching the source image.

Another common failure mode for the image proxy service is large images. Currently there's a limit (I think 2MB?) for source images. Anything over that and the proxy won't load them.

I hope that helps!

schmarty
 
Posts: 12
Joined: Wed Oct 16, 2013 12:00 pm

Re: pyportal & NASA image viewer

by jamesmj on Mon Apr 15, 2019 12:55 pm

Sorry, I forgot to include the "sign" and other params when I copied the source url into my post. The actual url passed to the image resizer is:

https://d2s58yb1g1qa3l.cloudfront.net/i ... height=800

This url loads in a private window, via curl, etc. I wonder if the resize service isn't parsing the extra params in the url?

jamesmj
 
Posts: 4
Joined: Thu Nov 19, 2015 11:21 pm

Re: pyportal & NASA image viewer

by jamesmj on Mon Apr 15, 2019 5:47 pm

Out of curiosity, I updated our server to provide a preview url without the signing and size params and it works. I think those were the culprit. It would be nice to be able to use these since many content delivery services used by API contain parameters for resizing info.

jamesmj
 
Posts: 4
Joined: Thu Nov 19, 2015 11:21 pm

Re: pyportal & NASA image viewer

by Mjevans1305 on Mon Apr 15, 2019 6:03 pm

Jamessm wrote:@Mjevans1305 If you connect to the serial output of the device, you should be able to see the original and resize urls it's trying to use. I'd be curious to know if your resize urls are failing for the same reason. You should be able to copy it from the serial output and simply paste it into a browser to see the image.


Not following, I'm a newbie and have no idea what you're asking me to do.

Mjevans1305
 
Posts: 3
Joined: Sun Apr 14, 2019 8:14 pm

Re: pyportal & NASA image viewer

by jamesmj on Mon Apr 15, 2019 6:08 pm

If you post the feed url or the photo url you are using I'll take a look and see if it's affected by the same issue as me.

jamesmj
 
Posts: 4
Joined: Thu Nov 19, 2015 11:21 pm

Re: pyportal & NASA image viewer

by schmarty on Tue Apr 16, 2019 3:24 pm

jamesmj wrote:Sorry, I forgot to include the "sign" and other params when I copied the source url into my post. The actual url passed to the image resizer is:

https://d2s58yb1g1qa3l.cloudfront.net/i ... height=800

This url loads in a private window, via curl, etc. I wonder if the resize service isn't parsing the extra params in the url?


It's possible that the image proxy is seeing the ? and/or & characters and interpreting them as arguments for the proxy, rather than URL pieces to pass along. You can try percent-encoding those characters to see if that helps the proxy ignore them.

schmarty
 
Posts: 12
Joined: Wed Oct 16, 2013 12:00 pm

Re: pyportal & NASA image viewer

by Mjevans1305 on Wed Apr 17, 2019 10:51 pm

Here is my Code.py. I'm still not sure what you're needing, but for some reason now I get 1 space image that doesn't change even after 2 hours. Even if I turn it off/on I still get that same image. Yesterday, however, it was a different image. Today it's a galaxy, yesterday it was a nebula.

import time
import board
from adafruit_pyportal import PyPortal

# Set up where we'll be fetching data from
DATA_SOURCE = "https://api.nasa.gov/planetary/apod?api_key=-gibberish"
# There's a few different places we look for data in the photo of the day
IMAGE_LOCATION = ["url"]
TITLE_LOCATION = ["title"]
DATE_LOCATION = ["date"]

# the current working directory (where this file is)
cwd = ("/"+__file__).rsplit('/', 1)[0]
pyportal = PyPortal(url=DATA_SOURCE,
json_path=(TITLE_LOCATION, DATE_LOCATION),
status_neopixel=board.NEOPIXEL,
default_bg=cwd+"/nasa_background.bmp",
text_font=cwd+"/fonts/Arial-12.bdf",
text_position=((5, 220), (5, 200)),
text_color=(0xFFFFFF, 0xFFFFFF),
text_maxlen=(50, 50), # cut off characters
image_json_path=IMAGE_LOCATION,
image_resize=(320, 240),
image_position=(0, 0))

# Get connected to Wifi
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
pyportal._debug = True
while True:
response = None
try:
response = pyportal.fetch()
print("Response is", response)
except RuntimeError as e:
print("Some error occured, retrying! -", e)

time.sleep(30*60) # 30 minutes till next check

Mjevans1305
 
Posts: 3
Joined: Sun Apr 14, 2019 8:14 pm

Please be positive and constructive with your questions and comments.