Skip to content

Commit

Permalink
Merge pull request #464 from mtconnect/460_461_mqtt_adapter_issues
Browse files Browse the repository at this point in the history
Improved host and port handling in MQTT adapter. Fixed options in the…
  • Loading branch information
wsobel authored Jun 19, 2024
2 parents 810664c + fb92f10 commit ca58d1f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 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 11)
set(AGENT_VERSION_BUILD 13)
set(AGENT_VERSION_RC "")

# This minimum version is to support Visual Studio 2019 and C++ feature checking and FetchContent
Expand Down
6 changes: 6 additions & 0 deletions src/mtconnect/configuration/agent_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,10 +950,16 @@ namespace mtconnect::configuration {
ConfigOptions adapterOptions = options;

GetOptions(block.second, adapterOptions, options);
// Erase the host and port so they can be properly defaulted.
adapterOptions.erase(configuration::Host);
adapterOptions.erase(configuration::Port);

AddOptions(block.second, adapterOptions,
{{configuration::Url, string()},
{configuration::Device, string()},
{configuration::UUID, string()},
{configuration::Host, string()},
{configuration::Port, int32_t()},
{configuration::Heartbeat, std::chrono::milliseconds()},
{configuration::Uuid, string()}});

Expand Down
2 changes: 1 addition & 1 deletion src/mtconnect/source/adapter/adapter_pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ namespace mtconnect::source::adapter {
void buildObservationDelivery(pipeline::TransformPtr next);

protected:
ConfigOptions m_options;
StringList m_devices;
std::optional<std::string> m_device;
std::string m_identity;
ConfigOptions m_options;
};
} // namespace mtconnect::source::adapter
8 changes: 7 additions & 1 deletion src/mtconnect/source/adapter/mqtt/mqtt_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ namespace mtconnect {
{
m_options[configuration::MqttHost] = m_options[configuration::Host];
}
if (!HasOption(m_options, configuration::MqttPort))

if (!HasOption(m_options, configuration::MqttPort) &&
HasOption(m_options, configuration::Port))
{
m_options[configuration::MqttPort] = m_options[configuration::Port];
}
else if (!HasOption(m_options, configuration::MqttPort))
{
m_options[configuration::MqttPort] = 1883;
}
Expand Down
3 changes: 0 additions & 3 deletions src/mtconnect/source/adapter/mqtt/mqtt_adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ namespace mtconnect::source::adapter::mqtt_adapter {

void build(const ConfigOptions &options) override;
Handler *m_handler {nullptr};

protected:
ConfigOptions m_options;
};

/// @brief An Mqtt adapter to connnect to another Agent and replicate data
Expand Down

0 comments on commit ca58d1f

Please sign in to comment.