hueplusplus 1.2.0
Loading...
Searching...
No Matches
Getting started

Creating the Hue bridge

To start searching for a Hue Bridge you will need to choose an IHttpHandler and create one. The options are a WinHttpHandler (for windows) or a LinHttpHandler (for linux or linux-like).

Then create a BridgeFinder object with the handler. The handler is needed, because it tells the finder which functions to use to communicate with a bridge or your local network. After that you can call findBridges(), which will return a vector containing the ip and mac address of all found Bridges.

// For windows use std::make_shared<hueplusplus::WinHttpHandler>();
auto handler = std::make_shared<hueplusplus::LinHttpHandler>();
hueplusplus::BridgeFinder finder(handler);
std::vector<hueplusplus::BridgeFinder::BridgeIdentification> bridges = finder.findBridges();
if (bridges.empty())
{
std::cerr << "No bridges found\n";
return;
}
Definition Bridge.h:62

Authenticate Bridges

If you have found the Bridge you were looking for, you can then move on with the authentication process. To get a new username from the Bridge (for now) you simply call getBridge(bridges[<index>]), where index is your preferred Bridge from the part Searching for Bridges. This requires the user to press the link button.

hueplusplus::Bridge bridge = finder.getBridge(bridges[0]);
Bridge class for a bridge.
Definition Bridge.h:139

If you on the other hand already have a username you can add your bridge like so

finder.addUsername(bridges[0].mac, "<username>");
hueplusplus::Bridge bridge = finder.getBridge(bridges[0]);

If you do not want to use the BridgeFinder or you already know the ip and username of your bridge you have the option to create your own Hue object. Here you will need to provide the ip address, the port number, a username and an HttpHandler

// For windows use std::make_shared<hueplusplus::WinHttpHandler>();
auto handler = std::make_shared<hueplusplus::LinHttpHandler>();
hueplusplus::Bridge bridge("192.168.2.102", 80, "<username>", handler);

At this point you may want to decide whether to use a shared state cache model or keep the default settings.

Controlling lights

hueplusplus::Light light = bridge.lights().get(1);
light.on();
light.off();
LightList & lights()
Provides access to the Lights on the bridge.
Definition Bridge.cpp:340
Class for Hue Light fixtures.
Definition Light.h:61
virtual bool off(uint8_t transition=4)
Function that turns the light off.
Definition Light.cpp:39
virtual bool on(uint8_t transition=4)
Function that turns the light on.
Definition Light.cpp:34
Resource get(const IdType &id)
Get resource specified by id.
Definition ResourceList.h:126

Use transactions to change multiple properties at once.

Controlling groups

hueplusplus::Group group = bridge.groups().get(1);
group.setOn(true);
GroupList & groups()
Provides access to the Groups on the bridge.
Definition Bridge.cpp:350
Class for Groups of lights.
Definition Group.h:42
void setOn(bool on, uint8_t transition=4)
Convenience function to turn lights on.
Definition Group.cpp:169
Resource get(const int &id)
Get group, specially handles group 0.
Definition ResourceList.h:339

More information