Connecting LilyGO-T-SIM7000G to Firebase problem

I recently obtained a LilyGO-T-SIM7000G Esp32 and been trying to figure out how to connect it to Firebase. If someone has already got it to work could you please point out what I'm doing wrong in my code or perhaps refer me to some sample code? Much appreciated. For the GPS coordinates I'm just sending hardcoded values until I figure out the connection portion of the code.

#define TINY_GSM_DEBUG Serial
#define TINY_GSM_MODEM_SIM7000SSL

#define PIN_TX      27
#define PIN_RX      26
#define UART_BAUD   115200
#define PWR_PIN     4

#include <Arduino.h>
#if defined(ESP32)
#include <FirebaseESP32.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <FirebaseESP8266.h>
#endif

#define USE_GSM
#include <Arduino.h>
#include <Wire.h>

#define PWR_PIN     4    

#include <TinyGsmClient.h> 
#include <ArduinoHttpClient.h> 

const char FIREBASE_HOST[]  = "";
const String FIREBASE_AUTH  = "";
const String FIREBASE_PATH  = "/";
const int SSL_PORT          = 443;

char apn[]  = "h2g2";
char user[] = "";
char pass[] = "";

HardwareSerial  gsmSerial(1);
TinyGsm modem(gsmSerial);

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


unsigned long previousMillis = 0;
long interval = 10000;

void setup() {
  
  Serial.begin(UART_BAUD);
  gsmSerial.begin(UART_BAUD, SERIAL_8N1, PIN_RX, PIN_TX);

  pinMode(PWR_PIN, OUTPUT); 
  
  digitalWrite(PWR_PIN, HIGH);
  delay(300);
  digitalWrite(PWR_PIN, LOW);

  int i = 6;
  delay(200);
    while (i) {
        Serial.println("Send AT");
        gsmSerial.println("AT");
        if (gsmSerial.available()) {
            String r = gsmSerial.readString();
            Serial.println(r);
            break;
        }
        delay(1000);
        i--;
    }
}

void loop() {
  
  http_client.connect(FIREBASE_HOST, SSL_PORT);
  gps_loop(); 
}

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
  
  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("Status code: ");
  Serial.println(statusCode);
  response = http->responseBody();
  Serial.print("Response: ");
  Serial.println(response);
  
  if (!http->connected()) {
    Serial.println();
    http->stop();// Shutdown
    Serial.println("HTTP POST disconnected");
  }
}

void gps_loop()
{
  String latt, longg;
  latt = "1";
  longg = "2";
  
  Serial.print("Latitude= "); 
  Serial.print(latt);
  Serial.print(" Longitude= "); 
  Serial.println(longg);
      
  String gpsData = "{";
  gpsData += "\"lat\":" + longg + ",";
  gpsData += "\"lng\":" + latt + "";
  gpsData += "}";
  
  PostToFirebase("PATCH", FIREBASE_PATH, gpsData, &http_client);
}

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