Code Monkey home page Code Monkey logo

ledenet_api's Introduction

ledenet_api

An API for the LEDENET Magic UFO LED WiFi Controller

What's this?

This RGB LED controller is a relatively cheap (~$30) alternative to something like the Phillips Hue RGB Strip + Hub, which can run you between $100 and $200.

However, it doesn't come with an open API, and doesn't integrate with smarthome hubs (SmartThings, etc.). I used a packet capture app on my phone to reverse engineer how the official app communicated with the controller.

Installing

ledenet_api is available on Rubygems. You can install it with:

$ gem install ledenet_api

You can also add it to your Gemfile:

gem 'ledenet_api'

Using it

In addition to the Ruby API, this gem also comes bundled with an executable named ledenet-ufo.

Commandline

Here's the --help message:

$ ledenet-ufo
  Usage: ledenet-ufo --list
     OR: ledenet-ufo [IP|HW ADDR] [OPTIONS]

    -r, --red [VALUE]                Set red to VALUE
    -g, --green [VALUE]              Set green to VALUE
    -b, --blue [VALUE]               Set blue to VALUE
    -w, --warm-white [VALUE]         Set warm white to VALUE
        --on                         Turn on the controller
        --off                        Turn off the controller
    -l, --list                       Prints a list of available devices and exits
    -s, --status                     Prints status as JSON
    -h, --help                       Prints this help message
        --function-id [VALUE]        Set function id to VALUE
    -f, --function [VALUE]           Set function to VALUE.

When using it, you can specify the IP address, hardware (mac) address, or let ledenet_api choose an arbitrary device on the local network (this would work well if you only have one).

Examples:

List available devices

$ ledenet-ufo --list
      IP ADDRESS         HW ADDRESS              Model #
    10.133.8.113       XXXXXXXXXXXX      HF-LPB100-ZJ200

Get current status

$ ledenet-ufo --status
{"is_on":true,"red":"255","green":"255","blue":"255","warm_white":"255","running_function?":false,"speed":61,"speed_packet_value":"12","function_name":"NO_FUNCTION","function_id":"97"}

Turn on, adjust colors

$ ledenet-ufo --on -r 200 -g 0 -b 255 --warm-white 0 --status
{"is_on":true,"red":"200","green":"0","blue":"255","warm_white":"0","running_function?":false,"speed":99,"speed_packet_value":"0","function_name":"NO_FUNCTION","function_id":"97"}

Turn off

$ ledenet-ufo --off

Set function

$ ledenet-ufo --speed 60 --function seven_color_cross_fade --status
{"is_on":true,"red":"255","green":"0","blue":"0","warm_white":"255","running_function?":true,"speed":61,"speed_packet_value":"12","function_name":"SEVEN_COLOR_CROSS_FADE","function_id":"37"}

Ruby API

Device discovery

These devices implement a service discovery protocol, which allows you to find them on your network without digging for their IP address. To use it:

require 'ledenet_api'
devices = LEDENET.discover_devices
=> [#<LEDENET::Device:0x007feccc0241d8 @ip="10.133.8.113", @hw_addr="XXXXXXXXXXXX", @model="HF-LPB100-ZJ200">]
devices.first.ip
=> "10.133.8.113"

By deafult, discover_devices waits for up to 5 seconds for a single device to respond, and returns immediately after finding one. To change this behavior:

irb(main):005:0> LEDENET.discover_devices(expected_devices: 2, timeout: 1)
=> [#<LEDENET::Device:0x007fff328f4330 @ip="10.133.8.113", @hw_addr="XXXXXXXXXXXX", @model="HF-LPB100-ZJ200">]

API

To construct an API class, use the following:

api = LEDENET::Api.new('10.133.8.113')

By default, each API call will open a new connection, and close it when it's finished. This is convenient if the API is being used inside of a long-running process (like a web server). If what you're doing is more short-lived, you can reuse the same connection:

api = LEDENET::Api.new('10.133.8.113', reuse_connection: true)

By default, the API will re-try transient-looking failures three times. You can change this behavior with:

api = LEDENET::Api.new('10.133.8.113', reuse_connection: true, max_retries: 0)

Status

To check if the controller is currently on:

api.on?
=> false

To turn the controller on and off:

api.on
api.off

Color / Warm White

To get the current color settings:

api.current_color_data
#=> {:red=>255, :green=>255, :blue=>255, :warm_white=>255}
api.current_rgb
#=> [255, 255, 255]
api.current_warm_white
#=> 255

To set the color:

api.update_rgb(255, 0, 255)

api.update_warm_white(100)

You can also update individual parameters:

api.update_color_data(red: 100)

api.update_color_data(blue: 255, warm_white: 0)

Functions

The UFO devices ship with 20 pre-programmed lighting functions. ledenet_api has support for these:

LEDENET::Functions.all_functions
#=> [:SEVEN_COLOR_CROSS_FADE, :RED_GRADUAL_CHANGE, :GREEN_GRADUAL_CHANGE, :BLUE_GRADUAL_CHANGE, :YELLOW_GRADUAL_CHANGE, :CYAN_GRADUAL_CHANGE, :PURPLE_GRADUAL_CHANGE, :WHITE_GRADUAL_CHANGE, :RED_GREEN_CROSS_FADE, :RED_BLUE_CROSS_FADE, :SEVEN_COLOR_STROBE_FLASH, :RED_STROBE_FLASH, :GREEN_STROBE_FLASH, :BLUE_STROBE_FLASH, :YELLOW_STROBE_FLASH, :CYAN_STROBE_FLASH, :PURPLE_STROBE_FLASH, :WHITE_STROBE_FLASH, :SEVEN_COLOR_JUMPING_CHANGE, :GREEN_BLUE_CROSS_FADE]
api.update_function(:seven_color_cross_fade)
api.update_function_speed(100) #very fast

api.update_function_data(
  function_id: LEDENET::Functions::BLUE_GREEN_CROSS_FADE,
  speed: 50
)

To quit the function and return to a constant color, simply update a color value:

api.update_color_data(warm_white: 255)

ledenet_api's People

Contributors

sidoh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ledenet_api's Issues

No available devices

Hi.

Just came across this awesome hack and tested it. Changing colors by passing on the IP works fine.
Just wonder why it wont discover any devices it self?

ledenet-ufo --list
Gives me an empty list.

As far as i can tell, (shows in the original MagicHome App), i have the UFO controller version 3.
A little packet sniffing on the phone, shows that it communicates via TCP on port 5577 if that matters.

BTW: Anyone figured the username/password for the ufo controllers web interface?
(Its not admin/nimda anymore)

Error: undefined method `ip' for nil:NilClass

OR "Error: Invalid argument"
I'm not a ruby guy, more of a JavaScript/PHP guy. So I'm not too excited to dig deeper here...
but it seems there is a simple semantic error for most of the commands.

The only thing that works (works great!) is --on and --off. Everything else results in a syntax error.

ledenet-ufo 192.168.29.148 --status

Error: Invalid argument

C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bindata-2.4.0/lib/bindata/io.rb:31:in pos' C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bindata-2.4.0/lib/bindata/io.rb:31:in seekable?'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bindata-2.4.0/lib/bindata/io.rb:23:in initialize' C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bindata-2.4.0/lib/bindata/io.rb:240:in initialize'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bindata-2.4.0/lib/bindata/base.rb:143:in new' C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bindata-2.4.0/lib/bindata/base.rb:143:in read'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bindata-2.4.0/lib/bindata/base.rb:21:in read' C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ledenet_api-1.4.2/lib/ledenet/api.rb:116:in block in send_packet'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ledenet_api-1.4.2/lib/ledenet/api.rb:142:in socket_action' C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ledenet_api-1.4.2/lib/ledenet/api.rb:112:in send_packet'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ledenet_api-1.4.2/lib/ledenet/api.rb:130:in request_status' C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ledenet_api-1.4.2/lib/ledenet/api.rb:20:in status'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ledenet_api-1.4.2/bin/ledenet-ufo:156:in <top (required)>' C:/Ruby22-x64/bin/ledenet-ufo:23:in load'
C:/Ruby22-x64/bin/ledenet-ufo:23:in <main>

PS C:\Users\Noah\downloads> ledenet-ufo --on -r 200 -g 0 -b 255 --warm-white 0 --status

Error: undefined method `ip' for nil:NilClass

C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ledenet_api-1.4.2/bin/ledenet-ufo:130:in <top (required)>' C:/Ruby22-x64/bin/ledenet-ufo:23:in load'
C:/Ruby22-x64/bin/ledenet-ufo:23:in <main>

Any ideas? :-)

(using window 10 and Ruby 2.2 and also tried with 2.3.x )

Can't get API to change the colour

Hi sidoh,

Thanks for your hard work - I was halfway through reverse engineering it myself before I found yours!

I'm trying to get this API to work with my LED device. I can get it to turn on and off, and to give full status readouts, but for the life of me I can't get it to update the colour of the LEDs. I've tried from the command line and from inside a script.

Is there anything you can suggest that I might try? I'd be very grateful for any insight you might have.

Many thanks,

James

Http control Ufo

Dear is see you have hacked the ufo rgbw controller..
Great job!!!!

I wil try to use this controller for my Home automation, Domoticz.
Is there perhaps a option that i can use your way with Http commands?
Domoticz can use the Http commands directly...
Or perhaps a script, domoticz can work with different types.

I did install the ledenet api, only now i am stuc.
Did install it on my RPi.

How can i use the api on a simple way.
I do not understand where i can place/put the api [ in putty is get strange values ]
Perhaps you have some examples, of your nice work

I am not ict expert... :-(
Hope you will help me with your nice hack...
I do not have a Ufo j@ this moment [ orderd 2 ] only i will learn before i got 1...

Thanks!!

Control WW(WarmWhite) interface

The RGB section is working perfectly, do you still plan on adding the WW control section? To turn on the WarmWhite is string.char(113) string.char(35) string.char (148) and to turn off is string.char(113) string.char(35) string.char(149)

Turn off 0x71, 0x24, 0x95

Turn on 0x71, 0x23, 0x94

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.