Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4955

MicroPython • Re: Connecting to the Internet with new Pico 2 W

$
0
0

Code:

import timeimport networkssid = 'BT-JJAC9T'password = 'xxxxxxxxx'wlan = network.WLAN(network.STA_IF)wlan.active(True)wlan.connect(ssid, password)# Wait for connect or failmax_wait = 10while max_wait > 0:    if wlan.status() < 0 or wlan.status() >= 3:        break    max_wait -= 1    print('waiting for connection...')    time.sleep(1)# Handle connection errorif wlan.status() != 3:    raise RuntimeError('network connection failed')else:    print('connected')    status = wlan.ifconfig()    print( 'ip = ' + status[0] )
If you're going to post python on here, you need to enclose it within [code][/code] tags, that forces the forum to respect the left hand whitespace (which is important for python code). I've quoted your code and added the tags.

Statistics: Posted by DougieLawson — Wed Nov 27, 2024 12:32 pm



Viewing all articles
Browse latest Browse all 4955

Trending Articles