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
+29 -44
View File
@@ -45,59 +45,44 @@ void Device::UpdatePresentDevices()
if (Functions::Ping(*it))
{
if (std::find(m_presentDevices.begin(), m_presentDevices.end(), *it) == m_presentDevices.end())
addedDevices.push_back(*it);
SendStateChange(true, *it);
presentDevices.push_back(*it);
}
}
for (std::vector<std::string>::iterator it = m_presentDevices.begin(); it != m_presentDevices.end(); ++it)
if (std::find(presentDevices.begin(), presentDevices.end(), *it) == presentDevices.end())
removedDevices.push_back(*it);
for (std::vector<std::string>::iterator it = addedDevices.begin(); it != addedDevices.end(); ++it)
{
std::stringstream ss;
ss << "Bluetooth: + " << *it;
syslog(LOG_INFO, "%s", ss.str().c_str());
std::stringstream url;
url << m_target << "/Bluetooth/+/" << *it;
try
{
m_httpClient.GetUrlSilent(url.str());
}
catch (const std::exception& e)
{
std::stringstream ss;
ss << "BluetoothDevice::UpdatePresentDevices() - Error: " << e.what() << std::endl;
syslog(LOG_ERR, "%s", ss.str().c_str());
}
}
for (std::vector<std::string>::iterator it = removedDevices.begin(); it != removedDevices.end(); ++it)
{
std::stringstream ss;
ss << "Bluetooth: - " << *it;
syslog(LOG_INFO, "%s", ss.str().c_str());
std::stringstream url;
url << m_target << "/Bluetooth/-/" << *it;
try
{
m_httpClient.GetUrlSilent(url.str());
}
catch (const std::exception& e)
{
std::stringstream ss;
ss << "BluetoothDevice::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 << "Bluetooth: " << sign << " " << macAddress;
syslog(LOG_INFO, "%s", ss.str().c_str());
std::stringstream url;
url << m_target << "/Bluetooth/" << sign << "/" << macAddress;
try
{
m_httpClient.GetUrlSilent(url.str());
}
catch (const std::exception& e)
{
std::stringstream ss;
ss << "Bluetooth::Device::SendStateChange() - Error: " << e.what() << std::endl;
syslog(LOG_ERR, "%s", ss.str().c_str());
}
}
} // namespace Bluetooth
} // namespace PresenceDetection