Hello.
I want to send http request to my esp32-s3 which uses gsm shield to connect to net. Basically, I want to send a command to enable or disable one of esp output. Something like this I want to send:
{
"ID": "123456789",
"action": "on"
}
What I did, first I tried to only connect with gsm to net, what was working.
#define TINY_GSM_MODEM_M95
#include <TinyGsmClient.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <SoftwareSerial.h>
const char apn[] = "internet";
const char gprsUser[] = "";
const char gprsPass[] = "";
SoftwareSerial SerialAT(38, 39);
TinyGsm modem(SerialAT);
AsyncWebServer server(8888);
void setup()
{
delay(15000);
Serial.begin(115200);
// Set GSM module baud rate
SerialAT.begin(9600);
// Wait for GSM module to initialize
delay(1000);
Serial.println("Initializing GSM module...");
modem.init();
String modemInfo = modem.getModemInfo();
Serial.print("Modem: ");
Serial.println(modemInfo);
// Connect to the internet using GPRS
Serial.println("Connecting to GPRS...");
if (!modem.gprsConnect(apn, gprsUser, gprsPass))
{
Serial.println("Failed to connect to GPRS");
while (true)
;
}
Serial.println("Connected to GPRS");
delay(1000);
Serial.println(modem.getLocalIP());
delay(1000);
// Start the web server
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
{ request->send(200, "text/plain", "Hello, World!"); });
server.on("/data", HTTP_POST, [](AsyncWebServerRequest *request)
{
if (request->hasParam("key1") && request->hasParam("key2")) {
String key1 = request->getParam("key1")->value();
String key2 = request->getParam("key2")->value();
// Process the data as needed
request->send(200, "text/plain", "Data received");
} else {
request->send(400, "text/plain", "Bad request");
} });
Serial.println(modem.isGprsConnected());
delay(1000);
server.begin();
}
void loop()
{
// Handle other tasks, if any
}
This is code I used. Problem is, that when it comes to executing server.begin() line, esp "crashes". On my PC I can hear sound of unplugged USB and in VScode I need to reconnect to serial. After that same thing keep hapening. Anyone have idea what might cause this problem. When it comes to using WiFi, everything works fin. Thanks for any help