No ACL setup yet! Denying access to everyone.
en:edu:zmitac:s2:aih:lab:stm32mqtt

This is an old revision of the document!


AT commands controlled WiFi module

The STM32WB55 microcontroller does not have the WiFi module built-in. There isn't also any additional WiFi-enabling element on the Nucleo board. The laboratory stand is equipped with a module based on ESP32-C3 SoC - super mini. It works as a WiFi modem connected by a UART port controlled with AT commands. It is connected to the hardware serial port lines RxD and TxD available at pins PC_0 and PC_1 respectively. To use it the HardwaSerial class object must be created.

// Serial port configuration (Constructor uses STM port numbering)
HardwareSerial WiFiSerial(PC_0, PC_1, NC, NC);
HardwareSerial class object constructor uses STM-like pin numbering, not Arduino numbering. Pins for RxD and TxD lines are specified. Because no hardware flow control is used the lines RTS and CTS remain unconnected.

In the setup function, the serial port should be opened and the bitrate specified.

// WiFiSerial is a hardware port for ESP32-C3 WiFi modem
WiFiSerial.begin(115200);
ESP32-C3 working as a WiFi modem uses 115200 bps and 8N1 frame format (8 bits of data, no parity control, one stop bit).

The WiFi modem can connect to the wireless network by using AT commands. The list of all supported commands is available on the Espessif website 1). It is important to finish every command with both CR and LF characters (13 and 10 decimal). Fortunately the Arduino function println() sends proper characters automaticaly. If the command is sent properly the modem responds according to the command and finishes the response with “OK”. For example, sending the command “AT” should result in an “OK” response.

AT

OK

If the command is wrong, contains errors, or is not allowed in the actual mode of the modem's operation the response is “ERROR”. A possible situation is that the modem has the WiFi or MQTT configuration stored in the EEPROM memory, and establishes connections automatically after the power-on. If a user tries to send the configuration data while connection is established the modem's response is “ERROR”. The execution time of commands can be quite long, up to a few seconds, especially if commands rely on other devices, eg. establishing the connection to the WiFi Access Point or receiving data from a remote server. It is always a good way to wait for “OK” (and possible “ERROR”) before taking further action. An example of the code that sends an “AT” command and waits for “OK” is shown below.

  String response;  //String object to store the response from modem
  String compOK;    //String object to store the "OK" text for comparison
 
  compOK = "OK";
  WiFiSerial.println("AT");
  do {
    response = WiFiSerial.readStringUntil(0x0A);
  } while (!(response.startsWith(compOK)));

The sequence of commands that establishes the connection to the WiFi Access Point contains two of them.

AT+CWMODE=1
AT+CWJAP="SSID","password"

It is possible to list

en/edu/zmitac/s2/aih/lab/stm32mqtt.1705496833.txt.gz · Last modified: by ktokarz