Client-server socket based project with Wio RP2040

Python RP2040 Wio

Let’s learn how to use the Wio dev board RP2040 microcontroller distributed by Seeed Studio to build a client-server socket based project.

We recently presented the Wio Dev Board RP2040 distributed by Seeed Studio, a high performance microcontroller based on dual core ARM Cortex M0 + processor. Today we will learn how to program its activities through the Python language.

The project that we are showing will allow to keep under control the transmission characteristics of our wireless network.

The basic program

First you need to define a program capable of acquiring information through the wifi antenna of the microcontroller.

We open our trusty Thonny, and after installing the latest firmware version of the card, we write the following code:

After importing the necessary micropython libraries, we create the N1 connection as WLAN_SPI, and activate it. Then we request the list of nearby networks (N1.scan) and print the result. Finally, if the connection works, we print the configuration of the board.

The result is the following:

wio rp2040

Interesting … but how can it come in handy?

Python is your friend

The isconnected () method returns a list of objects. We can access each of them through positional notation like this:

In the same way we can run the scan of lis, which contains the scan values (as indicated in line 13-15 of the previous listing). Each element of the list is a string, so it is possible to extract the necessary parameters through Python functions. Let’s say we want to manage a small db containing the network name and signal strength in dB: it will be sufficient to create a simple function to acquire the values through the .split () method and save the parameters placed in position 1 and 2.

At this point we just have to save the acquired data in a database to manage the time series later.

But we are on a microcontroller, and the available memory may not be enough … how to do it?

Socket programming

The idea is to use a client-server system based on socket programming, in which the client is represented by the Wio RP2040 manager and the server by a PC on the network.

The client source will be changed like this:

This time the client, instead of printing the list of data on the terminal, will format them and insert them in the networks and power lists.

On line 28 the connection to the server socket will be made, while the loop on lines 30-33 will create the information strings to be sent.

The last command closes the connection.

On the server side, the code is even simpler:

The code defines the server listening settings (lines 13-16), then, if all went well, it gets ready to receive the client’s address to print a message of successful connection.

Then it enters the listening configuration (ricevi_comandi(), line 3), receiving the strings transmitted by the client, decoding their content and printing the result on the screen.

Implementation notes:

The system was created to evaluate the characteristics of the SeeedStudio Wio RP2040 card (available on their website). The programs presented were written trying to evaluate if, with the latest firmware release, the product was “compliant” with the MicroPython programming libraries. The tests we have done show that the client server system works as expected, even if the implementation of the sources is not foolproof.

A possible subsequent development could be represented by a change to the server: on line 7, instead of just printing a string, we could send the information to a database. Maybe after extracting the components as we have seen on the client. Using the RTC module present on the card, we could time the sendings every few minutes, and have on the database the set of network coverage values ​​in the medium term. Or sound an alarm in the event of a drop in signal strength. With a little imagination it is easy to realize the infinite possibilities of application of the card.

Final remarks

After a large exchange of information and messages with Seeed Studio, we were able to get our hands on a sufficiently stable board firmware, which makes the board perfectly usable. We kept the card running for several hours, without experiencing any overheating or blocking of operation. We therefore believe that we can conclude the tests with a more than sufficient vote: even if limited to 2.4G, the RP2040 board coupled with the WiFi system is a winner in all those situations in which we have a distributed control system, based on sensors and piloted. from an MCU, but we want to centralize its information.

 

Join our groups onTelegram…

… and don’t forget our social channels!

 

Definire ciò che si è non risulta mai semplice o intuitivo, in specie quando nella vita si cerca costantemente di migliorarsi, di crescere tanto professionalmente quanto emotivamente. Lavoro per contribuire al mutamento dei settori cardine della computer science e per offrire sintesi ragionate e consulenza ad aziende e pubblicazioni ICT, ma anche perche’ ciò che riesco a portare a termine mi dà soddisfazione, piacere. Così come mi piace suonare (sax, tastiere, chitarra), cantare, scrivere (ho pubblicato 350 articoli scientfici e 3 libri sinora, ma non ho concluso ciò che ho da dire), leggere, Adoro la matematica, la logica, la filosofia, la scienza e la tecnologia, ed inseguo quel concetto di homo novus rinascimentale, cercando di completare quelle sezioni della mia vita che ancora appaiono poco ricche.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.