This is an old revision of the document!
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.
To implement this scenario, it is necessary to get familiar with at least one of the following scenarios first:
Present a MAC address on the selected display. The steps below present the reading part and display it on LCD. This display has 16 characters per line, but the commonly used format for MAC addresses requires 17 characters. For seeing the full MAC address modify the example and use the display other than LCD.
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()…
.
Include the LCD library in your source code:
#include "LiquidCrystal.h"
Create objects of the LCD and Hardware Serial classes:
// Serial port class and configuration (Constructor uses STM port numbering) HardwareSerial WiFiSerial(RxD_PIN, TxD_PIN, NC, NC); // LCD class const int rs = PC5, en = PB11, d4 = PB12, d5 = PB13, d6 = PB14, d7 = PB15; LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
Declare two variables with the strings to be compared with the responses from the WiFi module.
String compOK; String compERROR;
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+CIPSTAMAC?” which returns the MAC address in the response message which looks like this:
+CIPSTAMAC:"84:fc:e6:88:63:d1"
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); }
You should be able to see the MAC address of the ESP32-C3 module.
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.