简体   繁体   中英

Cross compiling code using Paho MQTT C & C++ libraries causing issues when publishing with a nonzero QoS

I have tried cross-compiling some small C++ code for a Raspberry Pi Model 3b using my Windows machine via Ubuntu-20.04 on WSL2. It uses the Paho MQTT C and C++ libraries to subscribe to and sometimes publish some messages. I'm pretty sure that most of it works since MQTT subscriptions work, as well as publishing messages using a QoS of 0.

However, when publishing with a QoS of 1 or 2, I get a runtime error: MQTT error [-9]: Invalid QoS value

When I try publishing with a QoS less than 0 or greater than 2, I get this instead: MQTT error [-9]: Bad QoS

I have compiled the same code in the RPi itself and the code runs without any issues.

I'm not completely sure what is happening, but I tried checking why I'm getting the same reason code but different error messages. It appears that the Bad QoS message is written in mqtt/message.h, which can be found in the C++ library, while the Invalid QoS Value can be found in MQTTAsync.c, from the C library.

As far as I know MQTT only supports 3 levels of QoS. QoS 0, 1 and 2. Thus using "QoS less than 0 or greater than 2" will indeed give the "Invalid QoS Value" Error. I suspect cross compilation is doing something unintended. It would be great if you could share more information about the project. Like What MQTT broker do you use? How do you cross compile etc.

Thank You. Naveen PS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM