Giter VIP home page Giter VIP logo

lifx's Introduction

Lifx

A Client for Lifx LAN API

Automatically discover and control all of your Lifx lightbulbs.

Use

1. git clone https://github.com/brianmay/lifx.git
2. mix do deps.get, deps.compile
3. iex -S mix

Explanation

As long as you are on the same subnet as your lightbulbs, you should see some information in stdout about devices being discovered

Starting Device
%Lifx.Device{
    group: %Lifx.Protocol.Group{
        id: [],
        label: nil,
        updated_at: 0
    },
    host: {192, 168, 1, 118},
    id: :"193196534887376",
    label: nil,
    location: %Lifx.Protocol.Location{
        id: [],
        label: nil,
        updated_at: 0
    },
    port: 56700,
}

What's shown here is the initial state of the bulb. Shortly after the bulb is discovered it will gather the state information, and update it every 5 seconds.

Architecture

Architecture Image

Lifx.Client is a small UDP server running on a randomly selected available port. As a new device is discovered a process is spawned and added to the device list maintained by Lifx.Client.

Every 5 seconds the device process queries itself for updated information. Only basic information is kept, such as connection information, group, and location. The updated information is then broadcast (using notify) over Lifx.Client.Events event bus. Anyone can add a handler to the event bus to handle updated device state by calling Lifx.Client.add_handler. See Lifx.Handler for an example implementation of an event handler.

If the device cannot be contacted, it is considered dead. A deleted notification is broadcast, and the device removed from the device list.

There's a good chance that by the time you've added your handler to Lifx.Client that device discovery has already happened. Luckily Lifx.Client also keeps a list of the known devices. You can return the currently known devices by calling Lifx.Client.devices which returns something similar to this.

[
    %Lifx.Device{
        group: %Lifx.Protocol.Group{
            id: <<251, 202, 127, 40, 82, 243, 115, 230, 221, 64, 134, 187, 206, 118, 102, 156>>,
            label: "Lab",
            updated_at: 13888846944200582420
        },
        host: {192, 168, 1, 118},
        id: :"193196534887376",
        label: "Bulb 2",
        location: %Lifx.Protocol.Location{
            id: <<205, 66, 137, 157, 220, 168, 133, 96, 147, 254, 0, 111, 52, 160, 229, 6>>,
            label: "CRT Lab",
            updated_at: 13836094609682883860
        },
        port: 56700,
    },
    %Lifx.Device{
        group: %Lifx.Protocol.Group{
            id: <<251, 202, 127, 40, 82, 243, 115, 230, 221, 64, 134, 187, 206, 118, 102, 156>>,
            label: "Lab",
            updated_at: 13868661424052266260
        },
        host: {192, 168, 1, 60},
        id: :"204217420968912",
        label: "Bulb 1",
        location: %Lifx.Protocol.Location{
            id: <<205, 66, 137, 157, 220, 168, 133, 96, 147, 254, 0, 111, 52, 160, 229, 6>>,
            label: "CRT Lab",
            updated_at: 9281461546755319060
        },
        port: 56700,
    }
]

Lifx.Protocol handles all protocol related functions, parsing and creating packets as well as payloads.

In order to communicate with a single bulb, in a network that may contain multiple devices you would use the Lifx.Device interface Lifx.Device.set_color(device, %Lifx.Protocol.HSBK{}, duration) where device is Lifx.Device

lifx's People

Contributors

axelson avatar brianmay avatar dependabot-preview[bot] avatar entone avatar iyzana 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.