Skip to content

Latest commit

 

History

History
145 lines (100 loc) · 4.55 KB

004_wlan_tutorials.md

File metadata and controls

145 lines (100 loc) · 4.55 KB

WLAN

Table of Contents

Prolog

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)

Scan for access points

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.

Connect as station to access point

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.

Create own access point (open)

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.

Create own access point (WPA)

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.

Additional information

Later examples then fall back on this basic examples. Think about what the improved version of the examples in boot.py would do then!

Home | Previous | Next