File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Examples/Astronaut_Network_Demo_mpy Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ import network
2+ import urequests
3+ import time
4+ import neopixel
5+ import machine
6+
7+ # Set up the NeoPixel LED
8+ pin = machine .Pin ("NEOPIXEL" )
9+ led = neopixel .NeoPixel (pin , 1 )
10+
11+ # Set the LED to red while connecting to WiFi
12+ led [0 ] = (255 , 0 , 0 )
13+ led .write ()
14+
15+ # Connect to a WiFi network
16+ wlan = network .WLAN (network .STA_IF )
17+ wlan .active (True )
18+ wlan .connect ('WIFI_NETWORK' , 'WIFI_PASSWORD' )
19+
20+ # Wait for the connection to complete
21+ print ("Waiting for connection..." )
22+ while not wlan .isconnected ():
23+ time .sleep (1 )
24+ print ('.' , sep = '' , end = '' , )
25+ print ('Connected!' )
26+
27+ # Set the LED to blue while downloading data
28+ led [0 ] = (0 , 0 , 255 )
29+ led .write ()
30+
31+ # Download the list of astronauts currently in space
32+ print ('Downloading list of astronauts currently in space...' )
33+ astronauts = urequests .get ("https://corquaid.github.io/international-space-station-APIs/JSON/people-in-space.json" ).json ()
34+
35+ # Print the number of astronauts and their names
36+ number = astronauts ['number' ]
37+ print ('There are' , number , 'astronauts in space.' )
38+ for i in range (number ):
39+ print (i + 1 , astronauts ['people' ][i ]['name' ])
40+
41+ # Set the LED to green to indicate success
42+ led [0 ] = (0 , 255 , 0 )
43+ led .write ()
You can’t perform that action at this time.
0 commit comments