This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| en:iot-open:practical:hardware:sut:stm32:iot_at [2024/04/27 11:13] – [Result validation] ktokarz | en:iot-open:practical:hardware:sut:stm32:iot_at [2024/04/27 11:14] (current) – [Result validation] ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== STM_IoT_AT: Programming of the WiFi interface with AT commands ===== | ||
| + | The STM32WB55 SoC doesn' | ||
| + | |||
| + | ===== Prerequisites ===== | ||
| + | To implement this scenario, it is necessary to get familiar with the LCD scenario first: | ||
| + | * [[en: | ||
| + | |||
| + | 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 ===== | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | |||
| + | ===== 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 '' | ||
| + | |||
| + | |||
| + | ==== 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: | ||
| + | <code c> | ||
| + | #include " | ||
| + | </ | ||
| + | |||
| + | |||
| + | === Step 2 === | ||
| + | We will connect to the ESP32-C3 WiFi module with a hardware serial port. We need to instantiate the object of the '' | ||
| + | |||
| + | <code c> | ||
| + | // Pins definition for Hardware Serial | ||
| + | #define RxD_PIN | ||
| + | #define TxD_PIN | ||
| + | HardwareSerial WiFiSerial(RxD_PIN, | ||
| + | |||
| + | // 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 | ||
| + | <code c> | ||
| + | String compOK; | ||
| + | String compERROR; | ||
| + | </ | ||
| + | === Step 3 === | ||
| + | In the '' | ||
| + | <code c> | ||
| + | WiFiSerial.begin(115200); | ||
| + | lcd.begin(16, | ||
| + | </ | ||
| + | And set the two strings for comparison: | ||
| + | <code c> | ||
| + | compOK = " | ||
| + | compERROR = " | ||
| + | </ | ||
| + | |||
| + | === 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 - " | ||
| + | <code c> | ||
| + | // Display the message that the software has started | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(" | ||
| + | delay(1000); | ||
| + | |||
| + | // Send the " | ||
| + | WiFiSerial.println(" | ||
| + | |||
| + | // Display the command on 1-st line of LCD | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(" | ||
| + | do { | ||
| + | |||
| + | // Read the response till the LF character | ||
| + | response = WiFiSerial.readStringUntil(0x0A); | ||
| + | | ||
| + | // Display the response on 2-nd line of LCD | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(response); | ||
| + | | ||
| + | // Repeat until " | ||
| + | } while (!(response.startsWith(compOK))); | ||
| + | </ | ||
| + | |||
| + | This code allows us to observe what AT command has been sent and all the responses. It waits until the " | ||
| + | < | ||
| + | You can use this part of the code in the following scenarios for every AT command to observe their behaviour and easily debug possible errors. | ||
| + | </ | ||
| + | |||
| + | ==== Result validation ==== | ||
| + | You should be able to see the " | ||
| + | <note info> | ||
| + | Because LCD can't properly display some non-visible characters the presented code sometimes shows additional, non-letter characters. It is out of the scope of this scenario to filter these characters out. We leave the task of making visual improvements to your invention. | ||
| + | </ | ||
| + | |||
| + | ===== FAQ ===== | ||
| + | **Do I need to write the program for the WiFi module?** No you don't have to. The ESP32-C3 module is flashed with the firmware from Espressif which implements all functionality for WiFi and MQTT. There are other modules which offer similar functionality.\\ | ||
| + | **Can I use a similar WiFi module in my own IoT projects?** Certainly! The universal serial port connects the module so the module can be used with almost every microcontroller as the WiFi network controller.\\ | ||
| + | **Are AT commands the same for all modules available? | ||
| + | |||
| + | <WRAP noprint> | ||
| + | ===== Project information ===== | ||
| + | {{: | ||
| + | This Intellectual Output was implemented under the Erasmus+ KA2.\\ | ||
| + | Project IOT-OPEN.EU Reloaded – Education-based strengthening of the European universities, | ||
| + | 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, | ||
| + | The content is Copyrighted and distributed under CC BY-NC [[https:// | ||
| + | <figure label> | ||
| + | {{: | ||
| + | </ | ||
| + | |||
| + | </ | ||