Philips hue lighting system - a JSON device

11 views (last 30 days)
My son got a Philips Hue bridge (network device) and some wi-fi bulbs. He wants to have his computer control the light bulbs. Has anyone played around with this Philips "personal wireless lighting system"? There is a Developers site and there are SDKs in a wide variety of languages but sadly none in MATLAB. So I guess one approach is to use the Java SDK and talk to that from MATLAB. I could probably figure it out but I was just hoping that if someone has done it already, I could start with a leg up. I already searched the entire Mathworks website and there is nothing on it (so far).
  7 Comments
Massimo Ciacci
Massimo Ciacci on 1 Jul 2017
Edited: Massimo Ciacci on 1 Jul 2017
Finding the IP address was not too hard, as follows:
url = 'https://www.meethue.com/api/nupnp';
data = webread(url);
Hue_ID = data.id;
Hue_IP = data.internalipaddress;
url = sprintf('http://%s/api/invalidUserID1234/', Hue_IP)
response = webread(url);
response.error
type: 1
address: '/'
description: 'unauthorized user'
Now I have to figure out how to use POST without using webwrite (I use ML2014b) to send messages to it such as..
body = '{"devicetype":"my_hue_app#_appname"}'
The next step would be to get a valid user name after pairing with the bridge (pressing the button on it), as described in
https://www.developers.meethue.com/documentation/getting-started
Image Analyst
Image Analyst on 1 Jul 2017
Nice trick. I've oncorporated it into my code. But I wonder how meethue.com knows the IP address of my lamp. Does the lamp "phone home" to Philips?
I'll post my code, which does lots of fancy things with the Hue lamp below as an answer sometime today. Will probably upload it to my File Exchange this weekend.

Sign in to comment.

Accepted Answer

Stephen Doe
Stephen Doe on 19 Jan 2016
The webwrite function supports GET and POST methods only.
You might try using urlread2 to communicate with the device. It's a user submission that might help you.
  6 Comments
Walter Roberson
Walter Roberson on 27 Jan 2016
On the previous firmware on my Cisco/Linksys it would have been no problem to add a fixed IP address for a MAC address. With the version I seem to have now, I don't see a way to do it.
You can use a tool such as nmap to find out what devices are present on your local network.
If you were using a Unix type system then you would be able to use netstat to read the table of known MAC addresses off of your PC. I think there might be an equivalent for MS Windows, but do not have time to check.
Walter Roberson
Walter Roberson on 1 Jul 2017
Looking again on my Linksys router, if I connect to the router's web page from the lan, log in, select "Connectivity", and click on the "Local Network" tab, then there is a DHCP Server section and a DHCP Reservations button there. clicking on that gets me to another page that lists the current reservations and has a "Manually add device reservation" button that can be used to associate an internal IP address with a particular MAC address.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 1 Jul 2017
Edited: Image Analyst on 2 Jul 2017
Mark, I have a Philips Hue and have made a nice program that will let you send any color to your lamp. Plus it will let you browse to a folder with music files and it will let you change the color of the lamp in time with the music as it plays. I've also measured the spectrum of the lamp with my Ocean Optics spectrometer, and the spectrum of the emitted light is displayed as the light color changes. So the spectrum is accurate.
The code is attached, and in my File Exchange. The comments are below:
% Program to manipulate the colors by the Philip Hue wireless LED lighting system.
% Program plays music files and the brightness of the lamp is controlled by the volume of the song.
% Communicate with a Philips Hue bridge to talk to the Hue personal wireless LED lights.
% Ref: http://www.developers.meethue.com/documentation/getting-started
% Make sure you do everything on that page to find out the IP Address of the bridge (something like '192.168.1.120'),
% and to set yourself up as an authorized user (with a string something like 1028d66426293e821ecfd9ef1a0731df that identifies you).
% Uses function urlread2() from the File Exchange. http://www.mathworks.com/matlabcentral/fileexchange/35693-urlread2
% Although the program will work with any music file, these are
% recommended music files to effectively demonstrate the capability of the program and lamp.
% Note: classical music pieces seem best because they vary the volume slowly and have a great dynamic range in volume.
% Fanfare for the Common Man, by Aaron Copland
% Symphony #5 by Beethoven
% Symphony #9 "New World" by Antonin Dvorak (one of the best symphonies ever written)
% O'Fortuna from Carmina Burana by Carl Orff (powerful, spine tingling music I'm sure you've heard before)
% Toccata in D minor by Bach (haunting, creepy funeral dirge organ music)
% Also Sprach Zarathustra by Richard Strauss (2001 a Space Oddysey movie theme)
% The Four Seasons by Vivaldi
% Anvil Chorus by Giuseppe Verdi
% Palladio Allegretto by Karl Jenkins (deBeers "A Diamond is Forever" theme music)
% Note: Some music that you might think would be good, such as Ode To Joy by Beethoven, which have a good beat,
% unfortunately change too rapidly for the lamp to follow. The lamp can only change colors about 10 times a second, but it seems
% even slower than that.
% Some rock songs that play well because of large but slow volume oscillations are
% Good Times Bad Times by Led Zeppelin
% Dazed and Confused by Led Zeppelin
% Stairway to Heaven by Led Zeppelin (actually almost any Led Zeppelin song!)
% We will Rock You by Queen
% Good Riddance (Time of Your Life) by Green Day
% Uprising by Muse
% Viva la Vida by Coldplay

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!