This is an old revision of the document!


STM_IoT_AT:

The STM32WB55 SoC doesn't have a WiFi network controller so our STM laboratory stands have the WiFi module based on ESP32-C3 SoC connected by serial port and controlled with AT commands. In this scenario, you will learn how to use these commands.

Prerequisites

To implement this scenario, it is necessary to get familiar with the LCD scenario first:

It is also possible to use other displays if you prefer. Please refer to the appropriate chapter to learn how to do it.

Suggested Readings and Knowledge Resources

Hands-on Lab Scenario

Task to be implemented

This introductory scenario shows how to use AT commands to control the ESP32-C3 WiFi module connected to the STM laboratory stand. In this scenario, we will use simple AT commands and try to display if their execution finished properly. We will use the LCD to observe the behaviour of the device. You can use this as the template for the single step of the procedure of establishing a WiFi connection.

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

In this scenario, we just send one command and display the result. In further scenarios, you will learn how to connect to the WiFi access point, connect to the MQTT broker, subscribe to the MQTT topic, and publish the message on a specific topic.

Step 1

Include the LiquidCrystal library in your source code to control LCD:

#include "LiquidCrystal.h"

Step 2

We will connect to the ESP32-C3 WiFi module with a hardware serial port. We need to instantiate the object of the HardwareSerial class. The LiquidCrystal object allows us to display data on LCD.

// Pins definition for Hardware Serial
#define RxD_PIN   PC_0  //STM numbering
#define TxD_PIN   PC_1  //STM 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);

We will also declare two strings for comparison with the responses from the WiFi module

String compOK;
String compERROR;

Step 3

In the setup(); function we need to initialise both devices:

WiFiSerial.begin(115200);
lcd.begin(16, 2);

And set the two strings :

compOK = "OK";
compERROR = "ERROR";

Step 4

The AT commands are sent via a serial port connected to the ESP32-C3 module. At the beginning, we can send an empty command AT. The module should respond OK if everything works properly or ERROR if something goes wrong.

lcd.setCursor(0,0);
lcd.print("Started");
delay(1000);
 
WiFiSerial.println("AT");     // Sent the AT command
  do{
    // Wait until 0x0A (Line Feed) character comes
    response = WiFiSerial.readStringUntil(0x0A);
    // Check if the response is "ERROR"
    if (response.startsWith(compERROR))
      {
      lcd.setCursor(0,0);
      lcd.println("Error at x"); // Message when ERROR came
      }
    } 
  // Stay in the loop until the response is "OK"
  while (!(response.startsWith(compOK)));
  lcd.setCursor(0,0);
  lcd.println("Step x OK"); // Message that the step was successful

In the final code change x with the number of the step of establishing connection procedure to have the feedback if something is wrong.

Result validation

You should be able to see the information Step x OK displayed on LCD, or possibly ERROR at x if any error in the communication with the ESP32-C3 module occurs.

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. You must first explicitly configure the ESP32 chip to work as an AP (Access Point, Server) or STA (WiFi Client) to do it. Sample stub code (for STA) may look as follows:

#include <WiFi.h>
#include <esp_wifi.h>
 
uint8_t newMAC[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE}; //Array of bytes with new MAC
void setup()
{
  WiFi.mode(WIFI_STA);
  esp_wifi_set_mac(WIFI_IF_STA, &newMAC[0]);
}

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_at.1714041524.txt.gz · Last modified: 2024/04/25 10:38 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