From 7539890b5c9ae2a20062ea63ed23b705a2704090 Mon Sep 17 00:00:00 2001 From: JDierkse Date: Sun, 14 Apr 2019 22:52:33 +0200 Subject: [PATCH] Add use of DomoticaServer API for Bluetooth Addresses --- Application/PresenceDetection.cc | 12 ++++++------ Bluetooth/Device.cpp | 11 +++++++++-- Bluetooth/Device.h | 2 +- PresenceDetection.ini | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Application/PresenceDetection.cc b/Application/PresenceDetection.cc index b706c8e..001762a 100644 --- a/Application/PresenceDetection.cc +++ b/Application/PresenceDetection.cc @@ -126,14 +126,14 @@ int main(int argc, char** argv) std::shared_ptr pBluetoothDevice; if (bluetooth) { - std::string devices; - boost::optional bluetoothDevices = pt.get_child_optional("Bluetooth.Devices"); - if (bluetoothDevices) - devices = pt.get("Bluetooth.Devices"); + std::string inventoryURL; + boost::optional bluetoothInventoryURL = pt.get_child_optional("Bluetooth.Inventory"); + if (bluetoothInventoryURL) + inventoryURL = pt.get("Bluetooth.Inventory"); else - throw std::runtime_error("Bluetooth Devices directive missing in ini file."); + throw std::runtime_error("Bluetooth Inventory directive missing in ini file."); - pBluetoothDevice = std::make_shared(devices, target); + pBluetoothDevice = std::make_shared(inventoryURL, target); } sigset_t wset; diff --git a/Bluetooth/Device.cpp b/Bluetooth/Device.cpp index 4720ec7..c5523c1 100644 --- a/Bluetooth/Device.cpp +++ b/Bluetooth/Device.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "Util/JSON.h" #include "Functions.h" #include "Device.h" @@ -8,10 +9,16 @@ namespace PresenceDetection { namespace Bluetooth { -Device::Device(const std::string& devices, const std::string& target) : +Device::Device(const std::string& inventoryURL, const std::string& target) : m_target(target) { - boost::split(m_devices, devices, boost::is_any_of(",")); + std::string devices = m_httpClient.GetUrlContents(inventoryURL); + Util::JSON json = Util::JSON::parse(devices); + + for (auto& element : json) + if (element["bluetooth"] != "") + m_devices.push_back(element["bluetooth"]); + Start(); } diff --git a/Bluetooth/Device.h b/Bluetooth/Device.h index c1b1480..9b1074f 100644 --- a/Bluetooth/Device.h +++ b/Bluetooth/Device.h @@ -13,7 +13,7 @@ namespace Bluetooth { class Device { public: - Device(const std::string& devices, const std::string& target); + Device(const std::string& inventoryURL, const std::string& target); ~Device(); void Start(); diff --git a/PresenceDetection.ini b/PresenceDetection.ini index 31ccd34..b3e31fb 100644 --- a/PresenceDetection.ini +++ b/PresenceDetection.ini @@ -11,4 +11,4 @@ Password = CookieFile = /tmp/UniFi_Cookies [Bluetooth] -Devices = +Inventory =