getting-started.html
7.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>hueplusplus: Getting started</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">hueplusplus
 <span id="projectnumber">1.0.0</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Getting started </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>To start searching for a Hue Bridge you will need to choose an IHttpHandler and create one. The options are a <a class="el" href="classhueplusplus_1_1_win_http_handler.html">WinHttpHandler</a> (for windows) or a <a class="el" href="classhueplusplus_1_1_lin_http_handler.html">LinHttpHandler</a> (for linux or linux-like).</p>
<p>Then create a <a class="el" href="classhueplusplus_1_1_bridge_finder.html">BridgeFinder</a> 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 <a class="el" href="classhueplusplus_1_1_bridge_finder.html#a86cce17f26187a97547a44fab8c920a1">findBridges()</a>, which will return a vector containing the ip and mac address of all found Bridges. </p><div class="fragment"><div class="line"> <span class="comment">// For windows use std::make_shared<hueplusplus::WinHttpHandler>();</span></div><div class="line"> <span class="keyword">auto</span> handler = std::make_shared<hueplusplus::LinHttpHandler>();</div><div class="line"> <a class="code" href="classhueplusplus_1_1_bridge_finder.html">hueplusplus::BridgeFinder</a> finder(handler);</div><div class="line"> std::vector<hueplusplus::BridgeFinder::BridgeIdentification> bridges = finder.findBridges();</div><div class="line"> <span class="keywordflow">if</span> (bridges.empty())</div><div class="line"> {</div><div class="line"> std::cerr << <span class="stringliteral">"No bridges found\n"</span>;</div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line"> }</div></div><!-- fragment --> <p>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 <a class="el" href="classhueplusplus_1_1_bridge_finder.html#a9ff121c380ceaceaf5da2b7a772e5c4b">getBridge(bridges[<index>])</a>, where index is your preferred Bridge from the part <a href="#searchingBridges">Searching for Bridges</a>. This requires the user to press the link button. </p><div class="fragment"><div class="line"> <a class="code" href="classhueplusplus_1_1_bridge.html">hueplusplus::Bridge</a> bridge = finder.getBridge(bridges[0]);</div></div><!-- fragment --><p> If you on the other hand already have a username you can add your bridge like so </p><div class="fragment"><div class="line"> finder.addUsername(bridges[0].mac, <span class="stringliteral">"<username>"</span>);</div><div class="line"> <a class="code" href="classhueplusplus_1_1_bridge.html">hueplusplus::Bridge</a> bridge = finder.getBridge(bridges[0]);</div></div><!-- fragment --><p> 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 </p><div class="fragment"><div class="line"> <span class="comment">// For windows use std::make_shared<hueplusplus::WinHttpHandler>();</span></div><div class="line"> <span class="keyword">auto</span> handler = std::make_shared<hueplusplus::LinHttpHandler>();</div><div class="line"> <a class="code" href="classhueplusplus_1_1_bridge.html">hueplusplus::Bridge</a> bridge(<span class="stringliteral">"192.168.2.102"</span>, 80, <span class="stringliteral">"<username>"</span>, handler);</div></div><!-- fragment --><p> At this point you may want to decide whether to use a <a class="el" href="shared-state.html">shared state</a> cache model or keep the default settings.</p>
<div class="fragment"><div class="line"> <a class="code" href="classhueplusplus_1_1_light.html">hueplusplus::Light</a> light = bridge.<a class="code" href="classhueplusplus_1_1_bridge.html#a7bd607246130312915a3b07116c72301">lights</a>().<a class="code" href="classhueplusplus_1_1_resource_list.html#a7bcf2ed48e70e9f11a4b6bdc24e0e611">get</a>(1);</div><div class="line"> light.<a class="code" href="classhueplusplus_1_1_light.html#aab9db2db84ad55e19d7b46c77807973d">on</a>();</div><div class="line"> light.<a class="code" href="classhueplusplus_1_1_light.html#a5f4699729652474534d5783c9a27ed94">off</a>();</div></div><!-- fragment --><p> Use <a class="el" href="transactions.html">transactions</a> to change multiple properties at once.</p>
<div class="fragment"><div class="line"> <a class="code" href="classhueplusplus_1_1_group.html">hueplusplus::Group</a> group = bridge.<a class="code" href="classhueplusplus_1_1_bridge.html#a86fa3bec3ae4729df0cf6305ce49388c">groups</a>().<a class="code" href="classhueplusplus_1_1_group_resource_list.html#a06bda9ca6016b48eb6a4a5f86a67c76d">get</a>(1);</div><div class="line"> group.<a class="code" href="classhueplusplus_1_1_group.html#acba209f24f41a55af7fc7669150377a9">setOn</a>(<span class="keyword">true</span>);</div></div><!-- fragment --> <ul>
<li><a class="el" href="transactions.html">Transactions</a></li>
<li><a class="el" href="shared-state.html">Shared state cache</a> </li>
</ul>
</div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>