MQTT connection to the broker failed
응답
18. 12. 19 오전 11:52

Hallo,

I'm trying to send data to MQTT Broker but failed.

I used the demo SendDataOverMQTT and configed the Session, what I changed is that I added a username and password because I saw they were added to XDK_MQTT.h and I think maybe now it is suppourted. The code shows below:

static MQTT_Connect_T MqttConnectInfo =
        {
                .ClientId = APP_MQTT_CLIENT_ID,
                .BrokerURL = APP_MQTT_BROKER_HOST_URL,
                .BrokerPort = APP_MQTT_BROKER_HOST_PORT,
                .CleanSession = true,
                .KeepAliveInterval = 100,
                .device_uname = "my username",
                .device_pw = "my password",
        };/*< MQTT connect parameters */

After flashed the code to my XDK it showed the erro message as below:

 INFO | XDK DEVICE 1: MqttEventHandler : Event - 1
 INFO | XDK DEVICE 1: AppControllerFire : MQTT connection to the broker failed
 INFO | XDK DEVICE 1: Error in XDK110 Application package.
 INFO | XDK DEVICE 1:  Package ID: 153
 INFO | XDK DEVICE 1:  Module ID: 39
 INFO | XDK DEVICE 1:  Severity code: 2
 INFO | XDK DEVICE 1:  Error code: 119
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 4
 INFO | XDK DEVICE 1: Error in XDK110 Application package.
 INFO | XDK DEVICE 1:  Package ID: 153
 INFO | XDK DEVICE 1:  Module ID: 39
 INFO | XDK DEVICE 1:  Severity code: 2
 INFO | XDK DEVICE 1:  Error code: 120

 Could you please tell me what's wrong with it?

Kind Regards,

Jiachen

0 (0 투표)
RE: MQTT connection to the broker failed
응답
18. 12. 19 오후 1:27 as a reply to Jiachen ZHAO.
Hello Jiachen,

If you look up the MQTT error codes the problem seems to be "Connection Refused, unacceptable protocol version" which you can look up here .

The follwing errors your are receiving can be tracked as follows:

Package ID 153: can be found inside SDK/XDK110/common/source/SystemStartup.c
which in your case is XDK110 Application
Module ID 39: can be found inside SDK/XDK110/common/include/XdkCommonInfo.h
which corresponds to the MQTT module
Error IDs are found in the XdkCommonInfo.h aswell
114, 119 and 120 are
RETCODE_MQTT_CONNECT_FAILED
RETCODE_MQTT_CONNECT_STATUS_ERROR
RETCODE_MQTT_CONNECTION_CLOSED

What MQTT broker are you trying to connect to? Did you verify that you are using a compatible mqtt version?
The recent workbench versions should be using MQTT version 3.1.1.

Kind regards,
Franjo
0 (0 투표)
RE: MQTT connection to the broker failed
응답
18. 12. 20 오후 1:07 as a reply to Franjo Stjepandic.

Thank you for replying.

I used the MQTT Broker: j56zrt7.mqtt.iot.gz.baidubce.com.

What i want is to connect a MQTT broker with username and password. Firstly, I added

.device_uname = "my username" and.device_pw = "my password"

to static MQTT_Connect_T MqttConnectInfo  in the code demo SendDataOverMQTT.

And it showed the erro. I think i can't just change this two sentences to connect a MQTT Broker which include a username and password.

Sencondly, I've also modified the MQTT.c file, I added StringDescr_wrap(&username, connect->device_uname);

MqttSession.username = username;

StringDescr_wrap(&password, connect->device_pw); 

MqttSession.password = password;in line 442.

It seems connect to the MQTT broker successfully and it shows the Info as below:       

 INFO | XDK DEVICE 1: WLANPersonalWPA2Connect : Connected to WPA network successfully.
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 0
 INFO | XDK DEVICE 1: MQTT_SubsribeToTopic : Subscribing to topic: $baidu/iot/shadow/xdk110_instance/update, Qos: 1
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 8
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 15
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 15
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 15

I think it means Publishing.

Please ignore the bild i don't know how to delete it.

Kind Regards,

Jiachen

0 (0 투표)
RE: MQTT connection to the broker failed
응답
18. 12. 20 오후 2:37 as a reply to Jiachen ZHAO.
Hello Jiachen,
I agree, that it looks like you connected and published successfully.
 
  1. Event -0: Triggered if the connection has been successfully established.
  2. Event -8: Triggered when the subscribe response is received from the server. Manual checking for subscription acceptance is required.
  3. Event -15: Triggered after a publish, once it is save to release / free the data. Note that for QoS 2 this is after the final complete message.
This is copied from the EvenHandler event list: xdk/Libraries/ServalStack/3rd-party/ServalStack/api/Serval_Mqtt.h
The next step would be to publish data through a payload and confirm the data on the broker.

If you have any questions, feel free to ask.

Kind regards,
Franjo
0 (0 투표)
RE: MQTT connection to the broker failed
응답
18. 12. 20 오후 2:58 as a reply to Franjo Stjepandic.

Thank you for replying.

So far i have succeed in publishing all the sensor data to the broker and i also succeed in the Visualisation of the data in Cloud.

Next step i'm going to user XDK kit to do some deeper research.

Best Regards,

Jiachen 

0 (0 투표)
RE: MQTT connection to the broker failed
응답
18. 12. 21 오후 1:47 as a reply to Jiachen ZHAO.
Hello Jiachen,
I'm really glad that this setup is working now.
Out of personal interest, what are you trying to do? What is the use case?
Kind regards,
Franjo
0 (0 투표)
RE: MQTT connection to the broker failed
응답
18. 12. 31 오전 7:09 as a reply to Franjo Stjepandic.

Hallo,

We are going to setup a IoT infrstructure. Using the XDK as intelligent sensor to gather the device data. And send the data to Cloud, analysing them with the help of Bigdata, to do some very fundamental reserch about predictive maintenance.

Best Regards,

Jiachen

 

0 (0 투표)
RE: MQTT connection to the broker failed
응답
18. 12. 31 오후 12:10 as a reply to Jiachen ZHAO.
Dear Jiachen,

Thank you for providing further information on your project. Using the XDK in combination with predictive maintenance sounds really interesting.

Please feel free to ask if you have any kind of further concern or question.

Kind regards,
Franjo
0 (0 투표)