Hi guys, I am facing a issue when trying to make HTTP Post and HTTP Get Commands using A9G Module with arduino Meg. I Want to post data to firebase realtime database and also read data from the same database using A9g GPRS internet connectivity but my code cant seem to work and i dont know whats the problem, and i am always getting CME error 58. could you please help me. this is the code:
#include <SoftwareSerial.h>
SoftwareSerial A9GSerial(10, 11); // RX, TX
void setup() {
Serial.begin(115200);
A9GSerial.begin(115200);
delay(5000);
}
void loop() {
// information to be posted
float temperature = 25.5;
float humidity = 60.0;}
void initializeA9G() {
sendATCommand("AT");
delay(5000);
sendATCommand("AT+CFUN=1"); // Enable full functionality (disable airplane mode)
delay(5000);
}
bool checkNetworkRegistration() {
sendATCommand("AT+CREG?");
delay(1000);
// Check the response for network registration status
if (A9GSerial.find("+CREG: 1,1") || A9GSerial.find("+CREG: 0,5")) {
return true;
} else {
return false;
}
}
bool attachGPRS() {
sendATCommand("AT+CGATT=1");
delay(5000);
// Check if GPRS is attached
if (A9GSerial.find("+CGATT: 1")) {
return true;
} else {
return false;
}
}
bool connectToInternet() {
sendATCommand("AT+CGDCONT=1,\"IP\",\"m-internet\"");
delay(2000);
sendATCommand("AT+CGACT=1,1");
delay(5000);
// Check if PDP activation is successful
if (A9GSerial.find("OK")) {
return true;
} else {
return false;
}
}
bool sendDataToFirebase(float temperature, float humidity) {
String firebaseURL = "https://base-de-dados-mmaip-default-rtdb.firebaseio.com/sensorData";
// Create JSON data
String jsonData = "{\"temperature\":" + String(temperature, 2) + ", \"humidity\":" + String(humidity, 2) + "}";
sendATCommand("AT+HTTPINIT");
delay(2000);
sendATCommand("AT+HTTPPARA=\"CID\",1");
sendATCommand("AT+HTTPPARA=\"URL\",\"" + firebaseURL + "\"");
sendATCommand("AT+HTTPPARA=\"CONTENT\",\"application/json\"");
sendATCommand("AT+HTTPDATA=" + String(jsonData.length()) + ",10000");
sendATCommand(jsonData);
sendATCommand("AT+HTTPACTION=1");
delay(15000);
// Check if HTTP POST was successful
if (A9GSerial.find("HTTPACTION: 1,200")) {
return true;
} else {
return false;
}
}
void sendATCommand(String command) {
A9GSerial.println(command);
delay(500);
Serial.print("Command: ");
Serial.println(command);
while (A9GSerial.available()) {
char c = A9GSerial.read();
Serial.print(c);
}
Serial.println();
}