SIM800MQTT icon indicating copy to clipboard operation
SIM800MQTT copied to clipboard

problem with MQTT_sub()

Open e0ne199 opened this issue 2 years ago • 6 comments

hello, your library is very great, but currently i am facing an issue on your library...whenever i try to use MQTT_sub(), my terminal says CLOSED (which showed CONNECT before it happened) not long after i call that function...after that, i am unable to send data to the broker except if i call MQTT_Init() which means i have to reinitialize the parameters again...do you know how to solve this issue? i am just able to send data to the broker but i am unable to subscribe to anything to receive data...your help is very appreciated, thx

e0ne199 avatar Nov 01 '21 17:11 e0ne199

Hi. Look at my example https://github.com/leech001/SIM800MQTT/blob/master/examples/MQTTSUB/Core/Src/main.c where the data is sent and received at the same time. If you get a CLOSED response from module it means that connection at TCP session level is broken and it is not the fault of MQTT protocol.

leech001 avatar Nov 02 '21 05:11 leech001

hello, thanks for the response anyway here is the part of my example code for the problem :


	//init internet
	SIM800.sim.apn = "internet";
	SIM800.sim.apn_user = "";
	SIM800.sim.apn_pass = "";
	SIM800.mqttServer.host = "broker.mqtt-dashboard.com";
	SIM800.mqttServer.port = 1883;
	SIM800.mqttClient.username = "";
	SIM800.mqttClient.pass = "";
	SIM800.mqttClient.clientID = "";
	SIM800.mqttClient.keepAliveInterval = 1200;
	
	MQTT_Init();
	
	sub = 0;
	
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
		 if (SIM800.mqttServer.connect == 0) 
		 {
			 
         MQTT_Init();
         sub = 0;
     }
     if (SIM800.mqttServer.connect == 1) 
		 {
         if(sub == 0)
				 {
             MQTT_Sub("publish");
             sub = 1;
         }

				
         MQTT_Pub("publish_2", "test");
				 HAL_Delay(1000);

       if(SIM800.mqttReceive.newEvent) 
				 {
             unsigned char *topic = SIM800.mqttReceive.topic;
             payload = atoi(SIM800.mqttReceive.payload);
            
					   //sprintf(buff,"%s   ",topic);
					   //LCD_Puts(0,0,buff);
					   SIM800.mqttReceive.newEvent = 0;
         }	 
     }
		 //MQTT_PingReq();
     HAL_Delay(1000);
			
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

there is absolutely no problem when sending the messages with only MQTT_Pub() and without MQTT_Sub(), but when i call both of them with MQTT_sub() being called first, the connection is severed and the modem gives CLOSED response..maybe could you please point out the problem in my example code? currently i am using SIM800L for the modem..

e0ne199 avatar Nov 02 '21 22:11 e0ne199

Hi, there is also a problem MQTT_sub() Log Server

2022-08-31 21:47:15: New connection from 176.59.102.197 on port 10317. 2022-08-31 21:47:22: New client connected from 176.59.102.197 as STM32Client (c1, k120, u'u_WK4J2M'). 2022-08-31 21:47:27: Invalid QoS in subscription command from 176.59.102.197, disconnecting.

Kazakoff64 avatar Aug 31 '22 20:08 Kazakoff64

image

The default QoS value of 0 is passed to the subscription function

leech001 avatar Sep 03 '22 09:09 leech001

image

The default QoS value of 0 is passed to the subscription function

У меня равно нулю, или вы предлагаете изменить ?

Kazakoff64 avatar Sep 05 '22 05:09 Kazakoff64

Как вариант можете попробовать изменить если у вас именно ругается на Qos

leech001 avatar Sep 05 '22 16:09 leech001