ESP32 connecting to internet SIM800L problem

Doublementi
Posts: 6
Joined: Sat May 07, 2022 1:05 pm

ESP32 connecting to internet SIM800L problem

Postby Doublementi » Sat May 07, 2022 1:47 pm

Hi, i am trying to connect my SIM800L to internet but i have problem with initialization.
I'm using Wemos Lolin32 Lite.
I think that it doesn't dedect my SIM800L because Serial Output "Module : " Is empty, should be SIM 800L. Sim 800L is blinking every 3 seconds, and after some time is blinking each 0.5 seconds. Output says: Connecting to internet fail. I don't know what is going on, maybe i connected something incorrectly, could you please check what is wrong? In my project i want to send lat and lon values from neo6m to my firebase -> user -> exampleuser.

Code: Select all

//Select your modem
//SSL/TLS is currently supported only with SIM8xx series
#define TINY_GSM_MODEM_SIM800

//Increase RX buffer
#define TINY_GSM_RX_BUFFER 256

//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
#include <TinyGPSPlus.h> //https://github.com/mikalhart/TinyGPSPlus
#include <TinyGsmClient.h> //https://github.com/vshymanskyy/TinyGSM
#include <ArduinoHttpClient.h> //https://github.com/arduino-libraries/ArduinoHttpClient
//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

const char FIREBASE_HOST[]  = "host"; //I want to connect to firebase user then change his lat/lon
const String FIREBASE_AUTH  = "auth";
const String USER_EMAIL ="email";
const String USER_PASSWORD = "pass";
const String USER_UID = "uid";
const String FIREBASE_PATH  = "x/x";
const int SSL_PORT          = 443;
//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[]  = "internet";
char user[] = "";
char pass[] = "";
//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
//GSM Module RX pin to ESP32 2
//GSM Module TX pin to ESP32 4
#define rxPin 4  //are these PIN's okay with my Lolin32 lite??
#define txPin 2
HardwareSerial sim800(1);
TinyGsm modem(sim800);
//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
//GPS Module RX pin to ESP32 17
//GPS Module TX pin to ESP32 16
#define RXD2 16
#define TXD2 17
HardwareSerial neogps(2);
TinyGPSPlus gps;
//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
TinyGsmClientSecure gsm_client_secure_modem(modem, 0);
HttpClient http_client = HttpClient(gsm_client_secure_modem, FIREBASE_HOST, SSL_PORT);
//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

unsigned long previousMillis = 0;
long interval = 10000;

//**************************************************************************************************
void setup() {
  Serial.begin(115200);
  Serial.println("esp32 serial initialize");
  
  sim800.begin(9600, SERIAL_8N1, rxPin, txPin);
  Serial.println("SIM800L serial initialize");

  neogps.begin(9600, SERIAL_8N1, RXD2, TXD2);
  Serial.println("neogps serial initialize");
  delay(3000);
  
  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
  //Restart takes quite some time
  //To skip it, call init() instead of restart()
  Serial.println("Initializing modem...");
  modem.restart();
  String modemInfo = modem.getModemInfo();
  Serial.print("Modem: ");
  Serial.println(modemInfo);  // not displaying
  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
  
  // Unlock your SIM card with a PIN
  //modem.simUnlock("1234");
  
  http_client.setHttpResponseTimeout(90 * 1000); //^0 secs timeout
}
//**************************************************************************************************


//**************************************************************************************************
void loop() {
  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
  //Restart takes quite some time
  //To skip it, call init() instead of restart()
  //Serial.println("Initializing modem...");
  //modem.init();
  //String modemInfo = modem.getModemInfo();
  //Serial.print("Modem: ");
  //Serial.println(modemInfo);
  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
  
  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
  //Serial.print(F("Waiting for network..."));
  //if (!modem.waitForNetwork()) {
    //Serial.println(" fail");
    //delay(1000);
    //return;
  //}
  //Serial.println(" OK");
  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
    
  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
  Serial.print(F("Connecting to "));
  Serial.print(apn);
  if (!modem.gprsConnect(apn, user, pass)) {
    Serial.println(" fail");             // <- fail
    delay(1000);
    return;
  }
  Serial.println(" OK");
  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
  
  http_client.connect(FIREBASE_HOST, SSL_PORT);
  
  //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
  while (true) {
    if (!http_client.connected()) {
      Serial.println();
      http_client.stop();// Shutdown
      Serial.println("HTTP  not connect");
      break;
    }
    else{
      gps_loop();
    }
  }
  //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
}
//**************************************************************************************************

//**************************************************************************************************
void PostToFirebase(const char* method, const String & path , const String & data, HttpClient* http) {
  String response;
  int statusCode = 0;
  http->connectionKeepAlive(); // Currently, this is needed for HTTPS
  
  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
  String url;
  if (path[0] != '/') {
    url = "/";
  }
  url += path + ".json";
  url += "?auth=" + FIREBASE_AUTH;
  Serial.print("POST:");
  Serial.println(url);
  Serial.print("Data:");
  Serial.println(data);
  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
  
  String contentType = "application/json";
  http->put(url, contentType, data);
  
  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
  // read the status code and body of the response
  //statusCode-200 (OK) | statusCode -3 (TimeOut)
  statusCode = http->responseStatusCode();
  Serial.print("Status code: ");
  Serial.println(statusCode);
  response = http->responseBody();
  Serial.print("Response: ");
  Serial.println(response);
  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
  if (!http->connected()) {
    Serial.println();
    http->stop();// Shutdown
    Serial.println("HTTP POST disconnected");
  }
  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
}
//**************************************************************************************************


//**************************************************************************************************
void gps_loop()
{
  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
  //Can take up to 60 seconds
  boolean newData = false;
  for (unsigned long start = millis(); millis() - start < 2000;){
    while (neogps.available()){
      if (gps.encode(neogps.read())){
        newData = true;
        break;
      }
    }
  }
  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
  //If newData is true
  if(true){
  newData = false;
  
  String latitude, longitude;
  //float altitude;
  //unsigned long date, time, speed, satellites;
  
  latitude = String(gps.location.lat(), 6); // Latitude in degrees (double)
  longitude = String(gps.location.lng(), 6); // Longitude in degrees (double)
  
  //altitude = gps.altitude.meters(); // Altitude in meters (double)
  //date = gps.date.value(); // Raw date in DDMMYY format (u32)
  //time = gps.time.value(); // Raw time in HHMMSSCC format (u32)
  //speed = gps.speed.kmph();
  
  Serial.print("Latitude= "); 
  Serial.print(latitude);
  Serial.print(" Longitude= "); 
  Serial.println(longitude);
      
  String gpsData = "{";
  gpsData += "\"lat\":" + latitude + ",";
  gpsData += "\"lng\":" + longitude + "";
  gpsData += "}";

  //PUT   Write or replace data to a defined path, like messages/users/user1/<data>
  //PATCH   Update some of the keys for a defined path without replacing all of the data.
  //POST  Add to a list of data in our Firebase database. Every time we send a POST request, the Firebase client generates a unique key, like messages/users/<unique-id>/<data>
  //https://firebase.google.com/docs/database/rest/save-data
  
  PostToFirebase("PATCH", FIREBASE_PATH, gpsData, &http_client);
  

  }
  //NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
}
//**************************************************************************************************
Attachments
ESP32-WeMos-LOLIN32-Lite-pinout-mischianti-low.jpg
Wemos Lolin32 lite pinout
ESP32-WeMos-LOLIN32-Lite-pinout-mischianti-low.jpg (267.59 KiB) Viewed 8265 times
Bez tytułu.png
My sketch connection
Bez tytułu.png (730.03 KiB) Viewed 8265 times

Tradiot
Posts: 4
Joined: Sat May 07, 2022 5:54 pm

Re: ESP32 connecting to internet SIM800L problem

Postby Tradiot » Sun May 08, 2022 8:35 am

Just a very quick observation..you have no shared ground wire from sim to esp. I use a bread board and put battery ground onto a rail, then have ground wire from rail to sim and a ground wire from rail to esp, you need this for signal reference

Tradiot
Posts: 4
Joined: Sat May 07, 2022 5:54 pm

Re: ESP32 connecting to internet SIM800L problem

Postby Tradiot » Sun May 08, 2022 8:41 am

I forgot to mention, I have a minimum 1500k resistor in series on this ground wire to esp32

Doublementi
Posts: 6
Joined: Sat May 07, 2022 1:05 pm

Re: ESP32 connecting to internet SIM800L problem

Postby Doublementi » Sun May 08, 2022 10:16 am

Tradiot wrote:
Sun May 08, 2022 8:41 am
I forgot to mention, I have a minimum 1500k resistor in series on this ground wire to esp32
So i should connect the ground from esp32 to Sim800L and ground from battery to NEO6m?

Doublementi
Posts: 6
Joined: Sat May 07, 2022 1:05 pm

Re: ESP32 connecting to internet SIM800L problem

Postby Doublementi » Sun May 08, 2022 10:28 am

Tradiot wrote:
Sun May 08, 2022 8:41 am
I forgot to mention, I have a minimum 1500k resistor in series on this ground wire to esp32
You mean this?
Attachments
without resistor.png
without resistor.png (657.59 KiB) Viewed 8081 times
with resistor.png
with resistor.png (658.31 KiB) Viewed 8081 times

Doublementi
Posts: 6
Joined: Sat May 07, 2022 1:05 pm

Re: ESP32 connecting to internet SIM800L problem

Postby Doublementi » Sun May 08, 2022 12:09 pm

Tradiot wrote:
Sun May 08, 2022 8:41 am
I forgot to mention, I have a minimum 1500k resistor in series on this ground wire to esp32
It works now, but i got lat 0 and lon 0

Doublementi
Posts: 6
Joined: Sat May 07, 2022 1:05 pm

Re: ESP32 connecting to internet SIM800L problem

Postby Doublementi » Sun May 08, 2022 1:22 pm

My neo6m module is not available, any solution?

Doublementi
Posts: 6
Joined: Sat May 07, 2022 1:05 pm

Re: ESP32 connecting to internet SIM800L problem

Postby Doublementi » Sun May 08, 2022 2:46 pm

Ok, it works perfectly, cold start - it took more than 20 minutes to start NEO6m

Tradiot
Posts: 4
Joined: Sat May 07, 2022 5:54 pm

Re: ESP32 connecting to internet SIM800L problem

Postby Tradiot » Mon May 09, 2022 11:43 am

Can’t help with the gps, never used one

Squirrelbd
Posts: 6
Joined: Tue Mar 22, 2022 4:39 am

Re: ESP32 connecting to internet SIM800L problem

Postby Squirrelbd » Mon Feb 05, 2024 11:25 am

Check this out, not sure if it will help or not. Interfacing neo-6m GPS module.

Who is online

Users browsing this forum: No registered users and 153 guests