// this project firebase json http get request example but I get 400 bad request error when pulling data
// my aim is to print firebase json data to serial monitor but html texts are coming to serial monitor i want json data to come
// How we can solve this problem
// fetch data show serial monitor
while (client.connected()) {
String line = client.readStringUntil('\n');
Serial.println(line);
}
// 10 second wait
delay(10000);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Serial Monitor Output
System starting...
GPRS connection done :-)
Local IP: 100.92.154.31
HTTP GET fetch data...
HTTP/1.1 400 Bad Request
// this project firebase json http get request example but I get 400 bad request error when pulling data // my aim is to print firebase json data to serial monitor but html texts are coming to serial monitor i want json data to come // How we can solve this problem
define TINY_GSM_MODEM_SIM800
define TINY_GSM_RX_BUFFER 256
include
include
include
const char apn[] = "internet"; // GPRS APN const char gprsUser[] = ""; // GPRS user const char gprsPass[] = ""; // GPRS şifre
const char host[] = "abcd-7892d-default-rtdb.firebaseio.com"; const char path[] = "/message.json"; const int port = 443;
SoftwareSerial SerialAT(10, 11); // RX, TX pin
TinyGsm modem(SerialAT); TinyGsmClient client(modem);
void setup() { Serial.begin(9600); SerialAT.begin(9600); delay(1000);
if (modem.restart()) { Serial.println((F("System starting..."))); } // GPRS connection create if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { Serial.println((F("GPRS connection error :-( "))); return; } else { Serial.println((F("GPRS connection done :-) "))); IPAddress local = modem.localIP(); Serial.print((F("Local IP: "))); Serial.println(local); } delay(5000); }
void loop() { // http get fetch path Serial.println("HTTP GET fetch data..."); if (client.connect(host,port)) { client.print(F("GET")); client.print(path); client.println(F(" HTTP/1.1")); client.print("Host:"); client.print(host); client.println(F("Accept: application/json")); client.println(F("Cache-Control: no-cache")); client.println(); } else { Serial.println("Connection error :-("); }
// fetch data show serial monitor while (client.connected()) { String line = client.readStringUntil('\n'); Serial.println(line); } // 10 second wait delay(10000); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Serial Monitor Output
System starting... GPRS connection done :-) Local IP: 100.92.154.31 HTTP GET fetch data... HTTP/1.1 400 Bad Request
Server: nginx
Date: Sun, 05 Mar 2023 09:52:39 GMT
Content-Type: text/html
Content-Length: 150
Connection: close
Strict-Transport-Security: max-age=31556926; includeSubDomains; preload
400 Bad Request