raise # Set up where we'll be fetching data from NUM_THINGS=25 # how many things to select from (we randomize between em) DATA_SOURCE = "https://api.thingiverse.com/users/adafruit/things?per_page="+str(NUM_THINGS) DATA_SOURCE += "&access_token=" + secrets['thingiverse_token'] IMAGE_LOCATION = [0, "thumbnail"] TITLE_LOCATION = [0, "name"] URL_LOCATION = [0, "public_url"] # determine the current working directory needed so we know where to find files cwd = ("/"+__file__).rsplit('/', 1)[0] pyportal = adafruit_pyportal.PyPortal(url=DATA_SOURCE, json_path=(TITLE_LOCATION, URL_LOCATION, IMAGE_LOCATION), status_neopixel=board.NEOPIXEL, default_bg=cwd+"/thingiverse_background.bmp", text_font=cwd+"/fonts/Arial-12.bdf", text_position=((5, 10), (5, 230)), text_color=(0x00FF00, 0x00FF00), text_transform=(None, None)) pyportal.preload_font() while True: response = None try: response = pyportal.fetch() print("Response is", response) pyportal.set_background(None) image_url = response[2].replace('_thumb_medium.', '_display_large.') pyportal.wget(pyportal.image_converter_url(image_url,320, 240,color_depth=16), "/cache.bmp", chunk_size=512)
from adafruit_esp32spi import adafruit_esp32spi_wifimanager import adafruit_esp32spi.adafruit_esp32spi_socket as socket import adafruit_minimqtt as MQTT import adafruit_pyportal import microcontroller from adafruit_bitmap_font import bitmap_font import adafruit_requests as requests try: from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise ### Variables ### pyportal = adafruit_pyportal.PyPortal() display = board.DISPLAY currentmessage = "null" mqstatus = "null" wifistatus = "null" runcount = 0 wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager( pyportal._esp, secrets, None) mqtt_topic = secrets["mqtopic"] requests.set_socket(socket, pyportal._esp) headers = {'Content-Type': 'application/json'} URL = 'http://worldclockapi.com/api/json/pst/now' ### Code - Definitions ###
# Get wifi details and more from a settings.py file try: from settings import settings except ImportError: print("WiFi settings are kept in settings.py, please add them there!") raise # Set up where we'll be fetching data from DATA_SOURCE = "https://img.shields.io/discord/327254708534116352.svg" DATA_LOCATION = ["svg"] cwd = __file__.rsplit('/', 1)[0] pyportal = adafruit_pyportal.PyPortal(url=DATA_SOURCE, json_path=DATA_LOCATION, status_neopixel=board.NEOPIXEL, default_bg=cwd + "/discord_background.bmp", text_font="/fonts/Collegiate-50.bdf", text_position=(165, 140), text_color=0xFFFFFF) # track the last value so we can play a sound when it updates last_value = 0 while True: try: value = pyportal.fetch() print("Response is", value) last_value = value except RuntimeError as e: print("Some error occured, retrying! -", e) time.sleep(10)
DATA_SOURCE = "https://api.hackster.io/v2/projects?" DATA_SOURCE += "client_id="+secrets['hackster_clientid'] DATA_SOURCE += "&client_secret="+secrets['hackster_secret'] IMAGE_LOCATION = ['records', 0, "cover_image_url"] TITLE_LOCATION = ['records',0, "name"] HID_LOCATION = ['records', 0, "hid"] NUM_PROJECTS = 24 # determine the current working directory needed so we know where to find files cwd = ("/"+__file__).rsplit('/', 1)[0] pyportal = adafruit_pyportal.PyPortal(url=DATA_SOURCE, json_path=(TITLE_LOCATION, HID_LOCATION), image_json_path=IMAGE_LOCATION, image_position=(0, 0), image_resize=(320, 240), status_neopixel=board.NEOPIXEL, default_bg=cwd+"/hackster_background.bmp", text_font=cwd+"/fonts/Arial-Bold-12.bdf", text_position=((5, 5), (5, 200)), text_color=(0xFF0000, 0xFF0000), text_wrap=(40, 40)) pyportal.preload_font() while True: response = None try: response = pyportal.fetch() print("Response is", response) pyportal.set_text("http://hackster.com/project/"+response[1], 1) except (IndexError, RuntimeError, ValueError) as e: print("Some error occured, retrying! -", e)
TEXT_LOCATION = ["items", 0, "children", 0, "properties", "name", 0] cwd = __file__.rsplit('/', 1)[0] # Find all image files on the storage imagefiles = [file for file in os.listdir(cwd+"/backgrounds/") if (file.endswith(".bmp") and not file.startswith("._"))] for i, filename in enumerate(imagefiles): imagefiles[i] = cwd+"/backgrounds/"+filename print("Image files found: ", imagefiles) pyportal = adafruit_pyportal.PyPortal(url=DATA_SOURCE, json_path=TEXT_LOCATION, status_neopixel=board.NEOPIXEL, default_bg=imagefiles[0], text_font="/fonts/Helvetica-Oblique-17.bdf", text_position=(15, 20), text_color=0xFFFFFF, text_wrap=35, # character to wrap around text_maxlen=280, # cut off characters debug=False) pyportal._text_font.load_glyphs(b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.,! \'"') while True: response = None try: pyportal.set_background(random.choice(imagefiles)) response = pyportal.fetch() print("Response is", response) except (IndexError, RuntimeError, ValueError) as e: print("Some error occured, retrying! -", e)
# Set up where we'll be fetching data from DATA_SOURCE = "https://www.adafruit.com/api/products?format=micro&" + PRODUCTS_TYPE + "=1&random=1" # What data we'll be viewing IMAGE_LOCATION = [0, "image"] NAME_LOCATION = [0, "name"] URL_LOCATION = [0, "url"] # determine the current working directory needed so we know where to find files cwd = ("/" + __file__).rsplit('/', 1)[0] pyportal = adafruit_pyportal.PyPortal( url=DATA_SOURCE, json_path=(NAME_LOCATION, URL_LOCATION), status_neopixel=board.NEOPIXEL, default_bg=cwd + "/new_background.bmp", text_font=cwd + "/fonts/Arial-Bold-12.bdf", text_position=((5, 35), (5, 225)), text_color=(0xFFFFFF, 0xFFFFFF), text_wrap=(35, 35), # characters to wrap image_json_path=IMAGE_LOCATION, image_resize=(320, 240), image_position=(0, 0)) pyportal.preload_font() while True: response = None try: response = pyportal.fetch() print("Response is", response) except (IndexError, RuntimeError, ValueError) as e: print("Some error occured, retrying! -", e)
raise # Set up where we'll be fetching data from NUM_THINGS = 25 # how many things to select from (we randomize between em) DATA_SOURCE = "https://api.thingiverse.com/users/adafruit/things?per_page=" + str( NUM_THINGS) + "&access_token=" + settings['thingiverse_token'] IMAGE_LOCATION = [0, "thumbnail"] TITLE_LOCATION = [0, "name"] URL_LOCATION = [0, "url"] cwd = __file__.rsplit('/', 1)[0] pyportal = adafruit_pyportal.PyPortal( url=DATA_SOURCE, json_path=(TITLE_LOCATION, URL_LOCATION, IMAGE_LOCATION), status_neopixel=board.NEOPIXEL, default_bg=cwd + "/thingiverse_background.bmp", text_font="/fonts/Arial.bdf", text_position=((5, 10), (5, 200), None), text_color=(0xFFFFFF, 0xFFFFFF, None), text_maxlen=(50, 50, None), # cut off characters debug=False) while True: response = None try: pyportal.set_background(None) response = pyportal.fetch() print("Response is", response) image_url = response[2].replace('_thumb_medium.jpg', '_display_medium.jpg') pyportal.wget(adafruit_pyportal.IMAGE_CONVERTER_SERVICE + image_url, "/cache.bmp")
import adafruit_pyportal # Set up where we'll be fetching data from DATA_SOURCE = "https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY" IMAGE_LOCATION = ["url"] TITLE_LOCATION = ["title"] DATE_LOCATION = ["date"] cwd = __file__.rsplit('/', 1)[0] pyportal = adafruit_pyportal.PyPortal( url=DATA_SOURCE, json_path=(TITLE_LOCATION, DATE_LOCATION), status_neopixel=board.NEOPIXEL, default_bg=cwd + "/nasa_background.bmp", text_font="/fonts/Arial.bdf", text_position=((5, 10), (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), debug=True) while True: response = None try: response = pyportal.fetch() print("Response is", response) except RuntimeError as e: print("Some error occured, retrying! -", e)
# random fox #DATA_SOURCE = "https://randomfox.ca/floof/" # not working for some reason #IMAGE_LOCATION = ["image"] # random shibe DATA_SOURCE = "http://shibe.online/api/shibes?count=1" IMAGE_LOCATION = [0] # more random cats! #DATA_SOURCE = "https://api.thecatapi.com/v1/images/search" #IMAGE_LOCATION = [0, "url"] cwd = __file__.rsplit('/', 1)[0] pyportal = adafruit_pyportal.PyPortal(url=DATA_SOURCE, status_neopixel=board.NEOPIXEL, default_bg=cwd + "/cute_background.bmp", image_json_path=IMAGE_LOCATION, image_resize=(320, 240), image_position=(0, 0), 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(10) # 30 secs till next check