HELLO, THE CODE FILES ARE BELOW, BUT I CAN'T CONNECT TO THE INTERNET WITH A SIM800L, MY LINE IS 4G BUT I CANNOT FIX IT, CAN YOU HELP URGENTLY?
#define TINY_GSM_MODEM_SIM800
#define TINY_GSM_RX_BUFFER 256
#include <TinyGsmClient.h>
#include <ArduinoHttpClient.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
static const int RXPin = 4, TXPin = 3;
TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);
#define rxPin 7
#define txPin 8
SoftwareSerial sim800(txPin, rxPin);
const char FIREBASE_HOST[] = "xxxxxxxxxxxxxxxxxxxxxxxx.firebaseio.com";
const String FIREBASE_AUTH = "xxxxxxxxxxxxxxxxxxxxxxxxxxxQdy5lewgCDJZPYzW";
const String FIREBASE_PATH = "gpsHost";
const int SSL_PORT = 443;
char apn[] = "internet";
char user[] = "";
char pass[] = "";
TinyGsm modem(sim800);
TinyGsmClientSecure gsm_client_secure_modem(modem, 0);
HttpClient http_client = HttpClient(gsm_client_secure_modem, FIREBASE_HOST, SSL_PORT);
unsigned long previousMillis = 0;
void setup()
{
Serial.begin(9600);
ss.begin(96000);
Serial.println(F("device serial initialize"));
sim800.begin(9600);
Serial.println(F("SIM800L serial initialize"));
Serial.println(F("Initializing modem..."));
modem.restart();
String modemInfo = modem.getModemInfo();
Serial.print(F("Modem: "));
Serial.println(modemInfo);
http_client.setHttpResponseTimeout(10 * 1000); //^0 secs timeout
}
void loop()
{
Serial.print(F("Connecting to "));
Serial.print(apn);
if (!modem.gprsConnect(apn, user, pass))
{
Serial.println(F(" fail"));
//delay(1000);
return;
}
Serial.println(F(" OK"));
http_client.connect(FIREBASE_HOST, SSL_PORT);
while (true) {
if (!http_client.connected())
{
Serial.println();
http_client.stop();// Shutdown
Serial.println(F("HTTP not connected"));
break;
}
else
{
gps_loop();
}
}
}
void PostToFirebase(const char* method, const String & path , const String & data, HttpClient* http)
{
String response;
int statusCode = 0;
http->connectionKeepAlive();
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);
String contentType = "application/json";
http->put(url, contentType, data);
statusCode = http->responseStatusCode();
Serial.print(F("Status code: "));
Serial.println(statusCode);
response = http->responseBody();
Serial.print(F("Response: "));
Serial.println(response);
if (!http->connected())
{
Serial.println();
http->stop();// Shutdown
Serial.println(F("HTTP POST disconnected"));
}
}
void gps_loop()
{
String latitude = String(gps.location.lat(),6);
String longitude = String(gps.location.lng(), 6);
String Data = "{";
Data += "\"Latitude\":" + latitude + ",";
Data += "\"Longitude\":" + longitude + "";
Data += "}";
PostToFirebase("PATCH", FIREBASE_PATH, Data, &http_client);
}