enwi / hueplusplus

A simple C++ library to control Philips Hue lights on Linux, MacOS, Windows, Espressif ESP32 SDK and Arduino. Full documentation at
https://enwi.github.io/hueplusplus/
GNU Lesser General Public License v3.0
55 stars 22 forks source link

json.exception.parse_error.101 when getting access to lights #87

Closed DoubVarial closed 1 year ago

DoubVarial commented 1 year ago

Describe the bug: I created a Bridge object with the IP, Port and username of my bridge. Now I want to get access to the lights of my Hue-system, where a json parse error is thrown.

To Reproduce: I used some of the code-snippets of the getting-started section and the BridgeSetup.cpp example:

#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;

// Connects to a bridge and returns it.
hue::Bridge connectToBridge()
{
    auto handler = std::make_shared<hueplusplus::WinHttpHandler>();
    hueplusplus::Bridge bridge("MyIP", 80, "<MyUsername>", handler);

    return bridge;
}
int main(int argc, char** argv)
{
    try
    {
        hue::Bridge hue = connectToBridge();
        std::cout << "Connected to bridge. IP: " << hue.getBridgeIP() << ", username: " << hue.getUsername() << '\n';
        std::vector<hueplusplus::Light> lights = hue.lights().getAll();   
    }
    catch (nlohmann::json::parse_error& e)
    {
        std::cout << e.what() << '\n';

    }

    std::cout << "Press enter to exit\n";
    std::cin.get();

    return 0;
}

Expected behavior: I want to get the vector of the lights in my Hue-system

Console log/Error message: [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: '<'

Desktop (please complete the following information):

enwi commented 1 year ago

@DoubVarial You cannot use <MyUsername> as the username, please choose sth. else

DoubVarial commented 1 year ago

Thanks for your answer! I did not use <MyUsername>, but the correct username of my Hue-System. It seems that my Bridge cannot be found. I added the code-snippet with Hue-Finder and get the message No bridges found:


#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;

int main(int argc, char** argv)
{

    try
    {

        auto handler = std::make_shared<hueplusplus::WinHttpHandler>();
        hueplusplus::BridgeFinder finder(handler);
        std::vector<hueplusplus::BridgeFinder::BridgeIdentification> bridges = finder.findBridges();
        if (bridges.empty())
        {
            std::cerr << "No bridges found\n";

        }
    }
    catch(...)
    {
        std::cout << "Error" << '\n';
    }

    std::cout << "Press enter to exit\n";
    std::cin.get();

    return 0;
}

My bridge's modelid is BSB002 and uses apiversion 1.56.0 Do you have more tips for troubleshooting? Thank your very much!

enwi commented 1 year ago

My bridge has software version 1.56.1956178040 and model 3241312018 and is found using the example.

enwi commented 1 year ago

@DoubVarial Is BSB002 an older or newer model? I guess older since you have a lower software version?

Edit: 3241312018 is model BSB002, so it should be working fine

enwi commented 1 year ago

Can you try updating the software on your bridge?