PHue++ v1.06

Welcome to PHue++, a set of C++ classes which encapsulate the Philips Hue Lights API as defined at https://developers.meethue.com for Windows. The Hue API is implemented as a RESTful interface. PHue++ uses the author's WinHTTPWrappers classes to provide the HTTP connectivity and JSON++ to handle the JSON parsing. All the functionality provided is all included in a C++ namespace called PhilipsHue and is included in one PHue++.h header file.

 

Usage
Copyright
History
API Reference
Contacting the Author

 

 

 

 

Usage

 

 

 

Copyright

 

 

 

History

v1.06 (5 June 2022)

v1.05 (7 November 2021)

v1.04 (1 March 2020)

v1.03 (18 December 2019)

v1.02 (12 October 2019)

v1.01 (28 April 2019)

v1.0 (13 January 2019)

 

 

API Reference

The API consists of the following variables, functions and classes and their methods and variables

 

g_GamutA

 

g_GamutB

 

g_GamutC

 

CErrorResponse

CErrorResponse::m_sAddress
CErrorResponse::m_sDescription
CErrorResponse::m_Type

 

KelvinToMired

 

MiredToKelvin

 

RGBToXY

 

XYToRGB

 

HSLToRGB

 

RGBToHSL

 

UPnPDiscover

 

CLightState

CLightState::m_Alert
CLightState::m_Brightness
CLightState::m_BrightnessInc
CLightState::m_CT
CLightState::m_CTInc
CLightState::m_Effect
CLightState::m_Hue
CLightState::m_HueInc
CLightState::m_On
CLightState::m_Saturation

CLightState::m_SaturationInc
CLightState::m_TransitionTime
CLightState::m_XY
CLightState::m_XYInc

 

CLight

CLight::Delete
CLight::GetAlert
CLight::GetBrightness
CLight::GetColorMode
CLight::GetColorTemperature
CLight::GetEffect
CLight::GetHue
CLight::GetLuminaireUniqueID
CLight::GetManufacturerName
CLight::GetModelID
CLight::GetName
CLight::GetOn
CLight::GetReachable
CLight::GetSaturation
CLight::GetType
CLight::GetUniqueID
CLight::GetXY
CLight::ID
CLight::Refresh
CLight::Rename
CLight::Set
CLight::SetAlert
CLight::SetBrightness

CLight::SetColorTemperature
CLight::SetEffect
CLight::SetHue
CLight::SetOff
CLight::SetOn
CLight::SetSaturation
CLight::SetXY
CLight::m_LastResponse
CLight::m_LastState

 

CBridge

CBridge::CreateNewUser
CBridge::DeleteUser
CBridge::GetConfiguration
CBridge::GetDescriptionXML
CBridge::GetFullState
CBridge::GetLight
CBridge::GetLights
CBridge::GetNewLights
CBridge::HasLight
CBridge::Initialize
CBridge::IsErrorResponse
CBridge::SearchNewLights
CBridge::m_Connection
CBridge::m_LastLights
CBridge::m_LastResponse
CBridge::m_sUsername

 

 

g_GamutA

Remarks

g_GamutA is an instance of type std::array<std::pair<float, float>, 3> and contains the three cartesian coordinates representing Gamut A as described at https://developers.meethue.com/develop/get-started-2/core-concepts/#colors-get-more-complicated.

 

 

g_GamutB

Remarks

g_GamutB is an instance of type std::array<std::pair<float, float>, 3> and contains the three cartesian coordinates representing Gamut B as described at https://developers.meethue.com/develop/get-started-2/core-concepts/#colors-get-more-complicated.

 

 

g_GamutC

Remarks

g_GamutC is an instance of type std::array<std::pair<float, float>, 3> and contains the three cartesian coordinates representing Gamut C as described at https://developers.meethue.com/develop/get-started-2/core-concepts/#colors-get-more-complicated.

 

 

CErrorResponse

Remarks

This class is used to contain one specific error instance as returned from the Philips Hue API. An array of these will be returned in failures from the Hue API.

 

CErrorResponse::m_sAddress

Remarks

This member variable is of type std::wstring and contains the logical API address associated with the error.

 

CErrorResponse::m_sDescription

Remarks

This member variable is of type std::wstring and contains a text description associated with the error.

 

CErrorResponse::m_Type

Remarks

This member variable is an enum of type of ERROR_TYPE and contains an identifier for the error as described at https://developers.meethue.com/develop/hue-api/error-messages/.

 

 

KelvinToMired

uint32_t KelvinToMired(uint32_t kelvin)

Return Value

Will contain the Mired converted value

Parameters

kelvin The color temperature to convert in degrees kelvin.

Remarks

A simple function which converts from Kelvin to Mired (aka “reciprocal megakelvin) as described at https://developers.meethue.com/develop/get-started-2/core-concepts/#colors-get-more-complicated.

 

 

MiredToKelvin

uint32_t MiredToKelvin(uint32_t mired)

Return Value

Will contain the kelvin converted value

Parameters

mired The color temperature to convert in mired (aka “reciprocal megakelvin).

Remarks

A simple function which converts from Mired to Kelvin as described at https://developers.meethue.com/develop/get-started-2/core-concepts/#colors-get-more-complicated.

 

 

RGBToXY

std::pair<float, float> RGBToXY(COLORREF color)

Return Value

A pair of floating point values representing the converted value. The "first" member variable of the pair will contain the X value and the "second" member variable will contain the Y value

Parameters

color A standard Windows rpresentation of a RGB color

Remarks

Allows conversion from the RGB color space to the XY color space. This code is based on the Python code at https://github.com/benknight/hue-python-rgb-converter.

 

 

XYToRGB

COLORREF XYToRGB(float x, float y, float brightness, const std::array<std::pair<float, float>, 3>& gamut = g_GamutB)

Return Value

A standard windows color representation of the XY color.

Parameters

x The x value of the color

y This y value of the color.

brightness This brightness value of the color.

gamut An array of three cartesian coordinates which represent the color gamut triangle to use for the conversion. The default value for this parameter will be an array instance representing "Gamut B" as described at https://developers.meethue.com/develop/get-started-2/core-concepts/#colors-get-more-complicated.

Remarks

Allows conversion from the XY color space to the RGB color space. This code is based on the Python code at https://github.com/benknight/hue-python-rgb-converter.

 

 

HSLToRGB

COLORREF HSLToRGB(float h, float s, float l)

Return Value

A standard windows color representation of the HSL color.

Parameters

h The hue component of the color in the range [0, 1]

s The saturation component of the color in the range [0, 1]

l The luminance component of the color in the range [0, 1]

Remarks

Allows conversion from the HSL color space to the RGB color space. This code is based on the Javascript code at https://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion.

 

 

HSLToRGB

std::array<float, 3> RGBToHSL(COLORREF color)

Return Value

An array containing the converted HSL color. The first element will contain the hue, the second element will contain the saturation and the third element will contain the luminance component of the color. All component values will be in the range [0, 1]

Parameters

color A standard windows color representation of the color to convert.

Remarks

Allows conversion from the RGB color space to the HSL color space. This code is based on the Javascript code at https://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion.

 

 

UPnPDiscover

HRESULT UPnPDiscover(_Inout_ std::vector<std::pair<std::string, std::string>>& devices, DWORD dwTimeout = 5, LPCSTR pszSearchTarget = "ssdp:all", LPCSTR pszUserAgent = nullptr, HANDLE hCancel = nullptr);

Return Value

A standard HRESULT value. Failures could be because of socket creation problems, failing to send the UPnP request over the socket or socket read errors.

Parameters

devices Upon successful return of this array this will contain the UPnP devices found. For each item in the array, the "first" element of the pair will contain the "Location" UPnP header which will be the IP address of the device, while the "second" element of the pair will contain the "Server" UPnP header of the device.

dwTimeout The time in seconds to monitor for UPnP broadbcasts

pszSearchTarget The value to pass to the "ST" UPnP request. This controls what devices to look for using UPnP.

pszUserAgent If a non null value is provided for this parameter, then a USER-AGENT header will this value will be included in the UPnP request.

hCancel If a non null parameter is provided for this parameter, then client code can cancel the search prematurely from a different thread by calling SetEvent or PulseEvent on this handle.

Remarks

This function issues a IPv4 UPnP request to search for devices on the local network. Philips Hue devices are discoverable using UPnP and this function can be used in your application to find these devices.

 

 

CLightState

This class represents all the attributes of a light which can be set via the Hue API using the CLight::Set method.

 

CLightState::m_Alert

Remarks

m_Alert is of type enum class ALERT and can have the values "NOT_SET", "NONE", "SELECT" or "LSELECT". This value corresponds to the "alert" attribute as described at https://developers.meethue.com/develop/hue-api/lights-api/#set-light-state.

 

CLightState::m_Brightness

Remarks

m_Brightness is of type std::optional<uint8_t>. If a value is provided in this value then it is used during the set light state API call. This value corresponds to the "bri" attribute as described at https://developers.meethue.com/develop/hue-api/lights-api/#set-light-state.

 

CLightState::m_BrightnessInc

Remarks

m_BrightnessInc is of type std::optional<int16_t>. If a value is provided in this value then it is used during the set light state API call. This value corresponds to the "bri_inc" attribute as described at https://developers.meethue.com/develop/hue-api/lights-api/#set-light-state.

 

CLightState::m_CT

Remarks

m_CT is of type std::optional<uint16_t>. If a value is provided in this value then it is used during the set light state API call. This value corresponds to the "ct" attribute as described at https://developers.meethue.com/develop/hue-api/lights-api/#set-light-state.

 

CLightState::m_CTInc

Remarks

m_CTInc is of type std::optional<int32_t>. If a value is provided in this value then it is used during the set light state API call. This value corresponds to the "ct_inc" attribute as described at https://developers.meethue.com/develop/hue-api/lights-api/#set-light-state.

 

CLightState::m_Effect

Remarks

m_Effect is of type enum class EFFECT and can have the values "NOT_SET", "NONE", "COLORLOPP". This value corresponds to the "effect" attribute as described at https://developers.meethue.com/develop/hue-api/lights-api/#set-light-state.

 

CLightState::m_Hue

Remarks

m_Hue is of type std::optional<uint16_t>. If a value is provided in this value then it is used during the set light state API call. This value corresponds to the "hue" attribute as described at https://developers.meethue.com/develop/hue-api/lights-api/#set-light-state.

 

CLightState::m_HueInc

Remarks

m_HueInc is of type std::optional<int32_t>. If a value is provided in this value then it is used during the set light state API call. This value corresponds to the "hue_inc" attribute as described at https://developers.meethue.com/develop/hue-api/lights-api/#set-light-state.

 

CLightState::m_On

Remarks

m_On is of type std::optional<bool>. If a value is provided in this value then it is used during the set light state API call. This value corresponds to the "on" attribute as described at https://developers.meethue.com/develop/hue-api/lights-api/#set-light-state.

 

CLightState::m_Saturation

Remarks

m_Saturation is of type std::optional<uint8_t>. If a value is provided in this value then it is used during the set light state API call. This value corresponds to the "sat" attribute as described at https://developers.meethue.com/develop/hue-api/lights-api/#set-light-state.

 

CLightState::m_SaturationInc

Remarks

m_SaturationInc is of type std::optional<int16_t>. If a value is provided in this value then it is used during the set light state API call. This value corresponds to the "sat_inc" attribute as described at https://developers.meethue.com/develop/hue-api/lights-api/#set-light-state.

 

CLightState::m_TransitionTime

Remarks

m_TransitionTime is of type std::optional<uint16_t>. If a value is provided in this value then it is used during the set light state API call. This value corresponds to the "transitiontime" attribute as described at https://developers.meethue.com/develop/hue-api/lights-api/#set-light-state.

 

CLightState::m_XY

Remarks

m_XY is of type std::optional<std::pair<float, float>>. If a value is provided in this value then it is used during the set light state API call. This value corresponds to the "xy" attribute as described at https://developers.meethue.com/develop/hue-api/lights-api/#set-light-state.

 

CLightState::m_XYInc

Remarks

m_XYInc is of type std::optional<std::pair<float, float>>. If a value is provided in this value then it is used during the set light state API call. This value corresponds to the "xy_inc" attribute as described at https://developers.meethue.com/develop/hue-api/lights-api/#set-light-state.

 

 

CLight

This class represents an actual bulb / light in the Hue API. You can obtain a usable instance of one using the CBridge::GetLight method.

 

CLight::Delete

HRESULT Delete(std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This method deletes a light from the bridge. This method corresponds to the API call https://developers.meethue.com/develop/hue-api/lights-api/#del-lights.

 

CLight::GetAlert

HRESULT GetAlert(CLightState::ALERT& alert);

Return Value

A standard HRESULT value.

Parameters

alert Upon successful return from this method, this will contain the last "alert" value parsed from m_LastState response through the Refresh method.

Remarks

Returns the last "alert" value received for this light.

 

CLight::GetBrightness

HRESULT GetBrightness(uint8_t& brightness);

Return Value

A standard HRESULT value.

Parameters

brightness Upon successful return from this method, this will contain the last "bri" value parsed from m_LastState response through the Refresh method.

Remarks

Returns the last "bri" value received for this light.

 

CLight::GetColorMode

HRESULT GetColorMode(std::wstring& sColorMode);

Return Value

A standard HRESULT value.

Parameters

sColorMode Upon successful return from this method, this will contain the last "colormode" value parsed from m_LastState response through the Refresh method.

Remarks

Returns the last "colormode" value received for this light.

 

CLight::GetColorTemperature

HRESULT GetColorTemperature(uint16_t& colorTemp);

Return Value

A standard HRESULT value.

Parameters

colorTemp Upon successful return from this method, this will contain the last "ct" value parsed from m_LastState response through the Refresh method.

Remarks

Returns the last "ct" value received for this light.

 

CLight::GetEffect

HRESULT GetEffect(CLightState::EFFECT& effect);

Return Value

A standard HRESULT value.

Parameters

effect Upon successful return from this method, this will contain the last "effect" value parsed from m_LastState response through the Refresh method.

Remarks

Returns the last "effect" value received for this light.

 

CLight::GetHue

HRESULT GetHue(uint16_t& hue);

Return Value

A standard HRESULT value.

Parameters

hue Upon successful return from this method, this will contain the last "hue" value parsed from m_LastState response through the Refresh method.

Remarks

Returns the last "hue" value received for this light.

 

CLight::GetLuminaireUniqueID

HRESULT GetLuminaireUniqueID(std::wstring& sLuminaireUniqueID);

Return Value

A standard HRESULT value.

Parameters

sLuminaireUniqueID Upon successful return from this method, this will contain the last "luminaireuniqueid" value parsed from m_LastState response through the Refresh method.

Remarks

Returns the last "luminaireuniqueid" value received for this light.

 

CLight::GetManufacturerName

HRESULT GetManufacturerName(std::wstring& sManufacturerName);

Return Value

A standard HRESULT value.

Parameters

sManufacturerName Upon successful return from this method, this will contain the last "manufacturername" value parsed from m_LastState response through the Refresh method.

Remarks

Returns the last "manufacturername" value received for this light.

 

CLight::GetModelID

HRESULT GetModelID(std::wstring& sModelID);

Return Value

A standard HRESULT value.

Parameters

sModelID Upon successful return from this method, this will contain the last "modelid" value parsed from m_LastState response through the Refresh method.

Remarks

Returns the last "modelid" value received for this light.

 

CLight::GetName

HRESULT GetName(std::wstring& sName);

Return Value

A standard HRESULT value.

Parameters

sName Upon successful return from this method, this will contain the last "name" value parsed from m_LastState response through the Refresh method.

Remarks

Returns the last "name" value received for this light.

 

CLight::GetOn

HRESULT GetOn(bool& bOn);

Return Value

A standard HRESULT value.

Parameters

bOn Upon successful return from this method, this will contain the last "on" value parsed from m_LastState response through the Refresh method.

Remarks

Returns the last "on" value received for this light.

 

CLight::GetReachable

HRESULT GetReachable();

Return Value

A standard HRESULT value.

Parameters

bReachable Upon successful return from this method, this will contain the last "reachable" value parsed from m_LastState response through the Refresh method.

Remarks

Returns the last "reachable" value received for this light.

 

CLight::GetSaturation

HRESULT GetSaturation(uint8_t& saturation);

Return Value

A standard HRESULT value.

Parameters

saturation Upon successful return from this method, this will contain the last "sat" value parsed from m_LastState response through the Refresh method.

Remarks

Returns the last "sat" value received for this light.

 

CLight::GetType

HRESULT GetType(std::wstring& sType);

Return Value

A standard HRESULT value.

Parameters

sType Upon successful return from this method, this will contain the last "type" value parsed from m_LastState response through the Refresh method.

Remarks

Returns the last "type" value received for this light.

 

CLight::GetUniqueID

HRESULT GetUniqueID(std::wstring& sUniqueID);

Return Value

A standard HRESULT value.

Parameters

sUniqueID Upon successful return from this method, this will contain the last "uniqueid" value parsed from m_LastState response through the Refresh method.

Remarks

Returns the last "uniqueid" value received for this light.

 

CLight::GetXY

HRESULT GetXY(std::pair<float, float>& xy);

Return Value

A standard HRESULT value.

Parameters

xy Upon successful return from this method, this will contain the last "xy" value parsed from m_LastState response through the Refresh method.

Remarks

Returns the last "xy" value received for this light.

 

CLight::ID

int ID();

Return Value

The numeric identifier of the light.

Remarks

This method returns the identifier of the light as known by the bridge. The return value to this method corresponds corresponds to the <id> parameter in the https://developers.meethue.com/develop/hue-api/lights-api/#get-attr-and-state API call.

 

CLight::Refresh

HRESULT Refresh(std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This method gets the latest state of the light from the bridge. This method corresponds to the API call https://developers.meethue.com/develop/hue-api/lights-api/#get-attr-and-state. The response to this API is stored in CLight::m_LastState and all the attributes in this response are made available by the various CLight::Get* methods.

 

CLight::Rename

HRESULT Rename(LPCSTR pszNewName,  std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

pszNewName The new name of the light.

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

Renames the light. This method corresponds to the API call https://developers.meethue.com/develop/hue-api/lights-api/#set-light-attr-rename.

 

CLight::Set

HRESULT Set(const CLightState& state, std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

state An instance of the CLightState class which contains the attributes which you want to set on the light.

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This is the main method call to control a Philips Hue light. This method corresponds to the API call https://developers.meethue.com/develop/hue-api/lights-api/#set-light-state.

 

CLight::SetAlert

HRESULT SetAlert(CLightState::ALERT alert, std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

alert The "alert" state to set the light to.

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This is a simple helper function which just sets the "alert" attribute for the light. Internally this method creates a CLightState instance and then call the CLight::Set method.

 

CLight::SetBrightness

HRESULT SetBrightness(uint8_t brightness, std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

brightness The "alert" value to set the light to.

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This is a simple helper function which just sets the "bri" attribute for the light. Internally this method creates a CLightState instance and then call the CLight::Set method.

 

CLight::SetColorTemperature

HRESULT SetColorTemperature(uint16_t colorTemp, std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

colorTemp The "ct" value to set the light to.

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This is a simple helper function which just sets the "ct" attribute for the light. Internally this method creates a CLightState instance and then call the CLight::Set method.

 

CLight::SetEffect

HRESULT SetEffect(CLightState::EFFECT effect, std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

effect The "effect" value to set the light to.

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This is a simple helper function which just sets the "effect" attribute for the light. Internally this method creates a CLightState instance and then call the CLight::Set method.

 

CLight::SetHue

HRESULT SetHue(uint16_t hue, std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

hue The "hue" value to set the light to.

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This is a simple helper function which just sets the "hue" attribute for the light. Internally this method creates a CLightState instance and then call the CLight::Set method.

 

CLight::SetOff

HRESULT SetOff(std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This is a simple helper function which just turns a light off. Internally this method creates a CLightState instance and then call the CLight::Set method.

 

CLight::SetOn

HRESULT SetOn(std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This is a simple helper function which just turns a light on. Internally this method creates a CLightState instance and then call the CLight::Set method.

 

CLight::SetSaturation

HRESULT SetSaturation(uint8_t saturation, std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

saturation The "sat" value to set the light to.

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This is a simple helper function which just sets the "sat" attribute for the light. Internally this method creates a CLightState instance and then call the CLight::Set method.

 

CLight::SetXY

HRESULT SetXY(const std::pair<float, float>& xy, std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

xy The "xy" value to set the light to.

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This is a simple helper function which just sets the "xy" attribute for the light. Internally this method creates a CLightState instance and then call the CLight::Set method.

 

CLight::m_LastResponse

Remarks

m_LastResponse is of type JSONPP::CValue. This variable contains the last JSON parsed response from the bridge through the CLight class.

 

CLight::m_LastState

Remarks

m_LastState is of type JSONPP::CValue. This variable contains the last JSON parsed response from the bridge from the CLight::Refresh call.

 

CBridge

This class represents a connection to the Philips Hue Bridge device.

 

CBridge::CreateNewUser

HRESULT CreateNewUser(LPCSTR pszUserName, std::wstring& sClientKey, std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

pszUserName The Username to pass to the API to create.

sClientKey Upon successful return from this method, this will contain the client key which must be provided to the bridge to authenticate

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

To successfuly use any API against the bridge a new user needs to be created. This method corresponds to the API call https://developers.meethue.com/develop/hue-api/7-configuration-api/#create-user.

 

CBridge::DeleteUser

HRESULT DeleteUser(LPCSTR pszUsername, _In_z_ LPCSTR pszClientKey, std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

pszUsername The username to remove from the bridge's whitelist.

pszClientKey The associated client key for the username.

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This deletes a user from the bridge. It is the corrolary method to the CBridge::CreateNewUser method. This method corresponds to the API call https://developers.meethue.com/develop/hue-api/7-configuration-api/#del-user-from-whitelist.

 

CBridge::GetConfiguration

HRESULT GetConfiguration(std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This method corresponds to the API call https://developers.meethue.com/develop/hue-api/7-configuration-api/#get-configuration. The fully parsed response to this API will be stored in CBridge::m_LastResponse.

 

CBridge::GetDescriptionXML

HRESULT GetDescriptionXML(std::string& sResponse);

Return Value

A standard HRESULT value.

Parameters

sResponse If Upon successful return from this method, this will contain the XML descriptor file text. Client code is then free to parse this XML to extract the data it wants. Example data you might want from this XML is to verify that this UPnP device is a Philips Hue device and also the icon image associated with the device for display purposes.

Remarks

As part of the hue Bridge discovery process, once you have got the IP address of the bridge, you can use this method call to UPnP xml descriptor file for the device.

 

CBridge::GetFullState

HRESULT GetFullState(std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This method corresponds to the API call https://developers.meethue.com/develop/hue-api/7-configuration-api/#get-full-state. The fully parsed response to this API will be stored in CBridge::m_LastResponse.

 

CBridge::GetLight

HRESULT GetLight(int nID, CLight& light);

Return Value

A standard HRESULT value.

Parameters

nID The numeric identifier of the light to get.

light Upon successful return from this method, this will contain a instance of the CLight class which you can then use to control the light.

Remarks

This method is the main way to obtain a CLight instance via the PHue++ class framework.

 

CBridge::GetLights

HRESULT GetLights(std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This method corresponds to the API call https://developers.meethue.com/develop/hue-api/lights-api/#get-all-lights. The fully parsed response to this API will be stored in CBridge::m_LastResponse.

 

CBridge::GetNewLights

HRESULT GetNewLights(std::vector<int>& newLights, std::wstring& sLastScan, std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

newLights Upon successful return this will contain a array of the light identifiers which have been found.

sLastScan Upon successful return this will contain the "Lastscan" value in the response.

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This method corresponds to the API call https://developers.meethue.com/develop/hue-api/lights-api/#get-new-lights. The fully parsed response to this API will be stored in CBridge::m_LastResponse.

 

CBridge::HasLight

bool HasLight(int nID);

Return Value

true if the specified light identifier exists from the last call to CBridge::GetLights, otherwise false

Parameters

nID The numeric light identifier to check to see if it exists

Remarks

This is a simple helper method which parses the last response to CBridge::GetLights to see if the specified light exists.

 

CBridge::Initialize

HRESULT Initialize(const WinHTTPWrappers::CSession& session, _In_z_ LPCWSTR pwszServerName, _In_ INTERNET_PORT nServerPort = INTERNET_DEFAULT_PORT);

Return Value

A standard HRESULT value.

Parameters

session The WinHTTP session wrapper class to use to initialize the WinHTTP connection with.

pwszServerName The IP address or hostname of the bridge to initialize the WinHTTP connection with.

nServerPort The port to connect to the bridge on. This defaults to the standard HTTP port of 80.

Remarks

To setup the connection to the Hue Bridge via the author's WinHTTPWrappers class framework, you first must call this method to specify the address and port number of the bridge device.

 

CBridge::IsErrorResponse

static HRESULT IsErrorResponse(const std::string& sResponse, bool& bError, std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

sResponse XThe JSON response from the bridge to check.

bError Upon successful return from this method, this parameter will be set to "true" if the response is an error response and "false" if it is not.

errors If this method return "bError" as true, then this parameter will contain all the parsed error values.

Remarks

This is a helper method used by the various CBridge methods which check the API response for logical errors.

 

CBridge::SearchNewLights

HRESULT SearchNewLights(std::vector<CErrorResponse>& errors);

Return Value

A standard HRESULT value.

Parameters

errors If the API call fails and there is an error in the JSON response, then this parameter will contain all the parsed error values.

Remarks

This method corresponds to the API call https://developers.meethue.com/develop/hue-api/lights-api/#search-for-new-lights. The fully parsed response to this API will be stored in CBridge::m_LastResponse.

 

CBridge::m_Connection

Remarks

m_Connection is of type WinHTTPWrappers::CConnection. This variable encapsulates the WinHTTP connection using to the bridge.

 

CBridge::m_LastLights

Remarks

m_LastLight is of type JSONPP::CValue. This variable contains the last parsed response from the CBridge::GetLights method call.

 

CBridge::m_LastResponse

Remarks

m_LastResponse is of type JSONPP::CValue. This variable contains the last JSON parsed response from the bridge through the CBridge class.

 

CBridge::m_sClientKey

Remarks

m_sClientKey is of type std::wstring. You should set this variable to the sClientKey parameter from a successful return from the CBridge::CreateNewUser method prior to calling any Hue API's which require a white listed user.

 

 

 

Contacting the Author

PJ Naughter
Email: pjna@naughter.com
Web: http://www.naughter.com
6 June 2022