Comments (3)
It's really hard to tell what's happening here, with pieces of code missing and others formatted in lots of different styles.
It might be helpful if you can reduce this down to a minimal example that fails, posted in a text code block. This should be pretty small, since it seems to be failing right on the client construction.
But the error from the console is pretty clear. The library is claiming that you're giving it a string that is not UTF-8. Are you using Unicode or wide char strings? Sorry I don't know much about Windows and MSVS, and how it is configured.
from paho.mqtt.cpp.
ok,I built a simplest case. The function of this case is to create a client. I tried to let it print some messages to help me analyze the cause of the problem, but still failed. The code is as follows:
#include <iostream>
#include <string>
#include "mqtt/async_client.h"
const std::string SERVER_ADDRESS("tcp://broker.emqx.io:1883");
const std::string CLIENT_ID("example_client");
int main() {
try {
std::cout << "Creating MQTT client..." << std::endl;
mqtt::async_client cli(SERVER_ADDRESS, CLIENT_ID);
std::cout << "MQTT client created successfully." << std::endl;
mqtt::connect_options connOpts;
connOpts.set_clean_session(true);
std::cout << "Connecting to the MQTT server..." << std::flush;
auto connToken = cli.connect(connOpts);
connToken->wait();
std::cout << "Connected!" << std::endl;
std::cout << "Disconnecting from the MQTT server..." << std::flush;
cli.disconnect()->wait();
std::cout << "Disconnected!" << std::endl;
}
catch (const mqtt::exception& exc) {
std::cerr << "MQTT exception: " << exc.what() << std::endl;
return 1;
}
catch (const std::exception& exc) {
std::cerr << "Standard exception: " << exc.what() << std::endl;
return 1;
}
catch (...) {
std::cerr << "Unknown exception occurred." << std::endl;
return 1;
}
return 0;
}
The program running results are as follows:
Note that I have successfully added and built the paho-mqtt3as.lib and paho-mqttpp3.lib libraries to my project, and I can run the server using the paho-mqtt-c version. But this exception still exists. The C++ library version I use is 1.4.0, and the C library version is: 1.3.13. I am not sure if there is any conflict between the two libraries. I hope to get your help. Thank you.
from paho.mqtt.cpp.
OK,I have been Sovled the fatal error! this is a Bug in 1.4.0version.Because I rolled back the code to 1.3.2, the previous version, and rebuilt from the source, the issue was resolved. My code as follow:
#include <iostream>
#include <string>
#include "mqtt/async_client.h"
const std::string SERVER_ADDRESS("tcp://broker.emqx.io:1883");
const std::string CLIENT_ID("example_client");
int main() {
try {
std::cout << "Creating MQTT client..." << std::endl;
mqtt::async_client cli(SERVER_ADDRESS, CLIENT_ID);
std::cout << "MQTT client created successfully." << std::endl;
mqtt::connect_options connOpts;
connOpts.set_clean_session(true);
std::cout << "Connecting to the MQTT server..." << std::flush;
auto connToken = cli.connect(connOpts);
connToken->wait();
std::cout << "Connected!" << std::endl;
std::cout << "Disconnecting from the MQTT server..." << std::flush;
cli.disconnect()->wait();
std::cout << "Disconnected!" << std::endl;
}
catch (const mqtt::exception& exc) {
std::cerr << "MQTT exception: " << exc.what() << std::endl;
return 1;
}
catch (const std::exception& exc) {
std::cerr << "Standard exception: " << exc.what() << std::endl;
return 1;
}
catch (...) {
std::cerr << "Unknown exception occurred." << std::endl;
return 1;
}
return 0;
}
and it's run of result as follow:
Hopefully this information gives you some ideas on how to fix this BUG. Thank you very much for your help
from paho.mqtt.cpp.
Related Issues (20)
- MQTT traffic over Https Proxy HOT 1
- MQTTAsync_send cpu load increases a lot while buffering messages HOT 2
- Subscribe to broker creates a random queue HOT 2
- Arm cross compile fails on version 1.3.x - disconnect options HOT 1
- SESSION_EXPIRY_INTERVAL is int, not uint HOT 7
- token->wait() hangs when publishing from 2 threads HOT 4
- Build error on Windows 11 - Visual Studio community 2022 - Cmake 3.29.6 HOT 7
- Running unit tests in GitHub CI Action on Windows
- Generated docs are empty HOT 2
- Confusion with oudated installation instructions - can't find paho-mqtt3a HOT 14
- msg->get_properties() not working in message_arrived HOT 4
- Paho sync client ssl return "Error: MQTT error [-13]: SSL is not supported [0]" HOT 12
- Is there a need to resubscribe to topics in async client clean_session(false) when disconnect event [-3] occurs. HOT 2
- paho-mqtt3a-static not found(does not already exist) HOT 2
- async_client does not use MQTTAsync_connect5 when connecting to MQTT brokers with protocol version 5 HOT 2
- 如何设置本地指定的ip 和 服务端建立连接 HOT 2
- Do you know which interface to call to set the specified network ip HOT 1
- mqtt\ssl_options.h(470): error C2062: type 'auto' unexpected HOT 7
- can't use get method in properties because of missing const HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from paho.mqtt.cpp.