GPRS connection not staying connected in private server

Hi, I’m trying to get my code to connect through a TTGO T-CALL to a private server.
Over wifi, locally and externally there’s no problem so far.
However, when trying to connect through the gprs modem it fails when using the private server, but works with the public cloud server? :confused:

Code:


// TTGO T-Call pin definitions
#define MODEM_RST            5
#define MODEM_PWKEY          4
#define MODEM_POWER_ON       23
#define MODEM_TX             27
#define MODEM_RX             26
#define I2C_SDA              21
#define I2C_SCL              22

#define BLYNK_PRINT Serial    
#define BLYNK_HEARTBEAT 30
#define TINY_GSM_MODEM_SIM800

#include <TinyGsmClient.h>
#include <BlynkSimpleSIM800.h>

#include <Wire.h>
// #include <TinyGsmClient.h>
#include "utilities.h"

// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial

// Hardware Serial on Mega, Leonardo, Micro
#define SerialAT Serial1


const char apn[]  = "natcom";
const char user[] = "";
const char pass[] = "";

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
const char auth[] = "ChF_4Yd8Wp2Urm5L3h9RwUd8-cLr6ATB";

WidgetLED led1(V2);
BlynkTimer timer;

TinyGsm modem(SerialAT);


// V1 LED Widget is blinking
void blinkLedWidget()
{
  if (led1.getValue()) {
    led1.off();
    Serial.println("LED on V1: off");
  } else {
    led1.on();
    Serial.println("LED on V1: on");
  }
}


void setup()
{
  // Set console baud rate
  SerialMon.begin(115200);
  delay(10);

  // Keep power when running from battery
  Wire.begin(I2C_SDA, I2C_SCL);
  bool   isOk = setPowerBoostKeepOn(1);
  SerialMon.println(String("IP5306 KeepOn ") + (isOk ? "OK" : "FAIL"));

  // Set-up modem reset, enable, power pins
  pinMode(MODEM_PWKEY, OUTPUT);
  pinMode(MODEM_RST, OUTPUT);
  pinMode(MODEM_POWER_ON, OUTPUT);

  digitalWrite(MODEM_PWKEY, LOW);
  digitalWrite(MODEM_RST, HIGH);
  digitalWrite(MODEM_POWER_ON, HIGH);

  // Set GSM module baud rate and UART pins
  SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
  delay(3000);

  // Restart takes quite some time
  // To skip it, call init() instead of restart()
  SerialMon.println("Initializing modem...");
  modem.restart();

  String modemInfo = modem.getModemInfo();
  SerialMon.print("Modem: ");
  SerialMon.println(modemInfo);

  // Unlock your SIM card with a PIN
  //modem.simUnlock("1234");

   SerialMon.print("Waiting for network...");
  if (!modem.waitForNetwork(240000L)) {
    SerialMon.println(" fail");
    delay(10000);
    return;
  }
  SerialMon.println(" OK");

  if (modem.isNetworkConnected()) {
    SerialMon.println("Network connected");
  }

  SerialMon.print(F("Connecting to APN: "));
  SerialMon.print(apn);
  if (!modem.gprsConnect(apn, user, pass, "http://bynk.xxx.net", 8080)) {
    SerialMon.println(" fail");
    delay(10000);
    return;
  }
  SerialMon.println(" OK");

  Blynk.begin(auth, modem, apn, user, pass);


    timer.setInterval(1000L, blinkLedWidget);

}

void loop()
{
  Blynk.run();
  timer.run();
}

Log:


14:36:57.908 -> Initializing modem...
14:37:04.877 -> Modem: SIM800 R14.18
14:37:04.877 -> Waiting for network... OK
14:37:12.284 -> Network connected
14:37:12.284 -> Connecting to APN: natcom OK
14:37:21.144 -> [26271] 
14:37:21.144 ->     ___  __          __
14:37:21.144 ->    / _ )/ /_ _____  / /__
14:37:21.144 ->   / _  / / // / _ \/  '_/
14:37:21.144 ->  /____/_/\_, /_//_/_/\_\
14:37:21.144 ->         /___/ v0.6.1 on ESP32
14:37:21.144 -> 
14:37:21.144 -> [26274] Modem init...
14:37:21.181 -> [26297] Connecting to network...
14:37:21.181 -> [26309] Network: 37203
14:37:21.181 -> [26309] Connecting to natcom ...
14:37:30.357 -> [35474] Connected to GPRS
14:37:30.357 -> [35485] Connecting to blynk.xxx.net:8080
14:37:32.582 -> [37697] Ready (ping: 968ms).
14:37:48.574 -> [53708] Connecting to blynk.xxx.net:8080
14:39:07.602 -> [132716] Connecting to blynk.xxx.net:8080
14:40:34.433 -> [211724] Connecting to blynk.xxx.net:8080
14:41:49.612 -> [290732] Connecting to blynk.xxx.net:8080


However with public blynk cloud log:

14:50:52.349 -> IP5306 KeepOn OK
14:50:55.482 -> Initializing modem...
14:51:02.446 -> Modem: SIM800 R14.18
14:51:02.446 -> Waiting for network... OK
14:51:09.072 -> Network connected
14:51:09.072 -> Connecting to APN: natcom OK
14:51:59.701 -> [67224] 
14:51:59.701 ->     ___  __          __
14:51:59.701 ->    / _ )/ /_ _____  / /__
14:51:59.701 ->   / _  / / // / _ \/  '_/
14:51:59.701 ->  /____/_/\_, /_//_/_/\_\
14:51:59.701 ->         /___/ v0.6.1 on ESP32
14:51:59.701 -> 
14:51:59.701 -> [67226] Modem init...
14:51:59.701 -> [67249] Connecting to network...
14:51:59.701 -> [67260] Network: 37203
14:51:59.701 -> [67260] Connecting to natcom ...
14:52:07.144 -> [74686] Connected to GPRS
14:52:07.144 -> [74697] Connecting to blynk-cloud.com:80
14:52:08.946 -> [76486] Ready (ping: 907ms).
14:52:10.050 -> LED on V1: on
14:52:11.057 -> LED on V1: off
14:52:12.043 -> LED on V1: on
14:52:13.045 -> LED on V1: off
14:52:14.030 -> LED on V1: on
14:52:15.042 -> LED on V1: off

Does anybody know what might be causing this?

It will connect at least once… albeit for a very short time.

However based on the blynk.xxx.net.net, I suspect your issue is more to do with the DDNS redirection service you are using, than any actual server issue. Perhaps they don’t like something about the GPRS, the port used, etc? You may need to try contacting them and asking.

Meanwhile, for testing this theory, try using your direct WAN (public) IP instead of the DDNS service address.

Thanks for your tip, I just tried the public IP and am finding the same result:

16:09:45.490 -> [22789] Modem init...
16:09:45.523 -> [22814] Connecting to network...
16:09:45.523 -> [22825] Network: 37203
16:09:45.523 -> [22825] Connecting to natcom ...
16:09:50.982 -> [28285] Connected to GPRS
16:09:50.982 -> [28296] Connecting to 190.xx.xx.xx:8080
16:09:51.627 -> [28929] Ready (ping: 309ms).
16:09:58.704 -> [36001] Connecting to 190.xx.xx.xx:8080
16:11:17.714 -> [115008] Connecting to 190.xx.xx.xx:8080
16:12:36.726 -> [194015] Connecting to 190.xx.xx.xx:8080

Same thing, connects once for a quick bit, doesn’t execute the loop, keeps stuck in the connecting bit :confused:

It may seem counterintuitive, but since one (generally) gets less lag with a Local Server, compared to Cloud), perhaps the high speed of the device-to-modem link is too fast now? Try slowing to 9600

I adjusted it to (without really understanding what the difference is, so going to read about it now):

  // Set GSM module baud rate and UART pins
  SerialAT.begin(9600, SERIAL_8N1, MODEM_RX, MODEM_TX);

However, I’m still stuck with the same result:

16:18:05.506 -> [25873] Network: 37203
16:18:05.506 -> [25873] Connecting to natcom ...
16:18:10.035 -> [30399] Connected to GPRS
16:18:10.104 -> [30493] Connecting to 190.xx.xx.xx:8080
16:18:11.443 -> [31804] Ready (ping: 573ms).
16:18:18.586 -> [38955] Connecting to 190.xx.xx.xx:8080
16:19:37.695 -> [118064] Connecting to 190.xx.xx.xx:8080

Only thing left I can think of is that your ISP doesn’t like something with the incoming GPRS signal… something is getting lost in the routing… not enough to prevent ALL connection attempts, just interferes most of the time and causes the unreliability when it does connect.

You may need to talk to your ISP tech support, explain what you are doing and see if they can see anything on their end.

1 Like

Like @Gunner said, it’s possible that the cell GPRS service company (in certain countries) doesn’t like something in the packet data and block them.
It might be port 8080, etc. we just don’t know. But at least port 80 is standard and OK.

You can try this hypothesis by

  1. In the sketch, connect port 80 instead of 8080
  2. Port forward 80 to 8080 in the router to the local server
1 Like

I just put the sim in a 4g router and then connected the esp32 to it over wifi, connection works normally then :thinking:
I’m really at a lost what’s happening :confused:

@Gunner After some playing around the solution was found.
For some reason, downloading the other server version -java8 fixed the problem.