I'm trying to read/send data to firebase using arduino uno , sim800l (rohs) with this code :
#define TINY_GSM_MODEM_SIM800
#include <TinyGsmClient.h> //https://github.com/vshymanskyy/TinyGSM
#include <ArduinoHttpClient.h> //https://github.com/arduino-libraries/ArduinoHttpClient
#include <SoftwareSerial.h>
SoftwareSerial sim800(5,6);
const char FIREBASE_HOST[] = "sim800l-5xxxxxxbaseio.com";
const String FIREBASE_AUTH = "2w8lrdaxxxxxxxL1mvShO";
const String FIREBASE_PATH = "/";
const int SSL_PORT = 443;
char apn[] = "internet.ooredoo.tn"; // type your APN here
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(115200);
sim800.begin(9600);
Serial.println("\nInitializing modem...");
modem.restart();
String modemInfo = modem.getModemInfo();
Serial.print("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(" fail");
delay(1000);
return;
}
Serial.println(" OK");
http_client.connect(FIREBASE_HOST, SSL_PORT);
while (true) {
if (!http_client.connected())
{
Serial.println();
http_client.stop();// Shutdown
Serial.println("HTTP not connect");
break;
}
else
GetFirebase("PATCH", FIREBASE_PATH, &http_client);
}
}
void GetFirebase(const char* method, const String & path , 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;
http->get(url);
//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");
}
}
I'm getting
Initializing modem...
Modem: SIM800 R14.18
Connecting to internet.ooredoo.tn OK
HTTP not connect
Connecting to internet.ooredoo.tn fail
Connecting to internet.ooredoo.tn fail
Connecting to internet.ooredoo.tn fail
can anyone help me please ?