ESP32 In MicroPython: WiFi
Written by Mike James & Harry Fairhead   
Tuesday, 01 August 2023
Article Index
ESP32 In MicroPython: WiFi
A Practical Connect
WiFi Scan

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

By Harry Fairhead & Mike James

esppython360

Buy from Amazon.

Contents

       Preface

  1. The ESP32 – Before We Begin
  2. Getting Started
  3. Getting Started With The GPIO 
  4. Simple Output
  5. Some Electronics
  6. Simple Input
  7. Advanced Input – Interrupts
  8. Pulse Width Modulation
       Extract:
    PWM And The Duty Cycle
  9. Controlling Motors And Servos
  10. Getting Started With The SPI Bus
  11. Using Analog Sensors
       Extract:
    Analog Input
  12. Using The I2C Bus
       Extract
    : I2C, HTU21D And Slow Reading 
  13. One-Wire Protocols
  14. The Serial Port
  15. Using WiFi
     Extract:
    WiFi 
  16. Sockets
     Extract:
    Client Sockets
     Extract:
    SSL Client Sockets***NEW!
  17. Asyncio And Servers
  18. Direct To The Hardware
     Extract:
    Using Hardware Registers 

<ASIN:187196282X>

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner



Last Updated ( Tuesday, 01 August 2023 )