connection refused [2107430] ### Closed: 0 #609
-
I am working on gsm with esp32 and sending data on firebase, but connection refused error occur. Here is the code: #define TINY_GSM_MODEM_SIM7600 // SIM7600 AT instruction is compatible with A7670
#define SerialAT Serial1
#define SerialMon Serial
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_DEBUG SerialMon
#define TINY_GSM_USE_WIFI false
#include <Arduino.h>
#include <TinyGsmClient.h>
#include <Firebase_ESP_Client.h>
#include "MPU9250.h"
#include <TinyGPSPlus.h>
#include <addons/TokenHelper.h>
#include <addons/RTDBHelper.h>
// See all AT commands, if wanted
#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif
TinyGsmClient client(modem);
#define GSM_PIN ""
String number = "xxxxxxxxxx";
String _buffer;
TinyGPSPlus gps;
TinyGsmClient gsm_client(modem);
static const uint32_t GPSBaud = 9600;
int sensor = 34;
int ANALOG_IN_PIN = 35;
int Battery_percent;
float GX;
float GY;
float GZ;
int Accx;
int Accy;
int Accz;
MPU9250 mpu;
String battery_alert = "Calling";
float adc_voltage = 0.0;
float voltage = 0.0;
// Floats for resistor values in divider (in ohms)
float R1 = 510.0;
float R2 = 1000.0;
float ref_voltage = 3.3;
int adc_value = 0;
float map(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
const char apn[] = ""; // Your GPRS credentials, if any
const char gprsUser[] = "";
const char gprsPass[] = "";
#define uS_TO_S_FACTOR 1000000ULL // Conversion factor for micro seconds to seconds
#define TIME_TO_SLEEP 600 // Time ESP32 will go to sleep (in seconds)
#define UART_BAUD 115200
#define PIN_TX 26
#define PIN_RX 27
float MQ3;
int Unique_ID;
double Latitude;
double Longitude;
#define API_KEY "My_api"
#define DATABASE_URL "My_url"
#define USER_EMAIL "my_mail"
#define USER_PASSWORD "my_password"
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
unsigned long sendDataPrevMillis = 0;
unsigned long count = 0;
bool signupOK = false;
void setup() {
Serial.begin(9600);
Serial2.begin(9600);
delay(3000);
Wire.begin();
SerialAT.begin(UART_BAUD, SERIAL_8N1, PIN_RX, PIN_TX);
Serial.println("In setup stage 1");
DBG("Wait...");
delay(3000);
DBG("Initializing modem...");
if (!modem.init()) {
DBG("Failed to restart modem, delaying 10s and retrying");
return;
}
modem.setNetworkMode(38);
if (modem.waitResponse(10000L) != 1) {
DBG(" setNetworkMode faill");
}
delay(2000);
String name = modem.getModemName();
DBG("Modem Name:", name);
String modemInfo = modem.getModemInfo();
DBG("Modem Info:", modemInfo);
SerialAT.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000);
Serial.println("In setup stage 2");
Serial_Printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);
Serial.println("In setup stage 3");
config.api_key = API_KEY;
auth.user.email = USER_EMAIL;
auth.user.password = USER_PASSWORD;
Serial.println("In setup stage 4");
config.database_url = DATABASE_URL;
config.token_status_callback = tokenStatusCallback; // see addons/TokenHelper.h
fbdo.setGSMClient(&gsm_client, &modem, GSM_PIN, apn, gprsUser, gprsPass);
Firebase.reconnectNetwork(true);
fbdo.setBSSLBufferSize(4096 /* Rx buffer size in bytes from 512 - 16384 */, 1024 /* Tx buffer size in bytes from 512 - 16384 */);
Firebase.setDoubleDigits(5);
Firebase.begin(&config, &auth);
Serial.println("Firebase Connected successfully");
Serial.println("In setup stage 5");
if (!mpu.setup(0x68)) { // change to your own address
while (1) {
Serial.println("MPU connection failed. Please check your connection with `connection_check` example.");
delay(1000);
return;
}
}
}
void gps_data() {
Serial.print(F("Location: "));
if (gps.location.isValid()) {
Serial.print("Lat: ");
Latitude = gps.location.lat();
Serial.println(Latitude, 6);
Serial.print("Lng: ");
Longitude = gps.location.lng();
Serial.println(Longitude, 6);
}
else {
Serial.println(F("INVALID"));
}
}
void loop() {
while (Serial2.available() > 0)
if (gps.encode(Serial2.read()))
gps_data();
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
}
if (mpu.update()) {
static uint32_t prev_ms = millis();
if (millis() > prev_ms + 25) {
gyroscope_data();
prev_ms = millis();
}
}
if (Firebase.ready() && (millis() - sendDataPrevMillis > 15000 || sendDataPrevMillis == 0)) {
sendDataPrevMillis = millis();
if (Firebase.RTDB.setInt(&fbdo, "/PROD/DeviceLocations/DEV_1004/Battery_percent", Battery_percent)) {
Serial.println("Battery_percent Value Inserted");
} else {
Serial.println("Battery_percent Value Not Inserted");
Serial.println(fbdo.errorReason());
}
if (Firebase.RTDB.setInt(&fbdo, "/PROD/DeviceLocations/DEV_1004/Latitude", Latitude)) {
Serial.println("Latitude Inserted");
} else {
Serial.println(fbdo.errorReason());
}
if (Firebase.RTDB.setInt(&fbdo, "/PROD/DeviceLocations/DEV_1004/Longitude", Longitude)) {
Serial.println("Longitude Inserted");
} else {
Serial.println(fbdo.errorReason());
}
if (Firebase.RTDB.setInt(&fbdo, "/PROD/DeviceLocations/DEV_1004/MQ3", MQ3)) {
Serial.println("MQ3 Value Inserted");
} else {
Serial.println("MQ3 Value Not Inserted");
Serial.println(fbdo.errorReason());
}
if (Firebase.RTDB.setInt(&fbdo, "/PROD/DeviceLocations/DEV_1004/Gx", GX)) {
Serial.println("Gx Value Inserted");
} else {
Serial.println("Gx Value Not Inserted");
Serial.println(fbdo.errorReason());
}
if (Firebase.RTDB.setInt(&fbdo, "/PROD/DeviceLocations/DEV_1004/Gy", GY)) {
Serial.println("Gy Value Inserted");
} else {
Serial.println("Gy Value Not Inserted");
Serial.println(fbdo.errorReason());
}
if (Firebase.RTDB.setInt(&fbdo, "/PROD/DeviceLocations/DEV_1004/Gz", GZ)) {
Serial.println("Gz Value Inserted");
} else {
Serial.println("Gz Value Not Inserted");
Serial.println(fbdo.errorReason());
}
if (Firebase.RTDB.setInt(&fbdo, "/PROD/DeviceLocations/DEV_1004/Accx", Accx)) {
Serial.println("Accx Value Inserted");
} else {
Serial.println("Accx Value Not Inserted");
Serial.println(fbdo.errorReason());
}
if (Firebase.RTDB.setInt(&fbdo, "/PROD/DeviceLocations/DEV_1004/Accy", Accy)) {
Serial.println("Accy Value Inserted");
} else {
Serial.println("Accy Value Not Inserted");
Serial.println(fbdo.errorReason());
}
if (Firebase.RTDB.setInt(&fbdo, "/PROD/DeviceLocations/DEV_1004/Accz", Accz)) {
Serial.println("Accz Value Inserted");
} else {
Serial.println("Accz Value Not Inserted");
Serial.println(fbdo.errorReason());
}
if(Firebase.RTDB.setTimestamp(&fbdo, "/PROD/DeviceLocations/DEV_1004/Timestamp") ){
Serial.println("Timestamp Value Inserted");
} else {
Serial.println("Timestamp Value Not Inserted");
Serial.println(fbdo.errorReason());
}
} else {
Serial.println("outside the loop");
}
display();
gps_data();
delay(500);
}
void callWhenChargingisLow() {
SerialAT.print (F("ATD"));
SerialAT.print (number);
SerialAT.print (F(";\r\n"));
_buffer = SerialAT.readString() ;
Serial.println(_buffer);
}
void display() {
MQ3 = analogRead(sensor);
Serial.print("MQ3: ");
Serial.println(MQ3);
adc_value = analogRead(ANALOG_IN_PIN);
adc_voltage = (adc_value * ref_voltage) / 4096.0;
voltage = adc_voltage / (R2/(R1+R2));
Battery_percent = map(voltage, 2.90 , 3.82 , 00, 100);
Serial.print("Input Voltage = ");
Serial.println(voltage, 2);
Serial.print("Battery_percent= ");
Serial.println(Battery_percent);
Serial.println( );
if ((voltage <= 3.1) && (battery_alert == "Calling")){
Serial.println("Battery percentage is too Low, Please charge the battery");
callWhenChargingisLow();
String reading = SerialAT.readString();
Serial.println(reading);
battery_alert = "Call_sent";
}
if (Battery_percent < 00){
Battery_percent = 00;
}
if (Battery_percent > 100){
Battery_percent = 100;
battery_alert = "Calling";
}
delay(500);
}
void gyroscope_data(){
GX = mpu.getYaw();
Serial.print("Gx: ");
Serial.println(GX);
GY = mpu.getPitch();
Serial.print("Gy: ");
Serial.println(GY);
GZ = mpu.getRoll();
Serial.print("Gz: ");
Serial.println(GZ);
Accx = mpu.getAccX();
Serial.print("Accx: ");
Serial.println(Accx);
Accy = mpu.getAccY();
Serial.print("Accy: ");
Serial.println(Accy);
Accz = mpu.getAccZ();
Serial.print("Accz: ");
Serial.println(Accz);
} Can you tell me the reason ? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
Not only macro Firebase-ESP-Client/examples/ExternalClient/RTDB/GSM/Basic/Basic.ino Lines 15 to 17 in 43d4a98 And make sure your GSM module used SIM7600 compatible modem chip. In case of other GSM modules, you should read the |
Beta Was this translation helpful? Give feedback.
-
Yeah I have added this already, and it was working properly. I think there is another issue.. |
Beta Was this translation helpful? Give feedback.
-
Are you sure your GSM module works? I did not see any debug information. You never even reset the modem. |
Beta Was this translation helpful? Give feedback.
-
yes I am sure. Here is the src/FirebaseFS.h file: `#include "./core/Firebase_Client_Version.h" #ifndef FirebaseFS_H #pragma once #include <Arduino.h> /**📍 Default Main Class */ /** 📌 Predefined Build Options
/**📍 For enabling the device or library time setup from NTP server
/**📍 For enabling the error string from error reason
/**📍 For RTDB class compilation
/**📍 For RTDB Error Queue compilation
/**📍 For Firestore compilation
/**📍 For Firebase Cloud Messaging compilation
/**📍 For Firebase Storage compilation
/**📍 For Google Cloud Storage compilation
/**📍 For Functions for Firebase compilation
/**📍 For enabling PSRAM support
/**📍 For enabling OTA updates support via RTDB, Firebase Storage and Google Cloud Storage buckets
/**📍 For enabling Keep Alive connection mode
/**📌 For enabling flash filesystem support
#if defined(ESP32) || defined(ESP8266) || defined(MB_ARDUINO_PICO) #if defined(ESP8266) || defined(MB_ARDUINO_PICO) #include <LittleFS.h> #elif defined(ESP_ARDUINO_VERSION) /* ESP32 core >= v2.0.x / / ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0) */ #include <LittleFS.h> #else #include <SPIFFS.h> #endif #endif // For ESP32, format SPIFFS or FFat if mounting failed /**📌 For enabling SD filesystem support
/** 🔖 Optional Build Options
*/ #if __has_include("CustomFirebaseFS.h") #include "./core/Firebase_Build_Options.h" #endif` |
Beta Was this translation helpful? Give feedback.
-
The error is about "no server or internet access". You have to check why |
Beta Was this translation helpful? Give feedback.
The error is about "no server or internet access".
You have to check why
TinyGSMClient
cannot connect to server which it can be hardware, code (initialization) and network issues.