ssid not defined #18838
-
|
I have been trying to get an Arduino Nano RP2040 Connect board to connect to a local network. I'm getting an error message that "ssid isn't defined" on the line "wlan.connect(ssid, password)".
MPY: soft reboot The file secrets.py contains: ''' #print(ssid) wlan = network.WLAN(network.STA_IF) ''' I also get an "ssid isn't defined" error when I simply run "print(ssid). |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Try:
Or:
It's quite correct that |
Beta Was this translation helpful? Give feedback.
-
|
The issue you are facing is a fundamental Python namespace error rather than a hardware fault with the Arduino Nano RP2040 Connect. When you use import secrets, the variables inside that file are contained within the secrets module, meaning they cannot be accessed directly by their names alone. To resolve the NameError, you must either change your import statement to from secrets import ssid, password to bring them into the local scope, or reference them as secrets.ssid and secrets.password within your wlan.connect() function. Using these standard import methods will allow MicroPython to identify your credentials correctly. For more advanced implementations and to see how Python handles connectivity in a broader context, you might find this https://www.pcbway.com/project/shareproject/IoT_Using_Raspberry_Pi_and_Python.html project helpful, as it demonstrates similar logic for managing data and network states effectively. |
Beta Was this translation helpful? Give feedback.
Try:
from secrets import ssid, passwordOr:
wlan.connect(secrets.ssid,secrets.password)It's quite correct that
ssidis not defined. It's such a basic error it's easy to miss, we have all done similiar, at least I certainly have.