Here are some issues and solutions regarding networking:
Yes, of course. Code like wifi.radio.connect(ssid="mynetwork", password="12345")
is valid, but is highly discouraged.
If you save the code to GitHub or another online repository or publish a guide or Playground Note, you will be handing your WiFi credentials to the world.
Placing the values in settings.toml and using os.getenv()
allows you to separate the values from the code.
There is active work on the ability to use IPv6 addresses in addition to IPv4. The work is incomplete as of mid-2024. Please keep an eye on CircuitPython version release notes for when the work will be complete. There is no estimated time of arrival (ETA) for this code to be ready.
os.getenv()
returns an error
Current CircuitPython implementations use a file called settings.toml to store the WiFi SSID ("network name") and password. See the Network Settings page in this guide on how to create this file and format content in it. The values must be in double quotes ("). Typical entries are similar to the ones below:
# settings.toml CIRCUITPY_WIFI_SSID = "MyLocalNet" CIRCUITPY_WIFI_PASSWORD = "mysecretpassword"
Also note: the values in settings.toml must match those in the code. In settings.toml if the SSID is specified in the value CIRCUITPY_WIFI_SSID
then use ssid=os.getenv("CIRCUITPY_WIFI_SSID")
to get that value and not ssid=os.getenv("SSID")
as there is a mismatch in the names which will not result in what you want.
You can print it using print("my IP addr:", wifi.radio.ipv4_address)
or save it to a variable with my_address = wifi.radio.ipv4_address
. Generally the libraries abstract the address such that you do not have to use its value explicitly. But there are times when it is handy to print it to verify there is a connection, re. if the value is 0.0.0.0
or another nonsense value when it should be similar to other devices on your network (example: 192.168.1.87
) then there may be an issue.
Not at this time. This can be revisited as new technologies come on the scene and are adopted by the community.
If you are using a single board computer like Raspberry Pi, you'll be using CPython ("regular Python") which has extensive networking support which you can find documentation in standard Python texts.
Text editor powered by tinymce.