The WIFI is working OK so I wanted to move on and use the display screen with Picographics and unpack the data being downloaded.
If I used the raw downloaded binary list (array?) b’string of characters’ I get an error but if I copy the same data and put it in the same variable I do not get an error.
>>>
MPY: soft reboot
MicroPython feature/presto-wireless, presto v0.0.5 on 2024-12-18; Presto with RP2350
Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT
MPY: soft reboot
malloc self
set fb pointers
m_new_class(ST7701...
launch core1
launched core1
core1 returned
Waiting for Wi-Fi connection...
Waiting for Wi-Fi connection...
Waiting for Wi-Fi connection...
Waiting for Wi-Fi connection...
Waiting for Wi-Fi connection...
Waiting for Wi-Fi connection...
Waiting for Wi-Fi connection...
Waiting for Wi-Fi connection...
Waiting for Wi-Fi connection...
Connected to Wi-Fi network.
('192.168.0.234', '255.255.255.0', '192.168.0.1', '194.168.4.100')
b'#EventID|Time|Latitude|Longitude|Depth/km|Author|Catalog|Contributor|ContributorID|MagType|Magnitude|MagAuthor|EventLocationName'
b'ak024gok29z8|2024-12-28T13:40:41.644|61.1041|-152.2603|36.6|ak|ak|ak|ak024gok29z8|ml|0.6|ak|60 km W of Tyonek, Alaska'
b'nn00890729|2024-12-28T13:39:57.703|36.8836|-116.3368|13|nn|nn|nn|nn00890729|ml|-0.5|nn|37 km E of Beatty, Nevada'
b'ak024gojy0nb|2024-12-28T13:20:54.471|61.2621|-152.0829|43.8|ak|ak|ak|ak024gojy0nb|ml|0.7|ak|55 km WNW of Tyonek, Alaska'
b'nn00890726|2024-12-28T13:10:14.574|39.1804|-119.0367|5.6|nn|nn|nn|nn00890726|ml|1.4|nn|24 km NNE of Yerington, Nevada'
b'ci40829359|2024-12-28T13:09:51.570|33.6586667|-116.6923333|15.64|ci|ci|ci|ci40829359|ml|0.63|ci|9 km SSE of Idyllwild, CA'
b'nn00890723|2024-12-28T13:03:02.356|39.1732|-119.0198|5.9|nn|nn|nn|nn00890723|ml|1.7|nn|24 km NNE of Yerington, Nevada'
b'nn00890720|2024-12-28T12:59:27.883|37.3603|-117.2082|0|nn|nn|nn|nn00890720|ml|1.1|nn|38 km S of Goldfield, Nevada'
b'ci40829351|2024-12-28T12:50:52.020|33.4151667|-116.6093333|7.77|ci|ci|ci|ci40829351|ml|0.39|ci|15 km N of Warner Springs, CA'
b'ci40829343|2024-12-28T12:36:31.910|35.0888333|-119.0911667|12.5|ci|ci|ci|ci40829343|ml|1.46|ci|22 km NW of Grapevine, CA'
b'nn00890718|2024-12-28T12:36:07.331|37.3406|-117.2023|4|nn|nn|nn|nn00890718|ml|1.3|nn|40 km S of Goldfield, Nevada'
b'ak024gok29z8|2024-12-28T13:40:41.644|61.1041|-152.2603|36.6|ak|ak|ak|ak024gok29z8|ml|0.6|ak|60 km W of Tyonek, Alaska'
b'ak024gojy0nb|2024-12-28T13:20:54.471|61.2621|-152.0829|43.8|ak|ak|ak|ak024gojy0nb|ml|0.7|ak|55 km WNW of Tyonek, Alaska'
(['ak024gojy0nb', '2024-12-28T13:20:54.471', '61.2621', '-152.0829', '43.8', 'ak', 'ak', 'ak', 'ak024gojy0nb', 'ml', '0.7', 'ak', '55 km WNW of Tyonek, Alaska'], '2024-12-28', '13:20:54')
>>> %Run -c $EDITOR_CONTENT
MPY: soft reboot
signal core1
core1 returned
malloc self
set fb pointers
m_new_class(ST7701...
launch core1
launched core1
core1 returned
Connected to Wi-Fi network.
('192.168.0.234', '255.255.255.0', '192.168.0.1', '194.168.4.100')
b'#EventID|Time|Latitude|Longitude|Depth/km|Author|Catalog|Contributor|ContributorID|MagType|Magnitude|MagAuthor|EventLocationName'
b'ak024gok29z8|2024-12-28T13:40:41.644|61.1041|-152.2603|36.6|ak|ak|ak|ak024gok29z8|ml|0.6|ak|60 km W of Tyonek, Alaska'
b'nn00890729|2024-12-28T13:39:57.703|36.8836|-116.3368|13|nn|nn|nn|nn00890729|ml|-0.5|nn|37 km E of Beatty, Nevada'
b'ak024gojy0nb|2024-12-28T13:20:54.471|61.2621|-152.0829|43.8|ak|ak|ak|ak024gojy0nb|ml|0.7|ak|55 km WNW of Tyonek, Alaska'
b'nn00890726|2024-12-28T13:10:14.574|39.1804|-119.0367|5.6|nn|nn|nn|nn00890726|ml|1.4|nn|24 km NNE of Yerington, Nevada'
b'ci40829359|2024-12-28T13:09:51.570|33.6586667|-116.6923333|15.64|ci|ci|ci|ci40829359|ml|0.63|ci|9 km SSE of Idyllwild, CA'
b'nn00890723|2024-12-28T13:03:02.356|39.1732|-119.0198|5.9|nn|nn|nn|nn00890723|ml|1.7|nn|24 km NNE of Yerington, Nevada'
b'nn00890720|2024-12-28T12:59:27.883|37.3603|-117.2082|0|nn|nn|nn|nn00890720|ml|1.1|nn|38 km S of Goldfield, Nevada'
b'ci40829351|2024-12-28T12:50:52.020|33.4151667|-116.6093333|7.77|ci|ci|ci|ci40829351|ml|0.39|ci|15 km N of Warner Springs, CA'
b'ci40829343|2024-12-28T12:36:31.910|35.0888333|-119.0911667|12.5|ci|ci|ci|ci40829343|ml|1.46|ci|22 km NW of Grapevine, CA'
b'nn00890718|2024-12-28T12:36:07.331|37.3406|-117.2023|4|nn|nn|nn|nn00890718|ml|1.3|nn|40 km S of Goldfield, Nevada'
b'ak024gok29z8|2024-12-28T13:40:41.644|61.1041|-152.2603|36.6|ak|ak|ak|ak024gok29z8|ml|0.6|ak|60 km W of Tyonek, Alaska'
b'ak024gok29z8|2024-12-28T13:40:41.644|61.1041|-152.2603|36.6|ak|ak|ak|ak024gok29z8|ml|0.6|ak|60 km W of Tyonek, Alaska'
Traceback (most recent call last):
File "<stdin>", line 111, in <module>
File "<stdin>", line 93, in splitup
TypeError: can't convert str to int
>>>
Here is the code:
# Test WIFI network DEMO on PRESTO
# Tony Goodhew 27 Dec 2024
import time
from random import randint
from presto import Presto
import network
import rp2
import requests
rp2.country("GB")
from secrets import WIFI_SSID, WIFI_PASSWORD
# Setup for the Presto display
presto = Presto(full_res=True,ambient_light=True)
display = presto.display
WIDTH, HEIGHT = display.get_bounds()
# Couple of colours for use later
BLUE = display.create_pen(28, 181, 202)
WHITE = display.create_pen(255, 255, 255)
RED = display.create_pen(230, 60, 45)
ORANGE = display.create_pen(245, 165, 4)
GREEN = display.create_pen(0,255,0)
PINK = display.create_pen(250, 125, 180)
MAGENTA = display.create_pen(255,0,255)
BLACK = display.create_pen(0, 0, 0)
COLOURS = [BLUE, RED, ORANGE, GREEN, PINK, MAGENTA]
def clean():
display.set_pen(BLACK)
display.clear()
presto.update()
display.set_font("bitmap8")
clean()
display.set_pen(RED)
display.text("Quake",70,200,460,8)
presto.update()
time.sleep(2)
touch = presto.touch
clean()
display.set_pen(RED)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
max_wait = 30
while max_wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
max_wait -= 1
print("Waiting for Wi-Fi connection...")
display.set_pen(RED)
display.text("Waiting for Wi-Fi connection...",10,200,460,5)
presto.update()
time.sleep(1)
if wlan.status() != 3:
raise RuntimeError("Network connection failed")
else:
print("Connected to Wi-Fi network.")
print(wlan.ifconfig())
clean()
display.set_pen(GREEN)
display.text("Connected",10,200,460,5)
presto.update()
time.sleep(1)
clean()
#response = requests.get("https://text.npr.org/")
#response = requests.get("http://wttr.in/cambridge?format=3")
#response = requests.get("http://ipecho.net/plain")
response = requests.get("https://earthquake.usgs.gov/fdsnws/event/1/query?format=text&limit=10")
#response = requests.get("http://artscene.textfiles.com/asciiart/unicorn")
lines = []
for x in response.content.splitlines():
xs = str(x)
print(str(xs))
lines.append(str(x))
response.close()
names = ['EventID', 'Time', 'Latitude', 'Longitude', 'Depth/km', 'Author', 'Catalog', 'Contributor',
'ContributorID', 'MagType', 'Magnitude', 'MagAuthor', 'EventLocationName', 'Date', 'Time']
def splitup(s):
string = ""
items = []
for p in range(len(s)):
c = s[p]
if chr(c) != "|":
string = string + chr(c)
else:
items.append(string)
string = ""
items.append(string)
# Extract date and time from second item
dt = items[1]
date = dt[0:10]
time = dt[11:19]
return(items,date,time)
test = lines[1]
print()
print(test)
#test = b'ak024gojy0nb|2024-12-28T13:20:54.471|61.2621|-152.0829|43.8|ak|ak|ak|ak024gojy0nb|ml|0.7|ak|55 km WNW of Tyonek, Alaska'
print(test)
k = splitup(test)
print()
print(k)
I do not understand why the unpasted version does not work.
Has anyone any ideas?