0

I just put my hands on RP Pico W to try it out but I hit the issue with the very first wifi test. Tutorials say to do this:

import network
import socket
from time import sleep
from picozero import pico_temp_sensor, pico_led
import machine

so my pico lib folder looks like this when I imported all required packages:

enter image description here

However when try to run wifi test like this:

def connect():
    #Connect to WLAN
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    wlan.connect(ssid, password)
    while wlan.isconnected() == False:
        print('Waiting for connection...')
        sleep(1)
    ip = wlan.ifconfig()[0]
    print(f'Connected on {ip}')


try:
    connect()
except KeyboardInterrupt:
    machine.reset()

it fails with following error:

>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/network.py", line 8, in <module>
  File "/lib/socket.py", line 42, in <module>
AttributeError: 'module' object has no attribute 'socket'
>>> 

This is whole code, I skipped only ssid and password.

I cannot figure out what exactly is wrong here. I do not have any other files named the same as socket or so.

I took the example from RP foundation pages: https://projects.raspberrypi.org/en/projects/get-started-pico-w/2

1 Answer 1

0

You can comment out the picozero import if you just want to test connecting to wireless. It worked for me. Below is the output.

//from picozero import pico_temp_sensor, pico_led


MicroPython v1.22.0 on 2023-12-27; Raspberry Pi Pico W with RP2040
Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT
Waiting for connection...
Waiting for connection...
Waiting for connection...
Connected on 192.168.0.219
>>> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.