This is an old revision of the document!


STM_IoT_2: Connecting to the WiFi Access Point and presenting IP

Each computer connected to the Internet is identified with the IP address. IP abbreviation stands for Internet Protocol, which is responsilbe to transmit data packets between computers in the whole global web - the Internet. The same mechanism is used to address and transmit packets among IP-capable IoT devices. The most popular local networks which support IP addressing are Ethernet and WiFi. The STM32WB55 SoC doesn't have Ethernet or WiFi network controller so our STM laboratory stands have the WiFi module based on ESP32-C3 SoC. It is connected by serial port and controlled with AT commands. To learn how to use these commands please refer to the STM_IoT_Intro chapter.
ESP32 chip gets the IP address from DHCP server after establishing the connection wit FiFi access point. In this scenario, we present how to connect to WiFi network, read and display the IP address on LCD. Displaying on other display than LCD is up to the developer. You can refer to the appropriate scenario, as listed below.

Prerequisites

To implement this scenario, it is necessary to get familiar with at least one of the following scenarios first:

Suggested Readings and Knowledge Resources

Hands-on Lab Scenario

Task to be implemented

Join the WiFi network. Present an IP address on the selected display. The commonly used format for IP addresses requires 15 characters, so LCD having 16 characters is sufficient to present the address. The steps below show the starting part of the software. How to implement the full software please refer to the previous scenarios:

The IP addresses are usually expressed as four decimal numbers ranging from 0 to 255 separated by dots eg. “192.168.1.100”.

Start

Check if you can see a full LCD in your video stream. Book a device and create a dummy Arduino file with void setup()… and void loop()….

Steps

Step 1

The beginning of the code is the same as in the previous scenario, so make a copy of it:

Step 2

In the Setup() function initialise the serial port, display, and strings.

WiFiSerial.begin(115200);
lcd.begin(16, 2);
compOK = "OK";
compERROR = "ERROR";

We will use the code template from STM_IoT_AT: Programming of the WiFi interface with AT commands to communicate with the WiFi module. The first command we will send “AT” to confirm that everything works properly:

WiFiSerial.println("AT");
lcd.setCursor(0,0);
lcd.print("AT              ");
do {
  response = WiFiSerial.readStringUntil(0x0A);
  lcd.setCursor(0,1);
  lcd.print(response);
} while (!(response.startsWith(compOK)));
 
delay(1000);

The next command can be the “AT+CIPSTA?” which returns in the response message the IP address, IP address of the gateway and IP address mask:

+CIPSTA:ip:"192.168.1.117"
+CIPSTA:gateway:"192.168.1.1"
+CIPSTA:netmask:"255.255.255.0"

We can implement the part of displaying the MAC by repeating the block of the code similar to the one presented above with two modifications. Change the “AT” command, and add inside the code the following lines:

if (response.startsWith("+CIPSTAMAC")) {
  response.remove(0,12);
  lcd.setCursor(0,0);
  lcd.print(response);
}

Result validation

You should be able to see the MAC address of the ESP32-C3 module.

Using another node should change the MAC read. Book another device and discover its MAC.

FAQ

Can I change MAC?: Actually, yes, you can. It is not advised, however, because you may accidentally generate an overlapping address that will collide with another device in the same network.

Project information


This Intellectual Output was implemented under the Erasmus+ KA2.
Project IOT-OPEN.EU Reloaded – Education-based strengthening of the European universities, companies and labour force in the global IoT market.
Project number: 2022-1-PL01-KA220-HED-000085090.

Erasmus+ Disclaimer
This project has been funded with support from the European Commission.
This publication reflects the views of only the author, and the Commission cannot be held responsible for any use that may be made of the information contained therein.

Copyright Notice
This content was created by the IOT-OPEN.EU Reloaded consortium, 2022,2024.
The content is Copyrighted and distributed under CC BY-NC Creative Commons Licence, free for Non-Commercial use.

en/iot-open/practical/hardware/sut/stm32/iot_2.1714125214.txt.gz · Last modified: 2024/04/26 09:53 by ktokarz
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0