19 mosq = mosquitto_new(NULL,
true, NULL);
22 cerr <<
"Failed to create Mosquitto object" << endl;
26 if ( OpenConnection())
28 cerr <<
"Failed to connect to server" << endl;
38 if ( OpenConnection())
42 int s = mosquitto_publish(mosq, NULL, _topic.c_str(), message.size(), message.c_str(), 0,
false);
43 if (s != MOSQ_ERR_SUCCESS)
45 cerr <<
"Failed to publish message: " << mosquitto_strerror(s) << endl;
46 mosquitto_destroy(mosq);
57 mosquitto_destroy(mosq);
58 mosquitto_lib_cleanup();
65 int rc = mosquitto_connect(mosq, _hostname.c_str(), _port, 60);
66 if (rc != MOSQ_ERR_SUCCESS)
68 cerr <<
"Failed to connect to MQTT broker: " << mosquitto_strerror(rc) <<
" on port " << _port << endl;
69 mosquitto_destroy(mosq);
80 mosquitto_disconnect(mosq);