MQTT Connection Issue: ESP32 + SIMCOM A7670

  Kiến thức lập trình

Description: I’m facing a significant problem with my current project involving the integration of a SIMCOM A7670 module with an ESP32 to establish an MQTT connection. Despite carefully following the code provided at [insert link to your code here] and other resources like [insert link to the other thread here], I’m still unable to get the device to connect to the MQTT server.

Problem Details:

Hardware Used: ESP32 and SIMCOM A7670.

Libraries Used: I’m using the TinyGsmClient.h and PubSubClient.h libraries.

**Problem Description: **The main issue lies in the device not connecting to the MQTT server, preventing it from subscribing to the desired topic and receiving or sending MQTT messages.

Steps Taken: I’ve meticulously reviewed my code, ensuring it’s properly tailored to my hardware and network configuration. Additionally, I’ve verified the physical hardware connections and the network setup on the MQTT server.

Error Messages: Upon attempting to establish the MQTT connection, I don’t receive specific error messages that could indicate the root cause of the problem. Simply put, the device fails to connect to the MQTT server.

Code

#define TINY_GSM_MODEM_SIM7600
#define TINY_GSM_RX_BUFFER 256
#define SerialAT Serial1

#include <TinyGsmClient.h>
#include <PubSubClient.h>

TinyGsm modem(SerialAT);
TinyGsmClient client(modem);
PubSubClient mqtt(client);

const char* mqtt_server = "io.adafruit.com";
const int mqtt_port = 1883;
const char* mqtt_topic = "prueba";

void reconnect() {
  while (!mqtt.connected()) {
    Serial.println("Conectando al broker MQTT...");
    if (mqtt.connect("ESP8266Client")) {
      Serial.println("Conectado al broker MQTT");
      mqtt.subscribe(mqtt_topic);
    } else {
      Serial.print("Error de conexión al broker MQTT, rc=");
      Serial.print(mqtt.state());
      Serial.println(" Intentando de nuevo en 5 segundos");
      delay(5000);
    }
  }
}

void setup() {
  Serial.begin(115200);
  SerialAT.begin(115200, SERIAL_8N1, 16, 17);

  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);
  delay(1000);

  Serial.println("Inicializando modem...");

  mqtt.setServer(mqtt_server, mqtt_port);
}

void loop() {
  if (!mqtt.connected()) {
    reconnect();
  }
  mqtt.loop();
}

**
Purpose of the Post: My primary goal is to seek the community’s assistance in identifying the root cause of this MQTT connection problem. I appreciate any guidance, advice, or solutions that can be offered to overcome this obstacle.

I hope this helps you kick off a constructive discussion on your forum and get the assistance you need to resolve this MQTT connection issue! Let me know if you need further details or any clarifications.

Purpose of the Post: My primary goal is to seek the community’s assistance in identifying the root cause of this MQTT connection problem. I appreciate any guidance, advice, or solutions that can be offered to overcome this obstacle.

New contributor

Google cuenta Pruebas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT