
Performs a scan of all access points it can see and prints out the name and signal
strength:
for ap in esp.scan_networks():
print("\t%s\t\tRSSI: %d" % (str(ap['ssid'], 'utf-8'), ap['rssi']))
Connects to the AP we've defined here, then prints out the local IP address, attempts
to do a domain name lookup and ping google.com to check network connectivity
(note sometimes the ping fails or takes a while, this isn't a big deal)
(
"Connecting to AP..."
)
while
not
esp.is_connected:
try
:
esp.connect_AP(secrets[
"ssid"
], secrets[
"password"
])
except
RuntimeError
as
e:
(
"could not connect to AP, retrying: "
, e)
continue
(
"Connected to"
,
str
(esp.ssid,
"utf-8"
),
"\tRSSI:"
, esp.rssi)
(
"My IP address is"
, esp.pretty_ip(esp.ip_address))
(
"IP lookup adafruit.com: %s"
%
esp.pretty_ip(esp.get_host_by_name(
"adafruit.com"
))
OK now we're getting to the really interesting part. With a SAMD51 or other large-RAM
(well, over 32 KB) device, we can do a lot of neat tricks. Like for example we can
implement an interface a lot like
(https://adafru.it/E9o)
- which makes getting
data really really easy
To read in all the text from a web URL call
requests.get
- you can pass in
https
URLs for SSL connectivity
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
print("Fetching text from", TEXT_URL)
r = requests.get(TEXT_URL)
print('-'*40)
print(r.text)
print('-'*40)
r.close()
Or, if the data is in structured JSON, you can get the json pre-parsed into a Python
dictionary that can be easily queried or traversed. (Again, only for nRF52840, M4 and
other high-RAM boards)
JSON_URL = "http://api.coindesk.com/v1/bpi/currentprice/USD.json"
print("Fetching json from", JSON_URL)
r = requests.get(JSON_URL)
print('-'*40)
print(r.json())
print('-'*40)
r.close()
©Adafruit Industries
Page 19 of 54
Содержание Airlift Bitsy Add-On
Страница 4: ...Adafruit Industries Page 4 of 54...
Страница 7: ...Pinouts Adafruit Industries Page 7 of 54...
Страница 42: ...Adafruit Industries Page 42 of 54...
Страница 54: ...Fab Print Adafruit Industries Page 54 of 54...