Giter Site home page Giter Site logo

daniel1111 / huelibent Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 4.0 107 KB

A library to control Hue entertainment areas from C with an audio visualiser as an example

License: BSD 2-Clause "Simplified" License

C 96.15% CMake 3.85%
hue dtls visualiser hue-entertainment

huelibent's Introduction

LibHueEnt - A library to control Hue entertainment areas from C

There are two main parts to this project:

  • The LibHueEnt library which can be used to control up to 10 hue lights simultaneously with up to 25 updates per second. It is not suitable for infrequently toggling single lamps. See API docs
  • HueVis - An audio visualiser for hue lights using LibHueEnt, heavily based on the CAVA project

There is also an additional example app (BasicColourFade) which is a basic example of using LibHueEnt to cycle though colours on each bulb in the entertainment area in turn. Unlike HueVis, this app isn't capable of registering itself with the bridge, so that needs to be done manually using the REST API on the bridge (for HueVis).

Requirements

  • OS: Currently only tested on Linux / Debian Stretch
  • Hue: A v2 Hue bridge on API version >= 1.22

Building

Debian:

apt-get install make libconfig-dev libssl-dev libjson-c-dev libfftw3-dev libpulse-dev libcurl4-gnutls-dev cmake

Then run cmake . followed by make in the repository root.

Usage

Before LibHueEnt will work, an entertainment area must be set up using the Hue app. This can be done from Settings > Entertainment Areas > Create entertainment area, then add some rooms / bulbs to the area. Once set up, run though the test to check it's working.

BasicColourFade

BasicColourFade is intended to be a simple example of using LibHueEnt, and is missing basic features like being able register itself with the bridge and using a config file, so everything must supplied on the command line.

So, to use it:

  1. Either follow the instructions on the Hue website to register with the bridge and get a username & clientkey, or use HueVis to register with the bridge and take its credentials from the generated bridge_credentials.conf file
  2. From the root directory, run ./bin/bcf -a <ip address> -i <username> -p <clientkey>

All going well, you should something along the lines of:

Getting entertainment areas
Enabling entertainment area [Entertainment area 1]
Making DTLS connection to bridge
Running...
Light = 0 (id = 12)

And each light in the entertainment cycling though colours in turn.

HueVis

HueVis is really the reason LibHueEnt exists - I wanted a music visualiser for Hue lights, but couldn't find anything for Linux that would use the entertainment area stuff that was recently(-ish) added to Hue. All the logic for audio capture and processing is pretty much ripped off from the CAVA project, which is designed to show a bar spectrum audio visualizer on the console. HueVis currently has two modes of operation (set in huevis.conf):

  1. cava_mode=1 - The brightness of each bulb represents what would have been a bar in the CAVA output. This means that all lamps are always the same colour, and the brighness of each light is (generally) different
  2. cava_mode=2 - CAVA is used to generate the equivalent of 3 bars, and the values are used for the value of Red/Green/Blue for all bulbs

Configuration

The huevis.conf file includes comments for the few options HueVis currently has, but the important one is audio_input - this controls where HueVis gets the audio from. The options are:

  • pulse - Use pulseaudio, the default can be specified using pulse_source, but if blank, the default device is used.
  • squeezelite - Gets audio from a running instance of squeezelite. Note that must be built with visualiser support and the -v parameter passed to it

Usage

After building, the first step is to register HueVis with the bridge. From the root directory, press the link button on the bridge and then within 30 seconds run ./bin/HueVis -r <ip address of bridge>. HueVis should then register with the bridge and write the connection details to a bridge_credentials.conf file.

Example

Example of HueVis running:

$ ./bin/huevis 
Getting entertainment areas
Enabling entertainment area [Entertainment area 1]
Making DTLS connection to bridge
Init audio
Using audio source: alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
Start audio capture & processing
Running...

HueVis

Hutil

A simple utility that can register with the bridge, show the whitelist (registered applications) and list configured entertainment areas.

Example

Registering; after pressing the link button on th bridge:

$ ./bin/hutil -r 192.0.2.10
Registered with hue bridge, config saved

Showing entertainment areas:

$ ./bin/hutil -e

Entertainment areas:
ID      Name                             Light IDs
6       Entertainment area 1             12 13 15 14 

Hdmx

HDmx is a simple DMX to Hue Entertainment Brudge. It is missing basic features like being able register itself with the bridge and using a config file, so everything must supplied on the command line.

So, to use it:

  1. Either follow the instructions on the Hue website to register with the bridge and get a username & clientkey, or use Hutil to register with the bridge and take its credentials from the generated bridge_credentials.conf file
  2. From the root directory, run ./bin/hdmx -a <ip address> -i <username> -p <clientkey> -e <area>

is the order the area's are listed, not the Area ID. All going well, you should something along the lines of:

Getting entertainment areas
2 lights found in entertainment area [Entertainment area 1]
Enabling entertainment area [Entertainment area 1]
Making DTLSc connection to bridge

Once running this creates an ART-NET node. Each light appears as a 3 channel RGB device, and can be controlled by any DMX software or hardware that supports ART_NET.

TODO

LibHueEnt:

  • Allow automatic bridge discovery - instead of always requiring an IP address to be entered - by following the notes on the Hue website
  • A better example - more involved than BasicColourFade e.g. with registration, maybe using multiple entertainment areas, etc

HueVis:

  • Most settings available in the CAVA project currently have hard-coded values. Some of these should probably be exposed in the config file
  • Other modes. The code is structured to allow adding something other than CAVA to process the audio at some point. CAVA works well, but other options could be interesting. In particular, a mode that uses varying colour and the same time as different bulbs doing different things would be good

huelibent's People

Contributors

chincheta0815 avatar daniel1111 avatar dctsystems avatar eric avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

huelibent's Issues

Question concerning an implementation of HueVis.

Hi daniel1111,

I found your great project and remembered that I once had the same issue on coupling squeezelite with hue.
So I worked on LMS-to-Hue (https://github.com/chincheta0815/LMS-to-Hue/tree/master/helper/LMS-to-Hue)

That thing discovers the Bridge, shows it as a LMS player, gets the music stream and is supposed to analyze it and flash the lights.

So far the idea. Until now that thing simply has issues with the correct stream output:

  1. I do not know if I get 16bit PCM correctly and the if I split up the channels correctly.
  2. Since point 1 I do not know if the analysis is correct.

But maybe you like the project. If you have any hints on how to get the audio stream and the analysis correctly I would also be happy.

BTW: I had to add minor functions to libHueEnt as I needed the apiversion. Maybe some headers (and functions) should be named more "liebhueent" specific (debug.h --> hue_debug.h, dtls.h --> hue_dtls.h) or so...
Do you want me to send as a pull request?

Best regards

C99

Getting this error while trying to compile!
[ 6%] Building C object CMakeFiles/HueEnt.dir/src/hue_rest.c.o /root/HueLibEnt/src/hue_rest.c: In function ‘free_whitelist’: /root/HueLibEnt/src/hue_rest.c:83:3: error: ‘for’ loop initial declarations are only allowed in C99 mode for (uint i=0; i < ctx->whitelist_count; i++) ^ /root/HueLibEnt/src/hue_rest.c:83:3: note: use option -std=c99 or -std=gnu99 to compile your code /root/HueLibEnt/src/hue_rest.c: In function ‘parse_entertainment_groups_json’: /root/HueLibEnt/src/hue_rest.c:657:7: error: ‘for’ loop initial declarations are only allowed in C99 mode for (int n = 0; n < json_object_array_length(obj_param) && n < MAX_LIGHTS_PER_AREA; n++) ^ make[2]: *** [CMakeFiles/HueEnt.dir/src/hue_rest.c.o] Error 1 make[1]: *** [CMakeFiles/HueEnt.dir/all] Error 2 make: *** [all] Error 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.