|
@@ -40,7 +40,8 @@ void Bridge::Start()
|
|
|
m_pHttpServer.reset(new Http::HttpServer(m_port, httpCallback));
|
|
m_pHttpServer.reset(new Http::HttpServer(m_port, httpCallback));
|
|
|
|
|
|
|
|
m_pWebSocketSubscription.reset(new WebSocketSubscription(m_toonSettings));
|
|
m_pWebSocketSubscription.reset(new WebSocketSubscription(m_toonSettings));
|
|
|
- m_messageHandler.Connect(std::bind(&Bridge::TimeToLiveCallback, this, m_pWebSocketSubscription.get(), std::placeholders::_1));
|
|
|
|
|
|
|
+ m_messageHandler.Connect(std::bind(&Bridge::ReconnectCallback, this, m_pWebSocketSubscription.get()));
|
|
|
|
|
+ m_messageCheckTimer.StartContinuous(300000, static_cast<std::function<void()>>(std::bind(&Bridge::CheckMessageReceived, this)));
|
|
|
|
|
|
|
|
std::stringstream ss;
|
|
std::stringstream ss;
|
|
|
ss << m_mqttSettings.topic << "/BridgeState";
|
|
ss << m_mqttSettings.topic << "/BridgeState";
|
|
@@ -60,27 +61,57 @@ Http::HttpServer::HttpReply Bridge::HttpCallback(const std::string& uri, const s
|
|
|
{
|
|
{
|
|
|
if (postData.size() > 0)
|
|
if (postData.size() > 0)
|
|
|
{
|
|
{
|
|
|
- for (auto& data : postData)
|
|
|
|
|
|
|
+ for (auto& item : postData)
|
|
|
{
|
|
{
|
|
|
- if (data.name == "data")
|
|
|
|
|
- m_messageHandler.HandleMessage(data.value);
|
|
|
|
|
|
|
+ if (item.name == "data")
|
|
|
|
|
+ m_messageHandler.HandleMessage(item.value);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
catch (const std::exception& e)
|
|
catch (const std::exception& e)
|
|
|
{
|
|
{
|
|
|
- std::stringstream ss;
|
|
|
|
|
- ss << "Bridge::HttpCallback() - Error: " << e.what() << std::endl;
|
|
|
|
|
- Logging::Log(Logging::Severity::Error, ss.str());
|
|
|
|
|
|
|
+ std::string data;
|
|
|
|
|
+ for (auto& item : postData)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (item.name == "data")
|
|
|
|
|
+ data = (item.value);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
+ m_messageReceived = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return reply;
|
|
return reply;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void Bridge::TimeToLiveCallback(ToonBridge::Toon::WebSocketSubscription* pSubscription, int timeToLive)
|
|
|
|
|
|
|
+void Bridge::ReconnectCallback(ToonBridge::Toon::WebSocketSubscription* pSubscription)
|
|
|
|
|
+{
|
|
|
|
|
+ std::stringstream ss;
|
|
|
|
|
+ ss << "Bridge::TimeToLiveCallback() - TTL Expired, reconnecting" << std::endl;
|
|
|
|
|
+ Logging::Log(Logging::Severity::Info, ss.str());
|
|
|
|
|
+
|
|
|
|
|
+ pSubscription->Reconnect();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void Bridge::CheckMessageReceived()
|
|
|
{
|
|
{
|
|
|
- if (timeToLive < 20)
|
|
|
|
|
- pSubscription->Reconnect();
|
|
|
|
|
|
|
+ bool messageReceived;
|
|
|
|
|
+ {
|
|
|
|
|
+ std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
+ messageReceived = m_messageReceived;
|
|
|
|
|
+ m_messageReceived = false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!messageReceived)
|
|
|
|
|
+ {
|
|
|
|
|
+ std::stringstream ss;
|
|
|
|
|
+ ss << "Bridge::CheckMessageReceived() - No message received for 5 minutes, reconnecting" << std::endl;
|
|
|
|
|
+ Logging::Log(Logging::Severity::Info, ss.str());
|
|
|
|
|
+
|
|
|
|
|
+ m_pWebSocketSubscription->Reconnect();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} // namespace Toon
|
|
} // namespace Toon
|