I have been trying to get the example project SendDataOverMQTT to work for the past few days, but am currently stuck. This is using Workbench version 3.6.1. I’ve tried to follow the relevant guides and forum posts. After flashing the project to the XDK I get the following output (abbreviated):
INFO | XDK_DEVICE_1: WLANPersonalWPA2Connect : Connected to WPA network successfully.
INFO | XDK_DEVICE_1: MqttEventHandler : Event - 2
INFO | XDK_DEVICE_1: AppControllerFire : MQTT connection to the broker failed
INFO | XDK_DEVICE_1: MqttEventHandler : Event - 3
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: 134
The only changes I made to the example project were editing the WiFi and MQTT settings in the app header file (XDK is connecting to WiFi so that doesn't seem to be a problem). MQTT settings are as follows:
#define APP_MQTT_BROKER_HOST_URL "broker.hivemq.com"
#define APP_MQTT_BROKER_HOST_PORT UINT16_C(1883)
I have also tried setting the host URL to "test.mosquitto.org" but either way I've had no luck. I can ping both URLs from the command line so I believe the problem is on the XDK side. As far as I can tell the error is coming from the MQTT module of the XDK application, but I can't make sense of the 134 error code. As for the MqttEventHandler outputs, I think these correspond to MQTT_CONNECT_SEND_FAILED and MQTT_CONNECT_TIMEOUT, respectively. I'm not sure if this means that the XDK initially connects to the MQTT broker and then the send fails or if there is never any connection at all. I've tried re-importing the example several times but each time I get the same error.
Again, I'm getting this error after only changing the four lines in the app header file that I mentioned. Reading through the documentation I've tried changing a few more things but still get the same error:
- Changing line 61 in Serval_Defines.h from #define SERVAL_ENABLE_MQTT 0 to #define SERVAL_ENABLE_MQTT 1 (does this enable support for the MQTT protocol?)
- Changing the package contents from the humidity, pressure and temp sensor outputs to "test" (I tried the example StreamSensorDataOverUsb and got it to work, so I don't think the problem is with the sensors)
- Changing various values in the AppController.c file, such as increasing the various timeout variables on lines 83-87, increasing the .KeepAliveInterval on line 176, activating and deactivating various sensors, and changing the QOS levels for subscribe and publish.
I'm considering either deleting and reinstalling the XDK software (maybe I mistakenly changed something in the original example file) or trying this on a different WiFi network (perhaps I need special permissions to send data over MQTT?). I'm still new to using the XDK so any help would be appreciated.
Solved! Go to Solution.
From the error code mentioned, XDK is unable to connect to MQTT broker. Are you using secured/unsecured MQTT connection ?
Also ensure whether valid server broker is used.
Changing WiFi network may not be necessary since your XDK is connected to WiFi network successfully. Please make sure your WiFi network has internet access to reach the extenal broker like mosquitto/hive.
There is no need to reinstall XDK workbench for XDK connection error with broker.
Thanks for the reply. I'm using an unsecured MQTT connection; APP_MQTT_SECURE_ENABLE is set to 0 in the header file. I think that both broker.hivemq.com and test.mosquitto.org are valid brokers. I'm able to connect to the HiveMQ browser client and when I ping test.mosquitto.org I get a response. Is there another way to see if these are valid?
I have downloaded XDK workbench v3.6.1 and use the SendDataOverMQTT application.
I used local mosquitto broker and following configurations has been changed in AppController.h,
Environment sensor data has been received in MQTT broker. Attached screenshot.
Possible issues with your setup,
Thanks for the reply. I did some more testing. As you showed, I was able to connect to a locally hosted Mosquitto broker with the XDK. In addition, using Eclipse Paho I am able to connect my PC to test.mosquitto.org, broker.hivemq.com, iot.eclipse.org and even an MQTT broker I created through AWS. I am not able to connect to these using the XDK. As you pointed out I think the Firewall on my local network is blocking the XDK from connecting to these brokers. Have you heard of this happening before? I'll do some more testing and let you know what I find.