Post by hicani123 on May 31, 2023 23:14:53 GMT
Hello, I am having an issue with posting data to my firebase database. My board has power, GPS, GPRS, and LTE, but it cannot post.
This is the error message I am getting.
Here is my code
#include "BotleticsSIM7000.h" // github.com/botletics/Botletics-SIM7000/tree/main/src
#define SIMCOM_7000
#define PROTOCOL_HTTP_POST // Generic
#define BOTLETICS_PWRKEY 6
#define RST 7
#define TX 10 // Microcontroller RX
#define RX 11 // Microcontroller TX
#include <SoftwareSerial.h>
SoftwareSerial modemSS = SoftwareSerial(TX, RX);
SoftwareSerial *modemSerial = &modemSS;
Botletics_modem_LTE modem = Botletics_modem_LTE();
uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);
char imei[16] = {0}; // Use this for device ID
uint8_t type;
uint16_t battLevel = 0; // Battery level (percentage)
float latitude, longitude, speed_kph, heading, altitude, second;
uint16_t year;
uint8_t month, day, hour, minute;
uint8_t counter = 0;
//char PIN[5] = "1234"; // SIM card PIN
char URL[200]; // Make sure this is long enough for your request URL
char body[100]; // Make sure this is long enough for POST body
char latBuff[12], longBuff[12], locBuff[50], speedBuff[12],
headBuff[12], altBuff[12], tempBuff[12], battBuff[12];
void setup()
{
Serial.begin(9600);
Serial.println(F("*** SIMCom Module IoT Example ***"));
pinMode(RST, OUTPUT);
digitalWrite(RST, HIGH); // Default state
modem.powerOn(BOTLETICS_PWRKEY); // Power on the module
moduleSetup(); // Establishes first-time serial comm and prints IMEI
modem.setFunctionality(1); // AT+CFUN=1
modem.setNetworkSettings(F("mobilenet"));
//modem.setPreferredMode(38); // Use LTE only, not 2G
modem.setPreferredLTEMode(1); // Use LTE CAT-M only, not NB-IoT
while (!modem.enableGPS(true)) {
Serial.println(F("Failed to turn on GPS, retrying..."));
delay(2000); // Retry every 2s
}
Serial.println(F("Turned on GPS!"));
if (!modem.enableGPRS(false)) Serial.println(F("Failed to disable GPRS!"));
// Turn on GPRS
while (!modem.enableGPRS(true)) {
Serial.println(F("Failed to enable GPRS, retrying..."));
delay(2000); // Retry every 2s
}
Serial.println(F("Enabled GPRS!"));
while (!netStatus()) {
Serial.println(F("Failed to connect to cell network, retrying..."));
delay(2000); // Retry every 2s
}
Serial.println(F("Connected to cell network!"));
}
void loop()
{
while (!modem.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude)) {
Serial.println(F("Failed to get GPS location, retrying..."));
delay(2000); // Retry every 2s
}
Serial.println(F("---------------------"));
Serial.print(F("Latitude: ")); Serial.println(latitude, 6);
Serial.print(F("Longitude: ")); Serial.println(longitude, 6);
Serial.println(F("---------------------"));
dtostrf(latitude, 1, 6, latBuff);
dtostrf(longitude, 1, 6, longBuff);
counter = 0;
sprintf(URL, "https://fir-test-93ea5.firebaseio.com/Temperature.json");
sprintf(body, "%s",latBuff);
//sprintf(URL, "http://dweet.io/dweet/for/%s", imei);
//sprintf(body, "{\"lat\":%s,\"long\":%s}", latBuff, longBuff);
while (counter < 3 && !modem.postData("POST", URL,body)) {
Serial.println(F("Failed to complete HTTP POST..."));
counter++;
delay(1000);
}
}
void moduleSetup() {
// SIM7000 takes about 3s to turn on and SIM7500 takes about 15s
// Press Arduino reset button if the module is still turning on and the board doesn't find it.
// When the module is on it should communicate right after pressing reset
// Software serial:
modemSS.begin(115200); // Default SIM7000 shield baud rate
Serial.println(F("Configuring to 9600 baud"));
modemSS.println("AT+IPR=9600"); // Set baud rate
delay(100); // Short pause to let the command run
modemSS.begin(9600);
if (! modem.begin(modemSS)) {
Serial.println(F("Couldn't find modem"));
while (1); // Don't proceed if it couldn't find the device
}
type = modem.type();
Serial.println(F("Modem is OK"));
Serial.print(F("Found "));
switch (type) {
case SIM800L:
Serial.println(F("SIM800L")); break;
case SIM800H:
Serial.println(F("SIM800H")); break;
case SIM808_V1:
Serial.println(F("SIM808 (v1)")); break;
case SIM808_V2:
Serial.println(F("SIM808 (v2)")); break;
case SIM5320A:
Serial.println(F("SIM5320A (American)")); break;
case SIM5320E:
Serial.println(F("SIM5320E (European)")); break;
case SIM7000:
Serial.println(F("SIM7000")); break;
case SIM7070:
Serial.println(F("SIM7070")); break;
case SIM7500:
Serial.println(F("SIM7500")); break;
case SIM7600:
Serial.println(F("SIM7600")); break;
default:
Serial.println(F("")); break;
}
// Print module IMEI number.
uint8_t imeiLen = modem.getIMEI(imei);
if (imeiLen > 0) {
Serial.print("Module IMEI: "); Serial.println(imei);
}
}
bool netStatus() {
int n = modem.getNetworkStatus();
Serial.print(F("Network status ")); Serial.print(n); Serial.print(F(": "));
if (n == 0) Serial.println(F("Not registered"));
if (n == 1) Serial.println(F("Registered (home)"));
if (n == 2) Serial.println(F("Not registered (searching)"));
if (n == 3) Serial.println(F("Denied"));
if (n == 4) Serial.println(F("Unknown"));
if (n == 5) Serial.println(F("Registered roaming"));
if (!(n == 1 || n == 5)) return false;
else return true;
}
This is the error message I am getting.
Here is my code
#include "BotleticsSIM7000.h" // github.com/botletics/Botletics-SIM7000/tree/main/src
#define SIMCOM_7000
#define PROTOCOL_HTTP_POST // Generic
#define BOTLETICS_PWRKEY 6
#define RST 7
#define TX 10 // Microcontroller RX
#define RX 11 // Microcontroller TX
#include <SoftwareSerial.h>
SoftwareSerial modemSS = SoftwareSerial(TX, RX);
SoftwareSerial *modemSerial = &modemSS;
Botletics_modem_LTE modem = Botletics_modem_LTE();
uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);
char imei[16] = {0}; // Use this for device ID
uint8_t type;
uint16_t battLevel = 0; // Battery level (percentage)
float latitude, longitude, speed_kph, heading, altitude, second;
uint16_t year;
uint8_t month, day, hour, minute;
uint8_t counter = 0;
//char PIN[5] = "1234"; // SIM card PIN
char URL[200]; // Make sure this is long enough for your request URL
char body[100]; // Make sure this is long enough for POST body
char latBuff[12], longBuff[12], locBuff[50], speedBuff[12],
headBuff[12], altBuff[12], tempBuff[12], battBuff[12];
void setup()
{
Serial.begin(9600);
Serial.println(F("*** SIMCom Module IoT Example ***"));
pinMode(RST, OUTPUT);
digitalWrite(RST, HIGH); // Default state
modem.powerOn(BOTLETICS_PWRKEY); // Power on the module
moduleSetup(); // Establishes first-time serial comm and prints IMEI
modem.setFunctionality(1); // AT+CFUN=1
modem.setNetworkSettings(F("mobilenet"));
//modem.setPreferredMode(38); // Use LTE only, not 2G
modem.setPreferredLTEMode(1); // Use LTE CAT-M only, not NB-IoT
while (!modem.enableGPS(true)) {
Serial.println(F("Failed to turn on GPS, retrying..."));
delay(2000); // Retry every 2s
}
Serial.println(F("Turned on GPS!"));
if (!modem.enableGPRS(false)) Serial.println(F("Failed to disable GPRS!"));
// Turn on GPRS
while (!modem.enableGPRS(true)) {
Serial.println(F("Failed to enable GPRS, retrying..."));
delay(2000); // Retry every 2s
}
Serial.println(F("Enabled GPRS!"));
while (!netStatus()) {
Serial.println(F("Failed to connect to cell network, retrying..."));
delay(2000); // Retry every 2s
}
Serial.println(F("Connected to cell network!"));
}
void loop()
{
while (!modem.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude)) {
Serial.println(F("Failed to get GPS location, retrying..."));
delay(2000); // Retry every 2s
}
Serial.println(F("---------------------"));
Serial.print(F("Latitude: ")); Serial.println(latitude, 6);
Serial.print(F("Longitude: ")); Serial.println(longitude, 6);
Serial.println(F("---------------------"));
dtostrf(latitude, 1, 6, latBuff);
dtostrf(longitude, 1, 6, longBuff);
counter = 0;
sprintf(URL, "https://fir-test-93ea5.firebaseio.com/Temperature.json");
sprintf(body, "%s",latBuff);
//sprintf(URL, "http://dweet.io/dweet/for/%s", imei);
//sprintf(body, "{\"lat\":%s,\"long\":%s}", latBuff, longBuff);
while (counter < 3 && !modem.postData("POST", URL,body)) {
Serial.println(F("Failed to complete HTTP POST..."));
counter++;
delay(1000);
}
}
void moduleSetup() {
// SIM7000 takes about 3s to turn on and SIM7500 takes about 15s
// Press Arduino reset button if the module is still turning on and the board doesn't find it.
// When the module is on it should communicate right after pressing reset
// Software serial:
modemSS.begin(115200); // Default SIM7000 shield baud rate
Serial.println(F("Configuring to 9600 baud"));
modemSS.println("AT+IPR=9600"); // Set baud rate
delay(100); // Short pause to let the command run
modemSS.begin(9600);
if (! modem.begin(modemSS)) {
Serial.println(F("Couldn't find modem"));
while (1); // Don't proceed if it couldn't find the device
}
type = modem.type();
Serial.println(F("Modem is OK"));
Serial.print(F("Found "));
switch (type) {
case SIM800L:
Serial.println(F("SIM800L")); break;
case SIM800H:
Serial.println(F("SIM800H")); break;
case SIM808_V1:
Serial.println(F("SIM808 (v1)")); break;
case SIM808_V2:
Serial.println(F("SIM808 (v2)")); break;
case SIM5320A:
Serial.println(F("SIM5320A (American)")); break;
case SIM5320E:
Serial.println(F("SIM5320E (European)")); break;
case SIM7000:
Serial.println(F("SIM7000")); break;
case SIM7070:
Serial.println(F("SIM7070")); break;
case SIM7500:
Serial.println(F("SIM7500")); break;
case SIM7600:
Serial.println(F("SIM7600")); break;
default:
Serial.println(F("")); break;
}
// Print module IMEI number.
uint8_t imeiLen = modem.getIMEI(imei);
if (imeiLen > 0) {
Serial.print("Module IMEI: "); Serial.println(imei);
}
}
bool netStatus() {
int n = modem.getNetworkStatus();
Serial.print(F("Network status ")); Serial.print(n); Serial.print(F(": "));
if (n == 0) Serial.println(F("Not registered"));
if (n == 1) Serial.println(F("Registered (home)"));
if (n == 2) Serial.println(F("Not registered (searching)"));
if (n == 3) Serial.println(F("Denied"));
if (n == 4) Serial.println(F("Unknown"));
if (n == 5) Serial.println(F("Registered roaming"));
if (!(n == 1 || n == 5)) return false;
else return true;
}