peter-murray / node-hue-api

Node.js Library for interacting with the Philips Hue Bridge and Lights
Apache License 2.0
1.19k stars 145 forks source link

Parse Error on setting rgb() color #74

Closed mwittig closed 8 years ago

mwittig commented 8 years ago

I am testing against the latest version 0.6 of the Hue Emulator.

var state = lightState.create().rgb(128, 128, 128);
api.setLightState(1, state).then(displayResult).done();

... gives me the following error:

c:\Users\marcus\Documents\Devel\node_modules\node-hue-api\node_modules\q\q.js:155
                throw e;
                      ^
Error: Parse Error
    at Socket.socketOnData (http.js:1584:20)
    at TCP.onread (net.js:528:27)

Process finished with exit code 8

If I use .hsl() instead it works fine. For this reason I guess it is problem with node-hue-api.

peter-murray commented 8 years ago

It works as expected for a real bridge. The problem is with the Hue Emulator.

To make a conversion between rgb into the xy co-ordinates, a conversion has to be made that is specific to the model of the bulb that is the target. This conversion is done using information on the modelid that is returned from light status for the id of the light.

I took a very quick look at the code the for Hue Emulator and could not find the location of where it is getting the configuration of the lights, so cannot comment if it is hard coded, or something that a user of the emulator provides.

If you turn on the long stack traces for Q, https://github.com/kriskowal/q#long-stack-traces, you should be able to see more information as to where the real problem lies.

mwittig commented 8 years ago

Well, I don't think so. Here is the configuration the emulator is using. As you can see the bulbs have a proper modelid "LCT001" used for Hue A19. Also the colormode is set. Is there anything else missing your library is using for conversion?

{
    "lights": {
        "1": {
            "state": {
                "on": true,
                "bri": 254,
                "hue": 4444,
                "sat": 254,
                "xy": [0.0,
                0.0],
                "ct": 0,
                "alert": "none",
                "effect": "none",
                "colormode": "hs",
                "reachable": true
            },
            "type": "Extended color light",
            "name": "Hue Lamp 1",
            "modelid": "LCT001",
            "swversion": "65003148",
            "uniqueid": "00:17:88:01:00:d4:12:08-0a",
            "pointsymbol": {
                "1": "none",
                "2": "none",
                "3": "none",
                "4": "none",
                "5": "none",
                "6": "none",
                "7": "none",
                "8": "none"
            }
        },
        "2": {
            "state": {
                "on": true,
                "bri": 254,
                "hue": 23536,
                "sat": 144,
                "xy": [0.346,
                0.3568],
                "ct": 201,
                "alert": "none",
                "effect": "none",
                "colormode": "hs",
                "reachable": true
            },
            "type": "Extended color light",
            "name": "Hue Lamp 2",
            "modelid": "LCT001",
            "swversion": "65003148",
            "uniqueid": "00:17:88:01:00:d4:12:08-0b",
            "pointsymbol": {
                "1": "none",
                "2": "none",
                "3": "none",
                "4": "none",
                "5": "none",
                "6": "none",
                "7": "none",
                "8": "none"
            }
        },
        "3": {
            "state": {
                "on": true,
                "bri": 254,
                "hue": 65136,
                "sat": 254,
                "xy": [0.346,
                0.3568],
                "ct": 201,
                "alert": "none",
                "effect": "none",
                "colormode": "hs",
                "reachable": true
            },
            "type": "Extended color light",
            "name": "Hue Lamp 3",
            "modelid": "LCT001",
            "swversion": "65003148",
            "uniqueid": "00:17:88:01:00:d4:12:08-0c",
            "pointsymbol": {
                "1": "none",
                "2": "none",
                "3": "none",
                "4": "none",
                "5": "none",
                "6": "none",
                "7": "none",
                "8": "none"
            }
        }
    },
    "schedules": {
        "1": {
            "time": "2012-10-29T12:00:00",
            "description": "",
            "name": "schedule",
            "command": {
                "body": {
                    "scene": null,
                    "on": true,
                    "xy": null,
                    "bri": null,
                    "transitiontime": null
                },
                "address": "/api/newdeveloper/groups/0/action",
                "method": "PUT"
            }
        }
    },
    "config": {
        "portalservices": false,
        "gateway": "192.168.178.1",
        "mac": "00:00:88:00:bb:ee",
        "swversion": "01005215",
        "linkbutton": false,
        "ipaddress": "192.168.178.70:8000",
        "proxyport": 0,
        "swupdate": {
            "text": "",
            "notify": false,
            "updatestate": 0,
            "url": ""
        },
        "netmask": "255.255.255.0",
        "name": "Philips hue",
        "dhcp": true,
        "proxyaddress": "",
        "whitelist": {
            "newdeveloper": {
                "name": "test user",
                "last use date": "2012-10-29T12:00:00",
                "create date": "2012-10-29T12:00:00"
            }
        },
        "UTC": "2012-10-29T12:05:00"
    },
    "groups": {
        "1": {
            "name": "Group 1",
            "action": {
                "on": true,
                "bri": 254,
                "hue": 33536,
                "sat": 144,
                "xy": [0.346,
                0.3568],
                "ct": 201,
                "alert": null,
                "effect": "none",
                "colormode": "xy",
                "reachable": null
            },
            "lights": ["1",
            "2"]
        }
    },
    "scenes": {

    }
}
peter-murray commented 8 years ago

I put together a quick test on the latest 2.0.1 version of the API against the 0.7 version of the Hue Emulator using the configuration you provided above. I bound the emulator to localhost port 80.

It worked for me with no errors.

What version of the API and Hue Emulator are you using, 0.6? The config above would not load into the 0.6 version of the Hue Emulator for me. Are you getting any requests showing up in the emulator? If not, try turning on the long stack traces, or use another library like longjohn that will generate a more complete stack trace that could give me something more to go on.