Connected by TCP LED bulbs - code to control them

Given that the ‘Connected by TCP’ LED bulbs ( http://www.tcpi.com/connected-by-tcp ) is one of the least expensive automated bulbs on the market, I’ve been doing some research to figure out if Vera can control them. I found a website ( http://misterhouse.10964.n7.nabble.com/Success-controlling-TCP-Connected-lights-td19316.html ) that seems to have cracked the code. Information from that page is posted below: You basically need to send an HTTP POST message with your bulb’s device ID (DID) and the value you want to conrol. Further down in the linked page is the perl code needed to connect to the gateway and print a list of all your bulb device ids.

The misterhouse website/project seems to be an open source HA project written in Perl. Vera, of course, would need to send these HTTP POST messages in some Lua/Luup code. Can anyone help and post, perhaps with the fully encoded on/off example at the bottom of my origianal post, the code needed to send the HTTP POST message in lua/luup within a scene?


The decoded commands (with encoded versions < > and / characters
converted to plain ASCII) look like this:

ON/OFF:

cmd=DeviceSendCommand&data=11234567890YOURDIDVALUE&fmt=xml

where YOURDID is the DID of the light you want to control and VALUE is
either 0 (for off) or 1 (for on)

Brightness:

cmd=DeviceSendCommand&data=11234567890YOURDIDDIMVALUElevel&fmt=xml

where YOURDID is the DID of the light you want to control and DIMVALUE
is the brightness in percent (don’t use a % sigh on the end).

You can send them to the light with a command like this (properly
encoded and thus a bit harder to read) to turn on a light:

echo -n “cmd=DeviceSendCommand&data=%3Cgip%3E%3Cversion%3E1%3C%2Fversion%3E%3Ctoken%3E1234567890%3C%2Ftoken%3E%3Cdid%3EYOURDID%3C%2Fdid%3E%3Cvalue%3E1%3C%2Fvalue%3E%3C%2Fgip%3E&fmt=xml” | POST -P “http://YOURGWIP/gwr/gop.php

I was able to answer my own question…

Happy to share my findings with the community. I now have a Connected by TCP bulb controlled by two simple Vera scenes - one to turn on and one to turn off. The steps to get this working are:

1. The first thing you need to do after installing the kit (TCP gateway and bulb(s)) is to find the device id of the specific bulb you want to control. To do that, use a Chrome browser (Safari on OS X didn’t work) and send in the following request by pasting the following into the address bar and replacing GWURL with your TCP gateway’s IP address:

http://GWURL/gwr/gop.php?cmd=GWRBatch&data=<gwrcmds><gwrcmd><gcmd>RoomGetCarousel</gcmd><gdata><gip><version>1</version><token>1234567890</token><fields>name,image,imageurl,control,power,product,class,realtype,status</fields></gip></gdata></gwrcmd></gwrcmds>&fmt=xml

Contrary to other hints and findings on the internet that led to my success, the URL does not need to be encoded…pasting that “readable” format in worked fine for me.

2. Once you have your device id you can use the following Lua code to turn on your TCP bulb

[code]local http = require(“socket.http”)

– 5 Second timeout
http.TIMEOUT = 5

result, status = http.request(“http://GWIP/gwr/gop.php”, “cmd=DeviceSendCommand&data=112345678902162419697466735241&fmt=xml”)
[/code]

Replacing GWID, again, with your TCP gateway IP address and replacing the with the value you found in step 1. I left my value in the example above so you can see what it looks like…18 characters long. A 1 in the tag turns the bulb on, a 0 turns it off.

I have not implemented the dimming function yet, but it seems to be very straightforward, the code is below (found on the webpage I mentioned in my first post)…

Brightness:

cmd=DeviceSendCommand&data=<gip><version>1</version><token>1234567890</token><did>YOURDID</did><value>DIMVALUE</value><type>level</type></gip>&fmt=xml

Nice work!

[quote=“ctguess, post:2, topic:178901”]I was able to answer my own question…

1. The first thing you need to do after installing the kit (TCP gateway and bulb(s)) is to find the device id of the specific bulb you want to control. To do that, use a Chrome browser (Safari on OS X didn’t work) and send in the following request by pasting the following into the address bar and replacing GWURL with your TCP gateway’s IP address:

http://GWURL/gwr/gop.php?cmd=GWRBatch&data=<gwrcmds><gwrcmd><gcmd>RoomGetCarousel</gcmd><gdata><gip><version>1</version><token>1234567890</token><fields>name,image,imageurl,control,power,product,class,realtype,status</fields></gip></gdata></gwrcmd></gwrcmds>&fmt=xml

Great work!

To save a step, you can use the local hostname “lighting” instead of the IP address:

http://lighting/gwr/gop.php?cmd=GWRBatch&data=%3Cgwrcmds%3E%3Cgwrcmd%3E%3Cgcmd%3ERoomGetCarousel%3C/gcmd%3E%3Cgdata%3E%3Cgip%3E%3Cversion%3E1%3C/version%3E%3Ctoken%3E1234567890%3C/token%3E%3Cfields%3Ename,image,imageurl,control,power,product,class,realtype,status%3C/fields%3E%3C/gip%3E%3C/gdata%3E%3C/gwrcmd%3E%3C/gwrcmds%3E&fmt=xml

Note that this only seemed to work in the browser and not in LUUP code, where I had to use the IP.

BTW, in addition to scene scripting, I got ambitious and decided to use ctguess’s info to write a plugin for a Connected By TCP gateway. It’s pretty well done, but I need to add in polling logic and would like to test some more edge cases. Since I am off on business for a week, it won’t be until the week of the 3rd that I’ll have something to share.

The basic approach I followed is to create a new device type for the gateway, which in turn creates standard child devices (Dimming1 or PowerSwitch) for each bulb.

Beta plugin posted at [url=http://forum.micasaverde.com/index.php/topic,22944.0.html]http://forum.micasaverde.com/index.php/topic,22944.0.html[/url]

I have been capturing packet to figure out the command set for TCPi as well here are a few I have come up with.

To get your device id’s
cmd=GWRBatch&data=SceneGetList11234567890bigicon,detail,imageurl1&fmt=xml

cmd=DeviceSendCommand&data=11234567890DEVICE_ID50level&fmt=xml

cmd=GWRBatch&data=SceneGetList11234567890bigicon,detail,imageurl1&fmt=xml

cmd=GWRBatch&data=RoomGetCarousel11234567890name,image,imageurl,control,power,product,class,realtype,statusUserGetListDefaultRooms11234567890UserGetListDefaultColors11234567890&fmt=xml"
cmd=SceneGetList&data=11234567890DEVICE_IDactiveonly,bigicon,detail,imageurl1&fmt=xml

Adjust Dimness
cmd=DeviceSendCommand&data=11234567890DEVICE_ID29level&fmt=xml

Trun On
cmd=DeviceSendCommand&data=11234567890DEVICE_ID1&fmt=xml

Gateway Info
cmd=GatewayGetInfo&data=112345678901&fmt=xml

When I try to use your Luup files
I get one _dimmable Light in the device tab. I have two such bulbs that I can get data to and from via the browser direct commands

It looks like the log shows the gateway not found at startup
50 02/05/14 19:37:37.494 luup_log:26: SysMon: Initialising System Monitor Plugin <0x2be45680>
50 02/05/14 19:37:37.495 luup_log:26: SysMon: Startup complete <0x2be45680>
50 02/05/14 19:37:37.499 luup_log:36: TCPLighting: tcplighting_plugin_startup - start <0x2be45680>
50 02/05/14 19:37:37.499 luup_log:36: TCPLighting: tcplighting_plugin_startup - not gateway <0x2be45680>
50 02/05/14 19:37:37.500 luup_log:36: TCPLighting: tcplighting_plugin_startup - end <0x2be45680>

Is there any other data that needs to be added when entering the information in step 4?

08 02/05/14 19:39:34.824 JobHandler_LuaUPnP::HandleActionRequest device: 36 service: urn:upnp-org:serviceId:Dimming1 action: e[36;1mSetLoadLevelTargete[0m <0x2ec45680>
08 02/05/14 19:39:34.825 JobHandler_LuaUPnP::HandleActionRequest argument DeviceNum=36 <0x2ec45680>
08 02/05/14 19:39:34.825 JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:upnp-org:serviceId:Dimming1 <0x2ec45680>

Thanks

I think the plug- in will be fantastic

Thanks for working on this! Do you know if the TCP bulbs will work to extend the mesh of my z-wave network? My guess would be no, but I’m hoping I’m wrong…

The TCP bulbs are not z-wave. It will not extend your z-wave network.

  • Garrett

[quote=“garrettwp, post:9, topic:178901”]The TCP bulbs are not z-wave. It will not extend your z-wave network.

  • Garrett[/quote]

Thanks! I would have sworn the TCP rep I spoke with at CES told me they were z-wave, but that was before I was neck deep in this stuff trying to figure it out, so likely remembering wrong. Should have double checked that oh so basic fact before posting!

The protocol they use is Jennet.

Thanks everyone for the info, I have stated a simple php Web application to control the bulbs, create schedules and read scenes. It works with the new and old bridge firmware. I’m trying to essentially make an app clone with a Web interface. Controlling the bulbs is in there.

Check it out here :

Hope it helps someone