Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT - Fix Interrupt in connection on request files #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/AgrirouterClient/inc/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#define MG_PARAMETER_CONNECTION_TYPE (MG_PARAMETER_BASE + 17)
#define MG_PARAMETER_POLLING_INTERVAL (MG_PARAMETER_BASE + 18)
#define MG_PARAMETER_POLLING_MAX_TIME (MG_PARAMETER_BASE + 19)
#define MG_PARAMETER_MQTT_KEEP_ALIVE_TIME (MG_PARAMETER_BASE + 20)

#define MG_EV_BASE 200
#define MG_EV_CAPABILITIES (MG_EV_BASE + CAPABILITIES)
Expand Down Expand Up @@ -93,6 +94,7 @@

// Other definitions
#define DEFAULT_CHUNK_SIZE 300000 // 0,3 MB
#define DEFAULT_KEEP_ALIVE_TIME 240 // 240 s

// Protobuf typedefs
typedef agrirouter::request::RequestEnvelope RequestEnvelope;
Expand Down
3 changes: 3 additions & 0 deletions lib/AgrirouterClient/inc/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class Settings
int getPollingInterval();
void setPollingMaxTime(int pollingMaxTime);
int getPollingMaxTime();
void setMqttKeepAliveTime(int keepAliveTime);
int getMqttKeepAliveTime();

private:
onParameterChangeCallback m_onParameter;
Expand Down Expand Up @@ -128,6 +130,7 @@ class Settings
// For general purposes
int m_pollingInterval = 0;
int m_pollingMaxTime = 0;
int m_mqttKeepAliveTime = 0;
};

#endif // LIB_AGRIROUTERCLIENT_INC_SETTINGS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ int MqttConnectionClient::init()
(m_mqttErrorCallback) (MG_ERROR_MISSING_OR_EXPIRED_CERTIFICATE, "MqttConnectionClient: MQTT TLS Failed", errorJSON, m_member);
return EXIT_FAILURE;
}
int keepAliveTime = m_settings->getMqttKeepAliveTime();
if(keepAliveTime == 0)
{
keepAliveTime = DEFAULT_KEEP_ALIVE_TIME;
}

int connect = mosquitto_connect_async(m_mosq, m_host.c_str(), m_port, 20);
int connect = mosquitto_connect_async(m_mosq, m_host.c_str(), m_port, keepAliveTime);
if(connect == MOSQ_ERR_SUCCESS)
{
m_settings->callOnLog(MG_LFL_NTC, "MqttConnectionClient: connect set successful - " + std::to_string(connect) + ": " + mosquitto_strerror(connect));
Expand Down
10 changes: 10 additions & 0 deletions lib/AgrirouterClient/src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,13 @@ void Settings::setPollingMaxTime(int pollingMaxTime)
}

int Settings::getPollingMaxTime() { return m_pollingMaxTime; }

void Settings::setMqttKeepAliveTime(int keepAliveTime)
{
m_mqttKeepAliveTime = keepAliveTime;
m_onParameter(MG_PARAMETER_MQTT_KEEP_ALIVE_TIME,
static_cast<void *>(&keepAliveTime),
m_callbackCallee);
}

int Settings::getMqttKeepAliveTime() { return m_mqttKeepAliveTime; }