vshymanskyy / TinyGSM

A small Arduino library for GSM modules, that just works
GNU Lesser General Public License v3.0
1.91k stars 708 forks source link

How to run a webserver through GPRS using ESP32 #790

Open lg007 opened 1 month ago

lg007 commented 1 month ago

[x ] I have read the Troubleshooting section of the ReadMe

What type of issues is this?

[ ] Request to support a new module

[ ] Bug or problem compiling the library [ ] Bug or issue with library functionality (ie, sending data over TCP/IP) [x ] Question or request for help

What are you working with?

Modem: SIM800L Main processor board: ESP32 TinyGSM version: 0.11.7 Code:

Scenario, steps to reproduce

I have a SIM card with a private APN. I would like to setup a webserver on port 80 through GPRS using the ESP32 (this webserver would be accesible only from those other endpoints that are within the private APN). I have tried the simple webserver library for ESP32 and also the ESPAsyncWebSrv. Unfortunatelly both crashed after issuing the server.begin() command. Of course before starting the webserver I also waited until the gprs connection was started. Could anyone give me some hints on what am I doing wrong?
(This setup works well with other GRPS endpoints that run linux, like a raspberry with a SIM800L modem, so there is no problem with the APN setup)

lukebuono commented 2 weeks ago

I don't usually comment much on git but i spent the better half of over a week trying to achieve a similar setup with a sim7600G. All way beyond my head but there is no simple way to interface the webservers built around WiFi to the network stack without serious deep diving. ESPIDF has some libs that could interface with the lower level TCP/IP libs like PPOS but I had no luck.

The best solution I achieved was starting up both an AsyncWebServer and a TCP/IP client with TinyGSM. I would then HTTP req from my PC -> ESP through a callback server hosted on AWS. Once the ESP received the request there still needs to be a method of passing this through to the Asyncwebservers stack. My rough work around was to initialize a HTTPClient and then scripted a listener on the TinyGSM ESP client side to passthrough incoming data to the HTTPClient, client function then bundles the HTTP path, params etc. then sends this to the local Asyncwebserver. The HTTPClient then forwarded the response from the Asyncwebserver back to the TinyGSM client back to my AWS server back to my PC. Worked fine for small web pages but struggled with handling any large datasets or libraries used in HTML. OTA was not working either.

In summary an easier solution I found was to use the TinyGSM client to listen to a port hosted on AWS EC2 instance. The AWS hosted a webserver/webpage which acts as a transparent passthrough to the ESP by only needing to send simple commands over 4G, this then triggered the ESP to do something much like how you would use the AsyncWebServer and ESP to talk to each other. ESP then sends back simple responses which is parsed by the AWS server and updated on the webpage. Also works in massively reducing data overhead,