Issue with MQTT connection on STM32F407G and SIM7600 GSM module
I'm working with an STM32F407G and a SIM7600G GSM module. I've successfully configured the GSM module using AT commands, switched to PPPOS, and obtained a valid IP address, gateway, and netmask using LWIP.
I can successfully resolve the IP address of test.mosquitto.org using netconn_gethostbyname(). However, when I try to connect to the MQTT broker at this IP (5.196.78.28), I keep getting "Connection disconnected" in the MQTT connection callback.
The issue is that after attempting to connect, the callback shows "Connection disconnected" status every time. The IP resolution works, and I'm using LWIP with PPPOS for the GSM connection. Could this be related to protocol issues, or is something missing in my MQTT connection setup? Any guidance would be appreciated!
Here’s the MQTT connection callback and code I’m using:
static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection_status_t status) {
switch (status) {
case MQTT_CONNECT_ACCEPTED:
printf("Connected to MQTT broker\n");
break;
case MQTT_CONNECT_REFUSED_PROTOCOL_VERSION:
printf("Connection refused: Protocol version not supported\n");
break;
case MQTT_CONNECT_REFUSED_IDENTIFIER:
printf("Connection refused: Invalid client identifier\n");
break;
case MQTT_CONNECT_REFUSED_SERVER:
printf("Connection refused: Server unavailable\n");
break;
case MQTT_CONNECT_REFUSED_USERNAME_PASS:
printf("Connection refused: Invalid username or password\n");
break;
case MQTT_CONNECT_REFUSED_NOT_AUTHORIZED_:
printf("Connection refused: Not authorized\n");
break;
case MQTT_CONNECT_DISCONNECTED:
printf("Connection disconnected\n");
break;
case MQTT_CONNECT_TIMEOUT:
printf("Connection timeout\n");
break;
default:
printf("Unknown connection status: %d\n", status);
break;
}
}
void mqtt_connect(mqtt_client_t *client) {
ip_addr_t my_mqtt;
struct mqtt_connect_client_info_t ci;
memset(&ci, 0, sizeof(ci));
ci.client_id = "lwip_testuuuuuu";
ipaddr_aton("5.196.78.28",&my_mqtt);
// Call the connect function with the correct parameters
err_t err = mqtt_client_connect(client,&my_mqtt, MQTTY_PORT,
mqtt_connection_cb, 0, &ci);
if (err != ERR_OK) {
printf("Failed to connect to MQTT broker: %d\r\n", err);
} else {
printf("Connecting to MQTT broker at IP: %s\r\n",
ipaddr_ntoa(&my_mqtt));
}
}
void mqtt_new(){
vTaskDelay(1000);
mqtt_client_t* client;
client = mqtt_client_new();
if (client != NULL){
mqtt_connect(client);
}
}
