Code Monkey home page Code Monkey logo

lighting-manager's Introduction

Lighting Manager

Control your ws281x LED strip with a Raspberry Pi through an API.


Setup

Docker

This can be run with docker-compose up -d lighting-manager with the following compose file:

version: "3"

services:
  lighting-manager:
    image: ghcr.io/fgardt/lighting-manager:latest
    container_name: lighting-manager
    restart: unless-stopped
    privileged: true
    ports:
      - "88:88"
#    environment:
#      - LOG_LEVEL=trace
    command: ["--count", "YOUR_LED_COUNT", "--pin", "YOUR_PIN"]

note: the container needs to be run in privileged mode to access the GPIOs.
note: default log level for the container is info. If you want to override it to any other value you'll need to use the environment variable. Possible values are off, error, warn, info, debug and trace.

Standalone

Another option would be to either compile the code yourself or download the binary from the latest release.
Once you have the binary simply execute it (and pass along all required flags described below).

note: this will probably need to be run as root or with sudo so it can access the GPIOs.

Compiling it yourself:

You could try to compile it directly on your Raspberry Pi but I highly doubt it will work (maybe on a Pi 4, couldn't try that yet).

To compile for your Raspberry on another machine you will need some dependencies.
This from now on assumes that you are on Ubuntu and have the rust toolchain already installed.

  • rustup target add arm-unknown-linux-gnueabihf
  • sudo apt install libclang-dev gcc-arm-linux-gnueabihf

To compile run cargo build --release --target arm-unknown-linux-gnueabihf.
The binary should be located at target/arm-unknown-linux-gnueabihf/release/lighting-manager.


Command flags

Usage: lighting-manager [OPTIONS] --pin <PIN> --count <COUNT>

Options:
  -p, --port <PORT>            Sets the port to listen on [default: 88]
  -a, --address <ADDRESS>      Sets the ip address to listen on [default: 0.0.0.0]
  -P, --pin <PIN>              Sets the pin to which the WS281x LED string is connected
  -c, --count <COUNT>          Sets the count of LEDs in the string
      --log-level <LOG_LEVEL>  Sets the used logging level
                               Possible values: error, warn, info, debug, trace
                               For no logging don't set this option
                               Note: the LOG_LEVEL environment variable overrides this option
  -h, --help                   Print help information
  -V, --version                Print version information

API

The API listens for HTTP GET requests. Values are parsed from the URI.

/

Returns a message with the current running version of the program.

/all_modes

Returns all currently supported modes of the program as JSON.

Example:

Request: http://your-pi:88/all_modes
Response (pretty printed):

{
  "ALARM": 4,
  "COLORRAPE": 5,
  "IDENTIFY": 7,
  "OFF": 0,
  "RAINBOW": 2,
  "SLEEP": 3,
  "STATIC": 1,
  "STROBE": 6
}

note: both the key and the corresponding value can be used to refer to a mode.

/mode

Returns the currently active mode.

Example:

Request: http://your-pi:88/mode
Response:

Current mode: STATIC

/mode/{MODE}

Change the currently active mode to {MODE}.

Example:

Request: http://your-pi:88/mode/RAINBOW
Response:

Updated mode: RAINBOW

note: the passed mode is case-insensitive or can also be the corresponding integer (2 in the case of RAINBOW).

/[h,s,v]

Returns the current value for hue, saturation or value.

Example:

Request: http://your-pi:88/h
Response:

Current HUE: 30

note: returned values are floats and range from [0-360) (hue) and [0-1] (saturation & value).

/[h,s,v]/{VALUE}

Change the current value for hue, saturation or value to {VALUE}.

Example:

Request: http://pi-squared.local/h/340.5
Response:

Updated HUE: 340.5

note: values get clipped to the previously mentioned ranges.
note: for legacy reasons provided values can also be treated as unsigned integers [0-360) (hue) and [0-255] (saturation & value).

/plain/[h,s,v,mode]

Returns the current value for hue, saturation, value or the currently active mode.

Example:

Request: http://pi-squared.local/plain/h
Response:

340.5

note: returned modes are in lowercase.

lighting-manager's People

Contributors

dependabot[bot] avatar fgardt avatar

Watchers

 avatar

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.