Giter Club home page Giter Club logo

Comments (3)

fpagliughi avatar fpagliughi commented on September 16, 2024

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.

ShuiYunXi avatar ShuiYunXi commented on September 16, 2024

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:
image
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.

ShuiYunXi avatar ShuiYunXi commented on September 16, 2024

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:
image

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.