Page 3 of 3
WiFi Scan
The scan method can be used to survey what access points are available. It returns a list of tuples, each tuple of which has the format:
(ssid, bssid, channel, RSSI, security, hidden)
where ssid is the usual name of the network, bssid is the MAC address of the access point, channel is the channel number of the access point and RSSI is a relative measure of the strength of the received signal. If your app needs to choose an access point, then picking the one with the highest RSSI is reasonable. The security item is one of:
0 – open
1 – WEP
2 – WPA-PSK
3 – WPA2-PSK
4 – WPA/WPA2-PSK
Finally hidden is False if the access point is broadcasting its SSID and True if not.
To display the WiFi access points in range you could use:
import network
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.disconnect()
aps = wifi.scan()
for ap in aps:
print(ap)
In chapter but not in this extract
- A Simple HTTP Client
- Request Methods
- A Custom Server
- The urequests Module
- A Temperature Sensor Client
Summary
-
Connecting to a WiFi network is a matter of using the WLAN class.
-
Implementing error handling for a WiFi connection can be challenging.
-
The simplest way of implementing an HTTP client is to use urequests.
-
An HTTP client can both send and receive data to the server depending on the request it makes.
-
The most common request is GET which accepts data from the server.
-
Both POST and PUT can be used to send data to the server.
-
The only difference between a client and server is that a client can only make a connection, a server can accept a connection.
-
It is possible to avoid having to implement a server on the ESP32 by allowing a client to connect to a server running on another machine and send its data using a PUT or POST request.
Programming the ESP32in MicroPython Second Edition
By Harry Fairhead & Mike James

Buy from Amazon.
Contents
Preface
- The ESP32 – Before We Begin
- Getting Started
- Getting Started With The GPIO **
- Simple Output
- Some Electronics
- Simple Input
- Advanced Input – Interrupts**
- Pulse Width Modulation
Extract: PWM And The Duty Cycle**
- Controlling Motors And Servos
- Getting Started With The SPI Bus
- Using Analog Sensors
Extract: Analog Input **
- Using The I2C Bus
Extract: I2C, HTU21D And Slow Reading **
- One-Wire Protocols
Extract: One Wire Bus DS1820 ***NEW!!!
- The Serial Port
- Using WiFi
Extract: WiFi **
- Sockets
Extract: Client Sockets** Extract: SSL Client Sockets**
- Asyncio And Servers
Extract: Asyncio **
- Direct To The Hardware
Extract: Using Hardware Registers **
** Not updated from first edition as yet
|