Esp32-s3 cant run webserver with gprs connection

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

Well ESP32 beeing connected to your GPRS-module means that the ESP32 has a local connection to the module.

Establishing an internet-connection over the cell-phone network requires more steps.
dialing a number
passing a login and a password etc.

I do not understand what you want to say with this:

pure assumption that might be wrong
using WiFi means you connect the ESP32 to a WiFi where the WiFi-router has done all the steps of establishing an internet-connection through passing a login and a password etc.

best regards Stefan

But I have connection, I provided apn and there are no usner and password. I got connection after using modem.gprsConnect().

As for part with WiFi, I mean that when using WiFi, I can easily just start web server with server.begin(), and with gsm, even when connection is done, I cant.

And the problem is that I cant start webserver when connected to gsm net. I wonder if it is even possible to do that. I didnt found any examples where someone tried to start web server like this, everywhere was only examples with sending data through gsm with http requests.

"I got connection" is a too general description to be useful

What IP-adress did your code print to the serial monitor?

what did this print to the serial monitor?

what did this print to the serial monitor?

Well If you hear a sound of USB-device removed this points to a power-failure.

Usually a simple crash does not cause the USB-COM-Port-chip to be unpowered.

How do you power the GPRS-module?
GSM-modules are able to send with 4W.
At 5V this means 4W / 5V = 0,8A which is way too much for the onboard voltage-regulator of an ESP32

best regards Stefan

image

IP is different every time I run program but that how it work I guess.

This is what print out, after printing "1" - which is Serial.println(modem.isGprsConnected()); - esp "disconnect".

Im powering up gsm shield with lipol battery

This is gsm shield I am using

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.