Skip to content

Commit

Permalink
Merge pull request #462 from mtconnect/460_461_mqtt_adapter_issues
Browse files Browse the repository at this point in the history
fixed two issues with disconnect and no termiinal '/'  interpreted as topic
  • Loading branch information
wsobel authored Jun 14, 2024
2 parents b903f15 + 34093f8 commit cd82ee3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set(AGENT_VERSION_MAJOR 2)
set(AGENT_VERSION_MINOR 3)
set(AGENT_VERSION_PATCH 0)
set(AGENT_VERSION_BUILD 10)
set(AGENT_VERSION_BUILD 11)
set(AGENT_VERSION_RC "")

# This minimum version is to support Visual Studio 2019 and C++ feature checking and FetchContent
Expand Down
2 changes: 1 addition & 1 deletion src/mtconnect/configuration/agent_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ namespace mtconnect::configuration {
string host, protocol, path;
auto url = *GetOption<string>(options, configuration::Url);

boost::regex pat("^([^:]+)://([^:/]+)(:[0-9]+)?(/?.+)");
boost::regex pat("^([^:]+)://([^:/]+)(:[0-9]+)?(/.+)?");
boost::match_results<string::const_iterator> match;
if (boost::regex_match(url, match, pat))
{
Expand Down
2 changes: 1 addition & 1 deletion src/mtconnect/configuration/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ namespace mtconnect {
boost::optional<std::string> command;
boost::optional<std::string> config;

const char *argp[3] = {"agent", "run", (const char *) configFile};
const char *argp[3] = {"agent", "run", (const char *)configFile};
auto options = g_service->parseOptions(3, argp, command, config);
g_service->initialize(options);

Expand Down
24 changes: 17 additions & 7 deletions src/mtconnect/mqtt/mqtt_client_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace mtconnect {
m_password = GetOption<std::string>(options, configuration::MqttPassword);

std::stringstream url;
url << "mqtt://" << m_host << ':' << m_port;
url << "mqtt://" << m_host << ':' << m_port << '/';
m_url = url.str();

// Some brokers require specific ClientID provided.
Expand Down Expand Up @@ -153,7 +153,7 @@ namespace mtconnect {
else
{
LOG(info) << "MQTT ConnAck: MQTT connection failed: " << ec;
reconnect();
disconnected();
}
return true;
});
Expand All @@ -162,12 +162,9 @@ namespace mtconnect {
LOG(info) << "MQTT " << m_url << ": connection closed";
// Queue on a strand
m_connected = false;
if (m_handler && m_handler->m_disconnected)
m_handler->m_disconnected(shared_from_this());
m_handler->m_disconnected(shared_from_this());
if (m_running)
{
reconnect();
disconnected();
return true;
}
else
Expand All @@ -180,7 +177,7 @@ namespace mtconnect {
LOG(error) << "error: " << ec.message();
m_connected = false;
if (m_running)
reconnect();
disconnected();
});

client->set_publish_handler([this](mqtt::optional<std::uint16_t> packet_id,
Expand Down Expand Up @@ -359,6 +356,19 @@ namespace mtconnect {
m_handler->m_receive(shared_from_this(), string(topic), string(contents));
}

void disconnected()
{
NAMED_SCOPE("MqttClientImpl::disconnected");

LOG(info) << "Calling handler disconnected";

if (m_handler && m_handler->m_disconnected)
m_handler->m_disconnected(shared_from_this());

if (m_running)
reconnect();
}

/// <summary>
///
/// </summary>
Expand Down

0 comments on commit cd82ee3

Please sign in to comment.