Fix Bluetooth Ping Timeout

This commit is contained in:
2019-02-04 21:35:20 +01:00
parent d114c685d0
commit b623ba5003
5 changed files with 113 additions and 87 deletions
+32 -41
View File
@@ -71,7 +71,7 @@ bool Device::Login()
catch (const std::exception& e)
{
std::stringstream ss;
ss << "UniFiDevice::Login() - Error: " << e.what() << std::endl;
ss << "UniFi::Device::Login() - Error: " << e.what() << std::endl;
syslog(LOG_ERR, "%s", ss.str().c_str());
std::lock_guard<std::mutex> lock(m_mutex);
m_loggedIn = false;
@@ -98,7 +98,7 @@ void Device::Logout()
catch (const std::exception& e)
{
std::stringstream ss;
ss << "UniFiDevice::Logout() - Error: " << e.what() << std::endl;
ss << "UniFi::Device::Logout() - Error: " << e.what() << std::endl;
syslog(LOG_ERR, "%s", ss.str().c_str());
}
}
@@ -156,7 +156,7 @@ void Device::UpdatePresentDevices()
catch (const std::exception& e)
{
std::stringstream ss;
ss << "UniFiDevice::IsDevicePresent() - Error: " << e.what() << std::endl;
ss << "UniFi::Device::IsDevicePresent() - Error: " << e.what() << std::endl;
syslog(LOG_ERR, "%s", ss.str().c_str());
Logout();
return;
@@ -167,49 +167,40 @@ void Device::UpdatePresentDevices()
removedDevices.push_back(*it);
for (std::vector<std::string>::iterator it = addedDevices.begin(); it != addedDevices.end(); ++it)
{
std::stringstream ss;
ss << "UniFi: + " << *it;
syslog(LOG_INFO, "%s", ss.str().c_str());
std::stringstream url;
url << m_target << "/UniFi/+/" << *it;
try
{
m_httpClient.GetUrlSilent(url.str());
}
catch (const std::exception& e)
{
std::stringstream ss;
ss << "UniFiDevice::UpdatePresentDevices() - Error: " << e.what() << std::endl;
syslog(LOG_ERR, "%s", ss.str().c_str());
}
}
SendStateChange(true, *it);
for (std::vector<std::string>::iterator it = removedDevices.begin(); it != removedDevices.end(); ++it)
{
std::stringstream ss;
ss << "UniFi: - " << *it;
syslog(LOG_INFO, "%s", ss.str().c_str());
std::stringstream url;
url << m_target << "/UniFi/-/" << *it;
try
{
m_httpClient.GetUrlSilent(url.str());
}
catch (const std::exception& e)
{
std::stringstream ss;
ss << "UniFiDevice::UpdatePresentDevices() - Error: " << e.what() << std::endl;
syslog(LOG_ERR, "%s", ss.str().c_str());
}
}
SendStateChange(false, *it);
m_presentDevices.assign(presentDevices.begin(), presentDevices.end());
}
void Device::SendStateChange(bool present, const std::string& macAddress)
{
char sign;
if (present)
sign = '+';
else
sign = '-';
std::stringstream ss;
ss << "UniFi: " << sign << " " << macAddress;
syslog(LOG_INFO, "%s", ss.str().c_str());
std::stringstream url;
url << m_target << "/UniFi/" << sign << "/" << macAddress;
try
{
m_httpClient.GetUrlSilent(url.str());
}
catch (const std::exception& e)
{
std::stringstream ss;
ss << "UniFi::Device::SendStateChange() - Error: " << e.what() << std::endl;
syslog(LOG_ERR, "%s", ss.str().c_str());
}
}
} // namespace UniFi
} // namespace PresenceDetection
+1
View File
@@ -26,6 +26,7 @@ private:
void Logout();
void UpdatePresentDevices();
void SendStateChange(bool present, const std::string& macAddress);
private:
Util::Timer m_timer;