Code Monkey home page Code Monkey logo

lighthouse's Introduction

LightHouse

Control lights and other devices connected to multiple Arduinos with Redis Pub/Sub messaging.

Build Status

Installing / Getting started

Prerequisites

  • A running Redis server
  • One or more Arduinos flashed with the firmata sketch.

Installation

  1. Download a binary for your system from the releases page.
  2. Create a config.toml and place it next to the binary (See configuration).
  3. Start the binary
cd lighthouse
wget https://.../lighthouse
nano config.toml
./lighthouse

Lighthouse should now be connecting to the specified Redis server and await commands on the configured channel.

Configuration

LightHouse is configured with the config.toml file. The service expects this file to be in the current working directory.

A minimal config.toml might look like this:

[redis]
host = "127.0.0.1:6379"
topic = "lighthouse"

[boards]
  [boards.first]
  serial = "/dev/ttyUSB0"
    [boards.first.dev]
      [boards.first.dev.led]
      mode = "direct"
      inverted = false
      pinse = ["13"]

This tells LightHouse to connect to the redis server running on 127.0.0.1:6379 and subscribe to the channel lighthouse. It configures one Arduino connected to /dev/ttyUSB0 and exposes the internal LED on pin 13.

[redis]

The [redis] section is pretty self-explainatory. Specify IP and Port in the host field and the Pub/Sub channel in the topic field.

[boards]

The [boards] section is the list of Arduinos to connect to.

[boards.name]

Each Arduino has a serial field, specifying the serial port and a dev array.

[boards.name.dev.name]

Give each device a unique name across all boards! You will later address a device using this name.

mode
what kind of device (for example "direct", "pwm" or "servo", see modes).

inverted
some modes have an inverted mode. If you have an LED connected to +5V and Arduino pin 2, you would need to set inverted to true.

pins
array of pins to use for this mode. some modes require multiple pins (e.g the rgb mode requires a red, green and a blue pin.)
Some modes will also perform actions on all pins if you specify more than one.

Commands

Commands are received through Redis Pub/Sub. To send a command you publish a JSON string to the configured channel:

$ redis-cli
redis> PUBLISH lighthouse '{"device": "internal", "action": "on", "params": {}}'
redis> PUBLISH lighthouse '{"device": "internal", "action": "write", "params": {"power": false}}'

Each command has the following format

{
  "device": "rgblight",
  "action": "color",
  "params": {
    "red": 255,
    "green": 96,
    "blue": 0
  }
}

device
the unique device identifier specified in the config.toml

action
which action to perform on the device. supported actiosn depend on the driver

params
parameters for the action

Modes

Currently, LightHouse supports the following modes:

Name Description Inverted Pins
direct switch a pin high or low value = !value same on all
pwm apply pwm to a pin value = 1-value same on all
rgb control an rgb-led like pwm r, g, b
servo control a servo does not apply same on all

Direct

Action Params
on {}
off {}
write {"power": bool}

Pwm

Action Params
on {}
off {}
power {"power": bool}
brightness {"brightness": float} (0 to 1)
write {"power": bool, "brightness": float} (0 to 1)

Rgb

Action Params
on {}
off {}
power {"power": bool}
color {"red": int, "green": int, "blue": int} (0 to 255)
write {"power": bool, "red": int, "green": int, "blue": int}

Servo

Action Params
on {}
off {}
power {"power": bool}
angle {"angle": int} (0 to 180)
write {"power": bool, "angle": int}

Licensing

The code in this project is licensed under the 2-Clause BSD license (BSD-2-Clause). See LICENSE for further details.

lighthouse's People

Contributors

xanecs avatar

Stargazers

 avatar

Watchers

 avatar  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.