// Callback handler on GET request
void onGet(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int eCode)
{
    (void)headerOptions;
    try
    {
        if (eCode == OC_STACK_OK)
        {
            std::cout << "GET request was successful" << std::endl;
            std::cout << "Resource URI: " << rep.getUri() << std::endl;

            std::cout << "Payload: " << rep.getPayload() << std::endl;

            rep.getValue("on-off", mylight.m_on_off);
            rep.getValue("dim", mylight.m_dim);
            rep.getValue("color", mylight.m_color);

            std::cout << "\ton-off: " << mylight.m_on_off << std::endl;
            std::cout << "\tcolor: " << mylight.m_color << std::endl;
            std::cout << "\tdim: " << mylight.m_dim << std::endl;

            putLightRepresentation(curResource);
        }
        else
        {
            std::cout << "onGET Response error: " << eCode << std::endl;
        }
    }
    catch (std::exception &e)
    {
        std::cout << "Exception: " << e.what() << " in onGet" << std::endl;
    }
}
void onGetForDISensor(const HeaderOptions &headerOptions, const OCRepresentation &rep,
                      const int eCode)
{
    (void)headerOptions;
    try
    {
        if (eCode == OC_STACK_OK)
        {
            std::cout << "GET request was successful" << std::endl;
            std::cout << "Resource URI: " << DISensorResource->uri() << std::endl;

            std::cout << "Payload: " << rep.getPayload() << std::endl;

            std::cout << "\tdiscomfortIndex: " << rep.getValue<std::string>("discomfortIndex") << std::endl;
        }
        else
        {
            std::cout << "onGET Response error: " << eCode << std::endl;
        }
    }
    catch (std::exception &e)
    {
        std::cout << "Exception: " << e.what() << " in onPut" << std::endl;
    }
}
Example #3
0
void handleLoginoutCB(const HeaderOptions &,
                      const OCRepresentation &rep, const int ecode)
{
    cout << "Auth response received code: " << ecode << endl;

    if (rep.getPayload() != NULL)
    {
        printRepresentation(rep);
    }

    if (ecode == 4)
    {
        g_accesstoken = rep.getValueToString("accesstoken");

        g_uid = rep.getValueToString("uid");
    }

    g_callbackLock.notify_all();
}