- Prolog
- Scan for access points
- Connect as station to access point
- Create own access point (open)
- Create own access point (WPA)
- Additional information
If your microcontroller has WLAN capabilities, you can take advantage of networks. All you really have to do is to decide in which mode you want to operate the microcontroller.
The local directory structure and files after all examples:
$ tree .
|____firmware
| |____esp32-20230426-v1.20.0.bin
|____examples
| |____board
| |____esp32_memory.py
| |____esp32_information.py
| |____mpy
| |____example_module.py
| |____wlan
| |____ap_scanner.py
| |____simple_station.py
| |____wp2_access_point.py
| |____open_access_point.py
|____venv
| |____bin
...
Advantage: station mode
- You can connect to the microcontroller with almost any other device in the network (e.g. home network)
- If the access point is connected to the internet, you can also do it mostly with the microcontroller
Advantage: access point mode
- Other nearby devices can easily connect to the microcontroller
- The microcontroller's WLAN is initially not directly connected to the other networks (keyword: security)
It sometimes makes sense to scan the surrounding area for access points. You can later try to scan for the known access points and if they cannot be reached, cancel further connection establishment. But here is just the scan itself.
# create new subdirectory
$ mkdir -p ~/Projects/ESP/examples/wlan
# create script
$ touch ~/Projects/ESP/examples/wlan/ap_scanner.py
Source Code for
ap_scanner.py
# copy file into pyboard as main.py
(venv) $ rshell -p [SERIAL-PORT] cp examples/wlan/ap_scanner.py /pyboard/main.py
# start repl
(venv) $ rshell -p [SERIAL-PORT] repl
Press the keys Control
+ d
or the reset button
and observe the output. If you want to leave the REPL, press keys Control
+ x
.
Okay, now try to connect to a reachable and known access point.
# create script
$ touch ~/Projects/ESP/examples/wlan/simple_station.py
Source Code for
simple_station.py
Change the values for
_AP_SSID
and_AP_PASSWORD
before running!
# copy file into pyboard as main.py
(venv) $ rshell -p [SERIAL-PORT] cp examples/wlan/simple_station.py /pyboard/main.py
# start repl
(venv) $ rshell -p [SERIAL-PORT] repl
Press the keys Control
+ d
and observe the output. In case of OSError: Wifi Internal Error
try the reset button
. If you want to leave the REPL, press keys Control
+ x
.
The script still has plenty of room for improvements but target was to show the minimum.
Even if it is now against all security, the first access point is created without a password (for learning purposes).
# create script
$ touch ~/Projects/ESP/examples/wlan/open_access_point.py
Source Code for
open_access_point.py
# copy file into pyboard as main.py
(venv) $ rshell -p [SERIAL-PORT] cp examples/wlan/open_access_point.py /pyboard/main.py
# start repl
(venv) $ rshell -p [SERIAL-PORT] repl
If you have the opportunity, scan for access points with another device.
Press the keys Control
+ d
or the reset button
and observe the output. If you want to leave the REPL, press keys Control
+ x
.
Then with a (no more) security standard for wireless radio networks based on Advanced-Encryption-Standard (AES) technology.
# create script
$ touch ~/Projects/ESP/examples/wlan/wpa_access_point.py
Source Code for
wpa_access_point.py
# copy file into pyboard as main.py
(venv) $ rshell -p [SERIAL-PORT] cp examples/wlan/wpa_access_point.py /pyboard/main.py
# start repl
(venv) $ rshell -p [SERIAL-PORT] repl
Press the keys Control
+ d
or the reset button
and observe the output. If you want to leave the REPL, press keys Control
+ x
.
Later examples then fall back on this basic examples. Think about what the improved version of the examples in boot.py
would do then!