BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
PhilipsHueBridge.h
1 #pragma once
2 
3 #include <list>
4 #include <string>
5 
6 #include <Poco/Mutex.h>
7 #include <Poco/SharedPtr.h>
8 #include <Poco/Timespan.h>
9 #include <Poco/Dynamic/Var.h>
10 #include <Poco/Net/HTTPRequest.h>
11 #include <Poco/Net/SocketAddress.h>
12 
13 #include "credentials/PasswordCredentials.h"
14 #include "net/HTTPEntireResponse.h"
15 #include "net/MACAddress.h"
16 #include "philips/PhilipsHueBridgeInfo.h"
17 #include "util/CryptoConfig.h"
18 #include "util/Loggable.h"
19 
20 namespace BeeeOn {
21 
27 class PhilipsHueBridge : protected Loggable {
28 public:
29  friend class PhilipsHueBulb;
30 
31  typedef Poco::SharedPtr<PhilipsHueBridge> Ptr;
32  typedef uint64_t BulbID;
33 
34  static const Poco::Timespan SLEEP_BETWEEN_ATTEMPTS;
35 
43  const Poco::Net::SocketAddress& address,
44  const Poco::Timespan& timeout);
45 
52  std::string authorize(const std::string& deviceType = "BeeeOn#gateway");
53 
60 
68  std::list<std::pair<std::string, std::pair<uint32_t, PhilipsHueBridge::BulbID>>> requestDeviceList();
69 
77  bool requestModifyState(
78  const uint32_t ordinalNumber,
79  const std::string& capability,
80  const Poco::Dynamic::Var value);
81 
88  std::string requestDeviceState(const uint32_t ordinalNumber);
89 
90  Poco::Net::SocketAddress address() const;
91  void setAddress(const Poco::Net::SocketAddress& address);
92  MACAddress macAddress() const;
93  std::string username() const;
94  void setCredentials(const Poco::SharedPtr<PasswordCredentials> credential,
95  const Poco::SharedPtr<CryptoConfig> config);
96 
97  uint32_t countOfBulbs();
98  Poco::FastMutex& lock();
99 
100  PhilipsHueBridgeInfo info();
101 
102 private:
103  void requestDeviceInfo();
104 
109  PhilipsHueBridge::BulbID decodeBulbID(const std::string& strBulbID) const;
110 
114  void incrementCountOfBulbs();
115 
119  void decrementCountOfBulbs();
120 
121  HTTPEntireResponse sendRequest(
122  Poco::Net::HTTPRequest& request,
123  const std::string& message,
124  const Poco::Net::SocketAddress& address,
125  const Poco::Timespan& timeout);
126 
127 private:
128  Poco::Net::SocketAddress m_address;
129  MACAddress m_macAddr;
130  Poco::SharedPtr<PasswordCredentials> m_credential;
131  Poco::SharedPtr<CryptoConfig> m_cryptoConfig;
132 
133  Poco::FastMutex m_lockCountOfBulbs;
134  int m_countOfBulbs;
135 
136  Poco::FastMutex m_lock;
137  Poco::Timespan m_httpTimeout;
138 };
139 
140 }
void requestSearchNewDevices()
Prepares POST HTTP request containing request to search new devices command and sends it to device vi...
Definition: PhilipsHueBridge.cpp:120
The class represents Philips Hue Bridge. Provides functions to control the bulbs. It means turn on...
Definition: PhilipsHueBridge.h:27
std::string requestDeviceState(const uint32_t ordinalNumber)
Prepares GET HTTP request containing request state of proper device command and sends it to device vi...
Definition: PhilipsHueBridge.cpp:274
Definition: HTTPEntireResponse.h:13
std::list< std::pair< std::string, std::pair< uint32_t, PhilipsHueBridge::BulbID > > > requestDeviceList()
Prepares GET HTTP request containing request device list command and sends it to device via HTTP...
Definition: PhilipsHueBridge.cpp:161
Definition: MACAddress.h:8
bool requestModifyState(const uint32_t ordinalNumber, const std::string &capability, const Poco::Dynamic::Var value)
Prepares JSON message containing request modify state command of proper device and sends it to device...
Definition: PhilipsHueBridge.cpp:215
PhilipsHueBridge(const Poco::Net::SocketAddress &address, const Poco::Timespan &timeout)
Creates Philips Hue Bridge. If the device do not respond in specified timeout, Poco::TimeoutException...
Definition: PhilipsHueBridge.cpp:31
Definition: Loggable.h:19
Abstract class representing generic Philips Hue bulb.
Definition: PhilipsHueBulb.h:23
Definition: PhilipsHueBridgeInfo.h:12
std::string authorize(const std::string &deviceType="BeeeOn#gateway")
Authorization of the gateway to Philips Hue Bridge. It starts by sending an HTTP authorization reques...
Definition: PhilipsHueBridge.cpp:67