BeeeOn Gateway
v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
|
The class represents Philips Hue Bridge. Provides functions to control the bulbs. It means turn on, turn off, modify dim, get state of bulb. More...
#include <PhilipsHueBridge.h>
Public Types | |
typedef Poco::SharedPtr < PhilipsHueBridge > | Ptr |
typedef uint64_t | BulbID |
Public Member Functions | |
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 is thrown. More... | |
std::string | authorize (const std::string &deviceType="BeeeOn#gateway") |
Authorization of the gateway to Philips Hue Bridge. It starts by sending an HTTP authorization request. After that, the user has to press the button on the bridge at a certain time. This generates a username by which we can control the bridge. More... | |
void | requestSearchNewDevices () |
Prepares POST HTTP request containing request to search new devices command and sends it to device via HTTP. If the device do not respond in specified timeout, Poco::TimeoutException is thrown. More... | |
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. If the device do not respond in specified timeout, Poco::TimeoutException is thrown. More... | |
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 via HTTP. If the device do not respond in specified timeout, Poco::TimeoutException is thrown. More... | |
std::string | requestDeviceState (const uint32_t ordinalNumber) |
Prepares GET HTTP request containing request state of proper device command and sends it to device via HTTP. If the device do not respond in specified timeout, Poco::TimeoutException is thrown. Return the body of HTTP response. More... | |
Poco::Net::SocketAddress | address () const |
void | setAddress (const Poco::Net::SocketAddress &address) |
MACAddress | macAddress () const |
std::string | username () const |
void | setCredentials (const Poco::SharedPtr< PasswordCredentials > credential, const Poco::SharedPtr< CryptoConfig > config) |
uint32_t | countOfBulbs () |
Poco::FastMutex & | lock () |
PhilipsHueBridgeInfo | info () |
Static Public Attributes | |
static const Poco::Timespan | SLEEP_BETWEEN_ATTEMPTS = 5 * Timespan::SECONDS |
Friends | |
class | PhilipsHueBulb |
Additional Inherited Members | |
Protected Member Functions inherited from BeeeOn::Loggable | |
void | setupLogger (Poco::Logger *logger=0) const |
Poco::Logger & | logger () const |
Loggable (const ClassInfo &info) | |
Loggable (const std::type_info &info) | |
Static Protected Member Functions inherited from BeeeOn::Loggable | |
static Poco::Logger & | forMethod (const char *name) |
static Poco::Logger & | forClass (const ClassInfo &info) |
static Poco::Logger & | forClass (const std::type_info &info) |
template<typename T > | |
static Poco::Logger & | forInstance (const T *i) |
static void | configureSimple (Poco::Logger &logger, const std::string &level) |
static void | logException (Poco::Logger &logger, const Poco::Message::Priority priority, const Poco::Exception &e, const char *file, size_t line) |
The class represents Philips Hue Bridge. Provides functions to control the bulbs. It means turn on, turn off, modify dim, get state of bulb.
PhilipsHueBridge::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 is thrown.
&address | IP address and port where the device is listening. |
&timeout | HTTP timeout. |
string PhilipsHueBridge::authorize | ( | const std::string & | deviceType = "BeeeOn#gateway" | ) |
Authorization of the gateway to Philips Hue Bridge. It starts by sending an HTTP authorization request. After that, the user has to press the button on the bridge at a certain time. This generates a username by which we can control the bridge.
Example of request's body: { "devicetype":"BeeeOn#gateway" }
Example of successful response's body: [ { "success": { "username": "YTV2PIPXrtrnHFLafGQlcVyrcxSgNo8wv-NQPmVk" } } ]
Example of failed response's body: [ { "error": { "type": 101, "address": "", "description": "link button not pressed" } } ]
list< pair< string, pair< uint32_t, PhilipsHueBridge::BulbID > > > PhilipsHueBridge::requestDeviceList | ( | ) |
Prepares GET HTTP request containing request device list command and sends it to device via HTTP. If the device do not respond in specified timeout, Poco::TimeoutException is thrown.
Example of response's body with one bulb: { "1": { "state": { "on": true, "bri": 51, "alert": "none", "reachable": true }, "swupdate": { "state": "readytoinstall", "lastinstall": null }, "type": "Dimmable light", "name": "Hue white lamp 1", "modelid": "LWB006", "manufacturername": "Philips", "uniqueid": "00:17:88:01:10:5c:34:5f-0b", "swversion": "5.38.1.15095" } }
string PhilipsHueBridge::requestDeviceState | ( | const uint32_t | ordinalNumber | ) |
Prepares GET HTTP request containing request state of proper device command and sends it to device via HTTP. If the device do not respond in specified timeout, Poco::TimeoutException is thrown. Return the body of HTTP response.
Example of response's body: { "state": { "on": true, "bri": 51, "alert": "none", "reachable": true }, "swupdate": { "state": "readytoinstall", "lastinstall": null }, "type": "Dimmable light", "name": "Hue white lamp 1", "modelid": "LWB006", "manufacturername": "Philips", "uniqueid": "00:17:88:01:10:5c:34:5f-0b", "swversion": "5.38.1.15095" }
bool PhilipsHueBridge::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 via HTTP. If the device do not respond in specified timeout, Poco::TimeoutException is thrown.
Example of request's body of setting brightness to 155: { "bri":155 }
Example of successful response's body: [ { "success": { "/lights/1/state/bri": 155 } } ]
Example of failed response's body: [ { "error": { "type": 2, "address": "/lights/1/state", "description": "body contains invalid json" } } ]
void PhilipsHueBridge::requestSearchNewDevices | ( | ) |
Prepares POST HTTP request containing request to search new devices command and sends it to device via HTTP. If the device do not respond in specified timeout, Poco::TimeoutException is thrown.
Example of successful response's body: [ { "success": { "/lights": "Searching for new devices" } } ]