Micro python programming practice of WLAN based on WiFi rp2040 wireless mini WiFi development board

Wio RP2040 Wireless mini WiFi Development board(hereinafter referred to as Wio RP2040 Development board)yes Seeed Studio The company launched a mini wireless in May 2021 WiFi Development board, which integrates Wio RP2040 wireless WiFi modular(See Figure 1),The module includes 133 MHz Raspberry pie double core RP2040 MCU Chip and ESP8285 wireless WiFi Chip, which supports the popular embedded microcontroller programming language MicroPython. 

Figure 1 Wio RP2040 module (RP2040+ESP8285 Chips)
Because raspberry Pico adopts dual core RP2040 MCU chip, the basic usage of Wio RP2040 development board is no different from raspberry Pico development board except network communication function.
The network communication of the Wio RP2040 module integrates ESP8285 wireless WiFi of Espressif company, so the communication capability of the Wio RP2040 module completely depends on the communication performance of the ESP8285 chip. According to the information released by Espressif: the ESP8285 chip is internally integrated with the enhanced Tensilica's L106 diamond series 32-bit core processor, and sealed with 1MB Flash; Like ESP8266, ESP8285 chip provides a highly integrated WiFi system level chip solution, which can meet the needs of wearable devices, Internet of things and other users for low power consumption, compact design and reliability.
The device side of the Wio RP2040 development board is connected to the computer server side through WiFi WLAN. The list of micro Python programs is as follows:

import time
import network  #Import network module
# The network module of micro Python has two WiFi interfaces:
# One is used for the station interface (when the Wio RP2040 development board is connected to the router), and the other is used for the access point (when other devices are connected to the Wio RP2040 development board)
import usocket   #Import the usocket module, which provides access to the BSD socket interface
from machine import Pin
station = network.WLAN_SPI(network.STA_IF)  #Create a WLAN station object and create station interface 
station.active(True)  # Activate the station object and activate the interface

station.connect("H3C_202","abcde12345")  # Replace with your own WiFi name and WiFi password to connect to WiFi, connect to an AP
if station.isconnected():     # Determine whether the station object is connected to WiFi
    print("    IP               Netmask            Gateway            MAC            SSID")
    print(station.ifconfig())   # Get the network information of the station object
    #IP:Wio RP2040 development board IP address, Netmask: subnet mask, Gateway: Gateway, MAC:MAC physical address, SSID:WiFi name
    ip_and_port=['',5000] # IP address and port number of my computer server
    skt.connect(ip_and_port) # ip_and_port: tuple or list of server IP addresses and port numbers
while True:
    skt.send("Greetings from Wio RP2040 mini Dev. board!") # Send data and return the number of bytes successfully sent

Above lan_com.py programs have added comments. There is no more explanation here. Connect the Wio RP2040 development board to the computer. Start Thonny and set up the development environment. Enter the above program in Thonny. For details, see my blog < a href=“ https://blog.csdn.net/yuanzywhu/article/details/122884444?spm=1001.2014.3001.5501 >< "hardware interface technology based on WiFi rp2040 Mini Wireless WiFi development board and basis of micro Python control programming" >
Press down, install the Net Assistant network debugging assistant, run the network debugging assistant program, set the "protocol type" in the upper left corner of the window to [TCP Server], set the "local host address" in the lower part to the IP address used as the computer server (here it is set to the IP address of the WLAN environment where my computer is located), and set the "local host port" to 5000. After all settings are completed, click the [open] button to start the server (see Figure 2).

Figure 2
Next, execute the file named LAN in thorny ide_ com. After the Wio RP2040 development board is successfully connected to WLAN, the five tuple information (IP, Netmask, Gateway, MAC, SSID) will be displayed in thorny's Shell window, where IP is the IP address of the Wio RP2040 development board, Netmask is the subnet mask, Gateway is the Gateway, MAC is the MAC physical address of the Wio RP2040 development board, and SSID is the WiFi name; The Wio RP2040 development board will send the string "Greetings from Wio RP2040 mini Dev. board!" to the network debugging assistant every 2 seconds (see Figure 3).

Figure 3
It should be noted that in the process of debugging the device side network communication program of the Wio RP2040 development board, if there is a communication problem between the computer and the development board, you can press the [RUN] button on the Wio RP2040 development board to restart and restore the normal communication function. In addition, in addition to using the network debugging assistant as the computer server-side program, we can also use Python, C, Java and other languages to write special computer server-side applications.
Release date: February 17, 2022

Keywords: network IoT micropython

Added by SurgeProto on Thu, 17 Feb 2022 18:10:55 +0200