Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:practical:hardware:sut:stm32:iot_at [2024/04/25 10:37] – [Result validation] ktokarzen:iot-open:practical:hardware:sut:stm32:iot_at [2024/04/27 08:14] (current) – [Result validation] ktokarz
Line 1: Line 1:
-====== STM_IoT_AT:  =====+====== STM_IoT_AT: Programming of the WiFi interface with AT commands =====
 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. 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.
  
Line 58: Line 58:
 lcd.begin(16, 2); lcd.begin(16, 2);
 </code> </code>
-And set the two strings :+And set the two strings for comparison:
 <code c> <code c>
 compOK = "OK"; compOK = "OK";
Line 65: Line 65:
  
 === Step 4 === === 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. +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 "OKif everything works properly or "ERRORif something goes wrong. 
 <code c> <code c>
 +// Display the message that the software has started
 lcd.setCursor(0,0); lcd.setCursor(0,0);
 lcd.print("Started"); lcd.print("Started");
 delay(1000); delay(1000);
  
-WiFiSerial.println("AT");     // Sent the AT command +// Send the "AT" command to the module 
-  do{ +WiFiSerial.println("AT"); 
-    // Wait until 0x0A (Line Feed) character comes + 
-    response = WiFiSerial.readStringUntil(0x0A); +// Display the command on 1-st line of LCD 
-    // Check if the response is "ERROR" +lcd.setCursor(0,0); 
-    if (response.startsWith(compERROR)) +lcd.print("AT              "); 
-      { +do { 
-      lcd.setCursor(0,0); + 
-      lcd.println("Error at x"); // Message when ERROR came +  // Read the response till the LF character 
-      } +  response = WiFiSerial.readStringUntil(0x0A); 
-    }  +   
-  // Stay in the loop until the response is "OK" +  // Display the response on 2-nd line of LCD 
-  while (!(response.startsWith(compOK))); +  lcd.setCursor(0,1); 
-  lcd.setCursor(0,0); +  lcd.print(response); 
-  lcd.println("Step x OK"); // Message that the step was successful+   
 +  // Repeat until "OK" comes 
 +while (!(response.startsWith(compOK)));
 </code> </code>
  
-In the final code change ''x'' with the number of the step of establishing connection procedure to have the feedback if something is wrong.+This code allows us to observe what AT command has been sent and all the responses. It waits until the "OK" comes which is the text sent by the module after every successful command. If something goes wrong we will see the AT command on the first line and "ERROR" on the second line of LCD, and the program stops. This can help with debugging. 
 +<note> 
 +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. 
 +</note>
  
 ==== Result validation ==== ==== Result validation ====
-You should be able to see the information ''Step x OK'' displayed on LCD.+You should be able to see the "AT" displayed on the upper line of the LCD, and "OK" on the lower line of the LCD. If any error in the communication with the ESP32-C3 module occurs the second line shows "ERROR"
 +<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. 
 +</note>
  
 ===== FAQ ===== ===== FAQ =====
-**Can change MAC?**: Actually, yes, you canIt 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: +**Do need to write the program for the WiFi module?** No you don't have toThe ESP32-C3 module is flashed with the firmware from Espressif which implements all functionality for WiFi and MQTTThere are other modules which offer similar functionality.\\ 
-<code c> +**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.\\ 
-#include <WiFi.h> +**Are AT commands the same for all modules available?** The basing AT command set is generally the samebut advanced functionality such as WiFi, MQTT and others can use different syntax for modules from different vendors. Always refer to the original documentation for details.
-#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]); +
-+
-</code>+
  
 <WRAP noprint> <WRAP noprint>
en/iot-open/practical/hardware/sut/stm32/iot_at.1714041454.txt.gz · Last modified: 2024/04/25 10:37 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