Publish LumaOps source
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
\file BridgeSetup.cpp
|
||||
Copyright Notice\n
|
||||
Copyright (C) 2021 Jan Rogall - developer\n
|
||||
|
||||
This file is part of hueplusplus.
|
||||
|
||||
hueplusplus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
hueplusplus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with hueplusplus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\example{lineno} BridgeSetup.cpp
|
||||
This example connects to a bridge with hardcoded mac and username.
|
||||
**/
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
#include <hueplusplus/Bridge.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <hueplusplus/WinHttpHandler.h>
|
||||
|
||||
using SystemHttpHandler = hueplusplus::WinHttpHandler;
|
||||
|
||||
#else
|
||||
#include <hueplusplus/LinHttpHandler.h>
|
||||
|
||||
using SystemHttpHandler = hueplusplus::LinHttpHandler;
|
||||
|
||||
#endif
|
||||
|
||||
namespace hue = hueplusplus;
|
||||
|
||||
// Configure existing connections here, or leave empty for new connection
|
||||
const std::string macAddress = "";
|
||||
const std::string username = "";
|
||||
|
||||
// Connects to a bridge and returns it.
|
||||
hue::Bridge connectToBridge()
|
||||
{
|
||||
hue::BridgeFinder finder(std::make_shared<SystemHttpHandler>());
|
||||
|
||||
std::vector<hue::BridgeFinder::BridgeIdentification> bridges = finder.findBridges();
|
||||
|
||||
for (const auto& bridge : bridges)
|
||||
{
|
||||
std::cout << "Bridge: " << bridge.mac << " at " << bridge.ip << '\n';
|
||||
}
|
||||
if (bridges.empty())
|
||||
{
|
||||
std::cout << "Found no bridges\n";
|
||||
throw std::runtime_error("no bridges found");
|
||||
}
|
||||
|
||||
if (macAddress.empty())
|
||||
{
|
||||
std::cout << "No bridge given, connecting to first one.\n";
|
||||
return finder.getBridge(bridges.front());
|
||||
}
|
||||
if (!username.empty())
|
||||
{
|
||||
finder.addUsername(macAddress, username);
|
||||
}
|
||||
auto it = std::find_if(
|
||||
bridges.begin(), bridges.end(), [&](const auto& identification) { return identification.mac == macAddress; });
|
||||
if (it == bridges.end())
|
||||
{
|
||||
std::cout << "Given bridge not found\n";
|
||||
throw std::runtime_error("bridge not found");
|
||||
}
|
||||
return finder.getBridge(*it);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
hue::Bridge hue = connectToBridge();
|
||||
|
||||
std::cout << "Connected to bridge. IP: " << hue.getBridgeIP() << ", username: " << hue.getUsername() << '\n';
|
||||
}
|
||||
catch (...)
|
||||
{ }
|
||||
|
||||
std::cout << "Press enter to exit\n";
|
||||
std::cin.get();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
add_executable(bridge_setup BridgeSetup.cpp)
|
||||
set_property(TARGET bridge_setup PROPERTY CXX_STANDARD 14)
|
||||
set_property(TARGET bridge_setup PROPERTY CXX_EXTENSIONS OFF)
|
||||
target_link_libraries(bridge_setup hueplusplusstatic)
|
||||
|
||||
add_executable(lights_off LightsOff.cpp)
|
||||
set_property(TARGET lights_off PROPERTY CXX_STANDARD 14)
|
||||
set_property(TARGET lights_off PROPERTY CXX_EXTENSIONS OFF)
|
||||
target_link_libraries(lights_off hueplusplusstatic)
|
||||
|
||||
|
||||
add_executable(username_config UsernameConfig.cpp)
|
||||
set_property(TARGET lights_off PROPERTY CXX_STANDARD 14)
|
||||
set_property(TARGET lights_off PROPERTY CXX_EXTENSIONS OFF)
|
||||
target_link_libraries(username_config hueplusplusstatic)
|
||||
|
||||
add_custom_target(hueplusplus_examples)
|
||||
add_dependencies(hueplusplus_examples bridge_setup lights_off username_config)
|
||||
|
||||
# Snippets for documentation, not included with the examples target
|
||||
add_executable(hueplusplus_snippets Snippets.cpp)
|
||||
set_property(TARGET hueplusplus_snippets PROPERTY CXX_STANDARD 14)
|
||||
set_property(TARGET hueplusplus_snippets PROPERTY CXX_EXTENSIONS OFF)
|
||||
target_link_libraries(hueplusplus_snippets hueplusplusstatic)
|
||||
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
\file LightsOff.cpp
|
||||
Copyright Notice\n
|
||||
Copyright (C) 2021 Jan Rogall - developer\n
|
||||
|
||||
This file is part of hueplusplus.
|
||||
|
||||
hueplusplus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
hueplusplus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with hueplusplus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\example{lineno} LightsOff.cpp
|
||||
This example turns off all lights for 20 seconds, then turns them on again.
|
||||
**/
|
||||
|
||||
#include <thread>
|
||||
|
||||
#include <hueplusplus/Bridge.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <hueplusplus/WinHttpHandler.h>
|
||||
|
||||
using SystemHttpHandler = hueplusplus::WinHttpHandler;
|
||||
|
||||
#else
|
||||
#include <hueplusplus/LinHttpHandler.h>
|
||||
|
||||
using SystemHttpHandler = hueplusplus::LinHttpHandler;
|
||||
|
||||
#endif
|
||||
|
||||
namespace hue = hueplusplus;
|
||||
|
||||
// Configure existing connections here, or leave empty for new connection
|
||||
const std::string macAddress = "";
|
||||
const std::string username = "";
|
||||
|
||||
// Connects to a bridge and returns it.
|
||||
hue::Bridge connectToBridge()
|
||||
{
|
||||
hue::BridgeFinder finder(std::make_shared<SystemHttpHandler>());
|
||||
|
||||
std::vector<hue::BridgeFinder::BridgeIdentification> bridges = finder.findBridges();
|
||||
|
||||
for (const auto& bridge : bridges)
|
||||
{
|
||||
std::cout << "Bridge: " << bridge.mac << " at " << bridge.ip << '\n';
|
||||
}
|
||||
if (bridges.empty())
|
||||
{
|
||||
std::cout << "Found no bridges\n";
|
||||
throw std::runtime_error("no bridges found");
|
||||
}
|
||||
|
||||
if (macAddress.empty())
|
||||
{
|
||||
std::cout << "No bridge given, connecting to first one.\n";
|
||||
return finder.getBridge(bridges.front());
|
||||
}
|
||||
if (!username.empty())
|
||||
{
|
||||
finder.addUsername(macAddress, username);
|
||||
}
|
||||
auto it = std::find_if(
|
||||
bridges.begin(), bridges.end(), [&](const auto& identification) { return identification.mac == macAddress; });
|
||||
if (it == bridges.end())
|
||||
{
|
||||
std::cout << "Given bridge not found\n";
|
||||
throw std::runtime_error("bridge not found");
|
||||
}
|
||||
return finder.getBridge(*it);
|
||||
}
|
||||
|
||||
// Turns off the lights on the bridge for 20 seconds.
|
||||
// Only turns the lights back on that were on before.
|
||||
void lightsOff(hue::Bridge& hue)
|
||||
{
|
||||
std::vector<hue::Light> lights = hue.lights().getAll();
|
||||
|
||||
// Save current on state of the lights
|
||||
std::map<int, bool> onMap;
|
||||
for (hue::Light& l : lights)
|
||||
{
|
||||
onMap.emplace(l.getId(), l.isOn());
|
||||
l.off();
|
||||
}
|
||||
|
||||
// This would be preferrable, but does not work because it also resets the brightness of all lights
|
||||
// Group 0 contains all lights, turn all off with a transition of 1 second
|
||||
// hue.groups().get(0).setOn(false, 10);
|
||||
// -------------------------------------
|
||||
|
||||
std::cout << "Turned off all lights\n";
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(20));
|
||||
|
||||
// Restore the original state of the lights
|
||||
for (hue::Light& l : lights)
|
||||
{
|
||||
if (onMap[l.getId()])
|
||||
{
|
||||
l.on();
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Turned lights back on\n";
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
hue::Bridge hue = connectToBridge();
|
||||
|
||||
std::cout << "Connected to bridge. IP: " << hue.getBridgeIP() << ", username: " << hue.getUsername() << '\n';
|
||||
|
||||
lightsOff(hue);
|
||||
}
|
||||
catch (...)
|
||||
{ }
|
||||
|
||||
std::cout << "Press enter to exit\n";
|
||||
std::cin.get();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
/**
|
||||
\file Snippets.cpp
|
||||
Copyright Notice\n
|
||||
Copyright (C) 2021 Jan Rogall - developer\n
|
||||
|
||||
This file is part of hueplusplus.
|
||||
|
||||
hueplusplus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
hueplusplus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with hueplusplus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\brief Contains code snippets used in the documentation, performs no useful functions.
|
||||
**/
|
||||
|
||||
#include <hueplusplus/Bridge.h>
|
||||
#include <hueplusplus/CLIPSensors.h>
|
||||
#include <hueplusplus/ZLLSensors.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <hueplusplus/WinHttpHandler.h>
|
||||
|
||||
namespace hueplusplus
|
||||
{
|
||||
// Dirty hack to make the snippets compile under windows. Dont do this,
|
||||
// instead use your own alias which is set to either type like in BridgeSetup.cpp!
|
||||
using LinHttpHandler = WinHttpHandler;
|
||||
} // namespace hueplusplus
|
||||
|
||||
#else
|
||||
#include <hueplusplus/LinHttpHandler.h>
|
||||
|
||||
#endif
|
||||
|
||||
void snippet1()
|
||||
{
|
||||
// Main page
|
||||
//! [search-bridge]
|
||||
// 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;
|
||||
}
|
||||
//! [search-bridge]
|
||||
//! [get-bridge-2]
|
||||
finder.addUsername(bridges[0].mac, "<username>");
|
||||
//! [get-bridge-1]
|
||||
hueplusplus::Bridge bridge = finder.getBridge(bridges[0]);
|
||||
//! [get-bridge-1]
|
||||
//! [get-bridge-2]
|
||||
//! [light-1]
|
||||
hueplusplus::Light light1 = bridge.lights().get(1);
|
||||
//! [light-1]
|
||||
//! [light-2]
|
||||
std::vector<hueplusplus::Light> lights = bridge.lights().getAll();
|
||||
//! [light-2]
|
||||
//! [light-3]
|
||||
light1.on();
|
||||
light1.setBrightness(120);
|
||||
light1.alertHueSaturation({25500, 254});
|
||||
light1.setColorLoop(true);
|
||||
light1.setColorRGB({255, 128, 0});
|
||||
lights[1].off();
|
||||
lights.at(1).setColorHue(4562);
|
||||
//! [light-3]
|
||||
//! [light-4]
|
||||
hueplusplus::ColorType type1 = light1.getColorType();
|
||||
//! [light-4]
|
||||
//! [light-5]
|
||||
light1.hasBrightnessControl();
|
||||
light1.hasTemperatureControl();
|
||||
light1.hasColorControl();
|
||||
//! [light-5]
|
||||
|
||||
// Getting started
|
||||
//! [control-lights]
|
||||
hueplusplus::Light light = bridge.lights().get(1);
|
||||
light.on();
|
||||
light.off();
|
||||
//! [control-lights]
|
||||
//! [control-groups]
|
||||
hueplusplus::Group group = bridge.groups().get(1);
|
||||
group.setOn(true);
|
||||
//! [control-groups]
|
||||
|
||||
// Sensors
|
||||
//! [sensor-conditions]
|
||||
//! [known-sensor-1]
|
||||
hueplusplus::sensors::ZLLSwitch switchSensor = bridge.sensors().getAsType<hueplusplus::sensors::ZLLSwitch>(2);
|
||||
//! [known-sensor-1]
|
||||
// ZLLSwitch conditions operate on `buttonEvent`, use makeConditionLastUpdate()
|
||||
// to trigger on the last update time.
|
||||
|
||||
// Some examples:
|
||||
hueplusplus::Condition upPressed
|
||||
= makeCondition(switchSensor).eq(hueplusplus::sensors::ZLLSwitch::c_UP_INITIAL_PRESS);
|
||||
hueplusplus::Condition buttonChanged = makeCondition(switchSensor).dx();
|
||||
|
||||
hueplusplus::time::TimeInterval interval(std::chrono::hours(12), std::chrono::hours(13));
|
||||
hueplusplus::Condition updatedAtNoon = makeConditionLastUpdate(switchSensor).in(interval);
|
||||
//! [sensor-conditions]
|
||||
//! [known-sensor-2]
|
||||
std::vector<hueplusplus::sensors::ZLLSwitch> allSwitches
|
||||
= bridge.sensors().getAllByType<hueplusplus::sensors::ZLLSwitch>();
|
||||
//! [known-sensor-2]
|
||||
//! [generic-sensor-1]
|
||||
hueplusplus::Sensor genericSensor = bridge.sensors().get(1);
|
||||
if (genericSensor.hasOn())
|
||||
{
|
||||
// Now can check whether it is on
|
||||
if (genericSensor.isOn())
|
||||
{
|
||||
// ...
|
||||
}
|
||||
}
|
||||
//! [generic-sensor-1]
|
||||
|
||||
// Transactions
|
||||
//! [transaction-lights]
|
||||
light.transaction().setOn(true).setBrightness(29).setColorHue(3000).setColorSaturation(128).commit();
|
||||
//! [transaction-lights]
|
||||
bool shouldTurnOn = true;
|
||||
//! [transaction-advanced]
|
||||
hueplusplus::StateTransaction t = light.transaction();
|
||||
if (shouldTurnOn)
|
||||
t.setOn(true);
|
||||
t.commit();
|
||||
//! [transaction-advanced]
|
||||
//! [transaction-groups]
|
||||
group.transaction().setOn(true).setBrightness(64).commit();
|
||||
//! [transaction-groups]
|
||||
hueplusplus::Schedule schedule = bridge.schedules().get(1);
|
||||
//! [transaction-action]
|
||||
hueplusplus::Action action = light.transaction().setOn(true).setBrightness(254).toAction();
|
||||
schedule.setCommand(action);
|
||||
//! [transaction-action]
|
||||
}
|
||||
void snippet2()
|
||||
{
|
||||
// Main page
|
||||
//! [get-bridge-3]
|
||||
// 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);
|
||||
//! [get-bridge-3]
|
||||
|
||||
// Sensors
|
||||
//! [generic-sensor-2]
|
||||
hueplusplus::Sensor genericSensor = bridge.sensors().get(1);
|
||||
if (genericSensor.getType() == hueplusplus::sensors::ZLLSwitch::typeStr)
|
||||
{
|
||||
hueplusplus::sensors::ZLLSwitch switchSensor = genericSensor.asSensorType<hueplusplus::sensors::ZLLSwitch>();
|
||||
// ...
|
||||
}
|
||||
//! [generic-sensor-2]
|
||||
}
|
||||
|
||||
void snippet3()
|
||||
{
|
||||
// Shared state
|
||||
auto handler = std::make_shared<hueplusplus::LinHttpHandler>();
|
||||
hueplusplus::BridgeFinder finder(handler);
|
||||
std::vector<hueplusplus::BridgeFinder::BridgeIdentification> bridges = finder.findBridges();
|
||||
//! [shared-bridge-1]
|
||||
hueplusplus::Bridge bridge = finder.getBridge(bridges[0], true);
|
||||
//! [shared-bridge-1]
|
||||
//! [refresh-example]
|
||||
bridge.setRefreshDuration(std::chrono::minutes(1));
|
||||
bridge.lights().setRefreshDuration(std::chrono::seconds(30));
|
||||
hueplusplus::Light light = bridge.lights().get(1);
|
||||
// ... wait some time
|
||||
bool on = light.isOn();
|
||||
//! [refresh-example]
|
||||
}
|
||||
void snippet4()
|
||||
{
|
||||
// Shared state
|
||||
auto handler = std::make_shared<hueplusplus::LinHttpHandler>();
|
||||
//! [shared-bridge-2]
|
||||
hueplusplus::Bridge bridge("192.168.2.102", 80, "<username>", handler, "", std::chrono::seconds(10), true);
|
||||
//! [shared-bridge-2]
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/**
|
||||
\file UsernameConfig.cpp
|
||||
Copyright Notice\n
|
||||
Copyright (C) 2021 Jan Rogall - developer\n
|
||||
|
||||
This file is part of hueplusplus.
|
||||
|
||||
hueplusplus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
hueplusplus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with hueplusplus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\example{lineno} UsernameConfig.cpp
|
||||
This example reads the username and mac address from a config file.
|
||||
**/
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
#include <hueplusplus/Bridge.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <hueplusplus/WinHttpHandler.h>
|
||||
|
||||
using SystemHttpHandler = hueplusplus::WinHttpHandler;
|
||||
|
||||
#else
|
||||
#include <hueplusplus/LinHttpHandler.h>
|
||||
|
||||
using SystemHttpHandler = hueplusplus::LinHttpHandler;
|
||||
|
||||
#endif
|
||||
|
||||
namespace hue = hueplusplus;
|
||||
|
||||
// Reads a json config file.
|
||||
// filename: Path to the config file
|
||||
// returns parsed json or an empty object if not successful.
|
||||
nlohmann::json readConfigFile(const std::string& filename)
|
||||
{
|
||||
std::ifstream stream(filename);
|
||||
try
|
||||
{
|
||||
nlohmann::json result = nlohmann::json::object();
|
||||
if (stream)
|
||||
{
|
||||
stream >> result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (const nlohmann::json::exception&)
|
||||
{
|
||||
// Ignore parse errors
|
||||
return nlohmann::json::object();
|
||||
}
|
||||
}
|
||||
|
||||
// Saves a json file.
|
||||
// filename: Path to the config file
|
||||
// config: Json value to save
|
||||
void saveConfigFile(const std::string& filename, const nlohmann::json& config)
|
||||
{
|
||||
std::ofstream stream(filename);
|
||||
stream << std::setw(4) << config;
|
||||
}
|
||||
|
||||
// Connects to a bridge and returns it
|
||||
// username: Already existing username, can be left empty.
|
||||
// macAddress: MAC address of the bridge, can be left empty.
|
||||
// throws std::runtime_error when the bridge was not found.
|
||||
// returns a connected bridge.
|
||||
hue::Bridge connectToBridge(const std::string& username, const std::string& macAddress)
|
||||
{
|
||||
hue::BridgeFinder finder(std::make_shared<SystemHttpHandler>());
|
||||
|
||||
std::vector<hue::BridgeFinder::BridgeIdentification> bridges = finder.findBridges();
|
||||
|
||||
for (const auto& bridge : bridges)
|
||||
{
|
||||
std::cout << "Bridge: " << bridge.mac << " at " << bridge.ip << '\n';
|
||||
}
|
||||
if (bridges.empty())
|
||||
{
|
||||
std::cout << "Found no bridges\n";
|
||||
throw std::runtime_error("no bridges found");
|
||||
}
|
||||
|
||||
if (macAddress.empty())
|
||||
{
|
||||
std::cout << "No bridge given, connecting to first one.\n";
|
||||
return finder.getBridge(bridges.front());
|
||||
}
|
||||
if (!username.empty())
|
||||
{
|
||||
finder.addUsername(macAddress, username);
|
||||
}
|
||||
auto it = std::find_if(
|
||||
bridges.begin(), bridges.end(), [&](const auto& identification) { return identification.mac == macAddress; });
|
||||
if (it == bridges.end())
|
||||
{
|
||||
std::cout << "Given bridge not found\n";
|
||||
throw std::runtime_error("bridge not found");
|
||||
}
|
||||
return finder.getBridge(*it);
|
||||
}
|
||||
|
||||
// Connects to a bridge. The steps are:
|
||||
// - read "config.json" for an existing config
|
||||
// - connect to the bridge
|
||||
// - save the username to the config file for the next run
|
||||
//
|
||||
// Also prints out the IP and username.
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
const std::string filename = "config.json";
|
||||
try
|
||||
{
|
||||
|
||||
nlohmann::json config = readConfigFile(filename);
|
||||
const std::string username = config.value("username", "");
|
||||
const std::string macAddress = config.value("mac", "");
|
||||
hue::Bridge hue = connectToBridge(username, macAddress);
|
||||
|
||||
// Store updated information into file
|
||||
config["username"] = hue.getUsername();
|
||||
config["mac"] = hue.config().getMACAddress();
|
||||
saveConfigFile(filename, config);
|
||||
|
||||
std::cout << "Connected to bridge. IP: " << hue.getBridgeIP() << ", username: " << hue.getUsername() << '\n';
|
||||
}
|
||||
catch (...)
|
||||
{ }
|
||||
|
||||
std::cout << "Press enter to exit\n";
|
||||
std::cin.get();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user