Go Down

Topic: SIMCOM 7600E ESP32 MQTT client is busy issue (Read 415 times) previous topic - next topic

rykers

Jul 27, 2020, 07:12 am Last Edit: Jul 27, 2020, 07:13 am by rykers
Hi everyone.

I'm desperate for help on this one, I have been working for days trying to figure out a solution to this SIMCOM 7600E modem issue...

I am trying to do a basic MQTT test using the AT command set in the various manuals as a guide..
However no matter what I have tried from information found online... the issue persists.

It seems that the connection itself is fine... however as soon as I try to send a subscribe or publish command, the modem responds with:

+CMQTTSUBTOPIC: 0,14

ERROR


Which according to the manual, means "client is busy"..
https://simcom.ee/documents/SIM7600E/SIM7500_SIM7600%20Series_MQTT_ATC_V1.01.pdf


Can anyone with more exerience with these modems see the issue?

If any more details are required, such as code etc please let me know.

Code: [Select]


=== SENT@4254 ===
AT
==================
=== RECV@4257 ===

OK
==================
=== SENT@4257 ===
ATE0
==================
=== RECV@4260 ===

OK
==================
=== SENT@4260 ===
ATI
==================
=== RECV@4273 ===

Manufacturer: SIMCOM INCORPORATED
Model: SIMCOM_SIM7600E
Revision: SIM7600M21-A_V1.1
IMEI: XXXXXXXXXXXXXXXXXXXXX
+GCAP: ==================
=== RECV@4277 ===
+CGSM

OK
==================
 OK
Registering on network...
=== SENT@4284 ===
AT+CPSI?
==================
=== RECV@4295 ===

+CPSI: LTE,Online,505-01,0x309D,136092930,257,EUTRAN-BAND3,1275,4,4,-178,-1185,-789,7

OK
==================
=== SENT@4300 ===
AT+CREG?
==================
=== RECV@4304 ===

+CREG: 0,1

OK
==================
=== SENT@4309 ===
AT+CGREG?
==================
=== RECV@4314 ===

+CGREG: 0,1

OK
==================
=== SENT@4319 ===
AT+CGDCONT=1,"IP","connect.apn"
==================
=== RECV@4341 ===

OK
==================
=== SENT@4341 ===
AT+CGACT=1,1
==================
=== RECV@4345 ===

OK
==================
OK
Init MQTT...
Connecting...
=== SENT@74524 ===
AT+CMQTTSTART
==================
=== RECV@74533 ===

+CMQTTSTART: 0

OK
==================
=== SENT@75533 ===
AT+CMQTTACCQ=0,"SIMCom_client01",1
==================
=== RECV@75539 ===

OK
==================
=== SENT@77539 ===
AT+CMQTTWILLTOPIC=0,10
==================
=== RECV@77543 ===

>==================
=== SENT@78543 ===
esp32/will
==================
=== RECV@78546 ===

OK
==================
=== SENT@79546 ===
AT+CMQTTWILLMSG=0,4,1
==================
=== RECV@79550 ===

>==================
=== SENT@80550 ===
test
==================
=== RECV@80554 ===

OK
==================
OK, CONNECTION SETUP READY!
CMQTTCONNECT Connecting...
=== SENT@81554 ===
AT+CMQTTCONNECT=0,"tcp://test.mosquitto.org:1883",60,1
==================
=== RECV@81569 ===

OK
==================
CMQTTCONNECT SUCCESS
CONNECTED!
=== SENT@82569 ===
AT+CMQTTSUBTOPIC=0,10,1
==================
=== RECV@82576 ===

+CMQTTSUBTOPIC: 0,14

ERROR
==================
FAILED TO SUBSCRIBE!



pylon

The documentation doesn't say that you're allowed to use a host name instead of an IP address in the MQTTCONNECT command.

rykers

Thanks for your response. Good point the docs don't mention being able to use hostnames.

Just tried with an IP address and same issue unfortunately.

pylon

May be necessary to post your code (don't forget to use code tags!).

rykers

Sure, thanks for your help.

The code is called via various class methods, I'll break it down and post it all shortly.

rykers

Ok so first thing, in the setup function I toggle the power on the SIM7600 module which is on pin 27; then send some AT commands until it responds with OK.

Code: [Select]


digitalWrite(27, HIGH);

if (command("AT\r") && command("ATE0\r") && command("ATI\r")) {
return true;
}




Note that command(command, timeout, expectedResult) simply writes bytes to the module via uart_write_bytes() and returns true/false if successful.


Then some more commands are sent to setup the network, this is done in a loop until it succeeds:

Code: [Select]

bool SIM7600::setup(const char* apn, unsigned int timeout)
{
  uint32_t t = millis();
  bool success = false;
  command("AT+CSQ\r");

  do {
    do {
      if (command("AT+CREG?\r", 1000, "+CREG: 0,")) {
        char *p = strstr(m_buffer, "+CREG: 0,");
        success = (p && (*(p + 9) == '1' || *(p + 9) == '5'));
      }
    } while (!success && millis() - t < timeout);
    if (!success) break;

    success = false;

    command("AT+CGREG?\r");

    do {
      success = command("AT+CPSI?\r", 1000, "Online");
      if (strstr(m_buffer, "Off")) {
        success = false;
        break;
      }
      if (success) {
        if (!strstr(m_buffer, "NO SERVICE"))
          break;
        success = false;
      }
    } while (millis() - t < timeout);
    if (!success) break;

    success = false;

    do {
      if (command("AT+CGREG?\r",1000, "+CGREG: 0,")) {
        char *p = strstr(m_buffer, "+CGREG: 0,");
        success = (p && (*(p + 10) == '1' || *(p + 10) == '5'));
      }
    } while (!success && millis() - t < timeout);
    if (!success) break;

    if (apn && *apn) {
      sprintf(m_buffer, "AT+CGDCONT=1,\"IP\",\"%s\"\r", apn);
      command(m_buffer);
    }
    if (!success) break;

    command("AT+CGACT=1,1\r");
    command("AT+CGACT?\r");

  } while(0);
  return success;
}


Once this has been completed, the celluar network is ready. I have confirmed this by sending HTTP and UDP requests successfully.

Then the MQTT AT commands begin:

Code: [Select]

bool SIM7600MQTT::open(const char *host, uint16_t port)
{
    delay(1000);

    command("AT+CMQTTSTART\r", 1000, "+CMQTTSTART:");

    delay(1000);

    if (!command("AT+CMQTTACCQ=1,\"client c\",0\r"))
    {
        Serial.println("CMQTTACCQ failure");
        return false;
    }

    delay(1000);

    if (!command("AT+CMQTTWILLTOPIC=1,10\r", 1000, "\r\n>"))
    {
        Serial.println("CMQTTWILLTOPIC failure");
        return false;
    }

    delay(1000);

    if (!command("esp32/will\r"))
    {
        Serial.println("CMQTTWILLTOPIC send failure");
        return false;
    }

    delay(1000);

    if (!command("AT+CMQTTWILLMSG=1,4,1\r", 1000, "\r\n>"))
    {
        Serial.println("CMQTTWILLMSG failure");
        return false;
    }

    delay(1000);

    if (!command("test\r"))
    {
        Serial.println("CMQTTWILLMSG send failure");
        return false;
    }

    Serial.println("OK, CONNECTION SETUP READY!");
    delay(1000);

    char cBuffer[38 + strlen(host)];
    sprintf(cBuffer, "AT+CMQTTCONNECT=1,\"tcp://%s:%u\",60,1\r", host, port);

    Serial.println("CMQTTCONNECT Connecting...");

    if (command(cBuffer))
    {
        Serial.println("CMQTTCONNECT SUCCESS");
        m_state = MQTT_CONNECTED;
        command("AT+CMQTTCONNECT?\r");
        return true;

    Serial.println("CMQTTCONNECT FAILED");
    Serial.println(m_buffer);
    m_state = MQTT_ERROR;
    return false;
}


Things work up to this point, and the MQTT client should now be connected...

Now I attempt to subscribe to a topic (or publish a message, same result).

Code: [Select]

bool SIM7600MQTT::subscribe(const char topic[])
{
    if (command("AT+CMQTTSUBTOPIC=1,9,1\r", 1000, "\r\n>")) // This is where the error is returned
    {
        Serial.println("OK, INPUT TOPIC...");
        if (command("esp32/sub\r"))
        {
            Serial.println("OK, SUBSCRIBED!");
            command("AT+CMQTTSUB=1\r");
            return true;
        }
    }

    return false;
}


I hope this helps!


pylon

What is the additional parameter 0 in AT+CMQTTACCQ for? The documentation says index,clientID but no third parameter.

Do you have the possibility to use an MQTT server you have access to the logs? It's much easier to debug if you see what the other party gets.

rykers

I must of added the third parameter in error while trying to debug this.

I have removed it, issue remains.

I will need to look into setting up a MQTT server in order to see logs. I will get onto this tonight.

rykers

#8
Aug 02, 2020, 03:40 am Last Edit: Aug 02, 2020, 05:46 am by rykers
So this has proved to be rather futile.

I setup a MQTT broker using Mosquitto PHP and it doesnt appear to ever register the connection.

I am positive through reading the IP address and HTTP  testing that the SIMCOM module does indeed have a connection to the network.. so its not a connectivity issue.

I read on a hackster.io comment that some have had success after updating the SIMCOM module firmware.. the issue for me with this is that its running a shield via UART on the ESP32, which the SIMCOM USB firmware update tool does not support.

Do you have any experience updating the module firmware via UART? Or is there some sort of serial port to USB device that I can purchase to acheive this?

Thanks again for your help.

Go Up