A7670E with ESP32 Devkit v1 and Level Shifter GSM-MQTT (uart connection) connection

Greetings ,

I'm trying to establish mqtt connection using AT commands in the form of :

// Function to send AT command and check for expected response

bool sendATCommand(String command, String expectedResponse)

I have managed to properly setup the SIM that i'm using following this sequence

  • AT+CFUN
  • ATEO
  • AT
  • AT+CPIN
  • AT+GMR
  • AT+CSQ
  • AT+COPS
  • AT+CREG
  • AT+CNMP
  • AT+CMEE
  • AT+CGDCONT
  • AT+CGACT
    (these seem to work properly)

MQTT Connection

  • AT+CMQTTSTART (works properly)
    *AT+CMQTTACCQ=0,"myClient"", "OK");
  • AT+CMQTTCON=0 (returns +CMQTTCONNECT: 0,0 )
  • AT+CMQTTKEEPALIVE (Sending command: AT+CMQTTKEEPALIVE=0,30
    Received response: ERROR)
  • AT+CMQTTSUBTOPIC=0,20,0 (ERROR)
  • AT+CMQTTSUB=0,20,0 (ERROR)
    The code that i'm using the is the following :
void initializeMQTT() 
{
  uint8_t retries = 3;
  bool commandSuccess = true;
  //Initialize MQTT stack
  do{
    sendATCommand("AT+CMQTTSTART", "OK");
    delay(2000);
    retries--;
  }while(!commandSuccess && retries > 0);

  if(!commandSuccess)
  {
    Serial.println("Failed to initialize MQTT stack.");
    return;
  }
  
  //Initialize MQTT client
  retries = 3;
  do{
    sendATCommand("AT+CMQTTACCQ=0,\"myClient\"", "OK");
    delay(2000);
    retries--;
  }while(!commandSuccess && retries > 0);

  if(!commandSuccess)
  {
    Serial.println("Failed to initialize MQTT client.");
    return;
  }
 

  //Connect to MQTT server
  retries = 3;
  do{
      sendATCommand("AT+CMQTTCONNECT=0,\"tcp://broker.hivemq.com:1883/\",60,0", "+CMQTTCONNECT: 0,0,0");
      delay(2000);
      sendATCommand("AT+CMQTTKEEPALIVE=0,30", "OK");
      delay(2000);
    retries--;
  }while(!commandSuccess && retries > 0);

  if(!commandSuccess)
  {
    Serial.println("Failed to connect to MQTT server.");
    return;
  }

The main issue that i have is that even after initializing the mqtt stack properly , and connecting to the broker i'm unable to progress further. Any suggestions or feedback would be appreciated.
I followed this datasheet: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/datasheet/module/sim7680/A76XX%20Series_MQTT(S)_Application%20Note_V1.02.pdf

// Connect to the broker
    sendATCommand("AT+CMQTTCONNECT=0,\"tcp://broker.hivemq.com:1883/\",60,0", "+CMQTTCONNECT: 0,0,0");
    delay(2000);

    // Set the keep alive time to 30 seconds
    sendATCommand("AT+CMQTTKEEPALIVE=0,30", "OK");
    delay(2000);

    // Subscribe to the topic "test/topic"
    sendATCommand("AT+CMQTTSUB=0,20,0,\"test/topic\",0", "+CMQTTSUBACK: 0,0,0");
    delay(5000);

    if (gsmSerial.available() > 0) 
    {
      String response = gsmSerial.readString();
      Serial.println(response); // Debug

    if (response.indexOf("+CMQTTSUB: 0,") != -1) 
    {
      if (response.indexOf("hello there") != -1) 
      {        
        Serial.println("Received message:hello there"); //debug
        gsmSerial.println("AT+CMQTTPUBLISH=0,\"test/topic\",0,0,\"hello there\"");
      }
    } 
  }

Thank you for your time.

Disclaimer : Pardon if not in right category.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.