Git Product home page Git Product logo

pythonwifibulb's Introduction

PythonWifiBulb

A python script and class for controlling "MagicLight Wifi Smart LED Light Bulbs" without the use of the mobile app.

Note

I had been developing this library myself by reverse engineering the network traffic using Wireshark. Only recently I found Danielhiversen/flux_led which serves the same purposes of this library, but with a more complete implementation. I would recommend using this library instead, since it is more complete.

That being said, I'm glad I could use this more complete library as a way to check my work. We came across many of the same magic numbers and structures of the message contents.

Usage

Your bulb must be connected to your local network, as set up inside the app. You can get the bulb's IP address from inside the app.

CLI Example

Bulb color can be set via the command line by specifying the IP address, and the red, green, and blue components of the color you wish to set.

python3 WifiBulb.py 192.168.x.x 255 0 0

Code Example

A test usage can be seen in sampleProgram.py, however here's a brief snippet:

# import the class
from WifiBulb import WifiBulb

# create a new object and assign it's IP address
IP = "192.168.x.x"
myLightBulb = WifiBulb(IP)

# connect to the bulb
myLightBulb.connect()

# send it some colors
myLightBulb.setColor((255, 0, 0))

# disconnect when finished
myLightBulb.disconnect()

What type of Wifi enabled lightbulbs work?

So far I've used this with these bulbs: Magic Light Wifi Smart Light Bulb. I have used two versions of these bulbs, but they both worked with the same Android app. They list themselves as v5 and v7. As far as I know, as long as they work with the MagicLight app, they should work with this.

Notes on Packet Structure

I used wireshark to capture packets being sent to the bulbs from my phone. I set up an access point on my laptop, connected both my phone and the bulb to it, and listened for all traffic between them on that interface.

The app would send TCP packets on ports 5577, and 55649. It seemed port 5577 was used for incoming traffic on the bulb.

Here's a sample of what the data in a packet may look like: 31FF00FF00F00FXX31FF00FF00F00FXX31FF00FF00F00FXX31FF00FF00F00FXX

Note that this data is repeated. It appears that if the connection is slow, more data will be appended.

RGB Color

This data represents a single message to the bulb to change it to a specified RGB color. 31FF00FF00F00FXX

  • '31' I'm not certain what this does. When using a color-picking function in the app, all messages begin with this. When using a preset, the 31 is missing from the messages.

  • 'FF00FF' is the color. In this case #FF00FF (purple).

  • '00F00F' are some "magic bytes". I don't know what they do, but they never changed in this pattern, so I wasn't concerned about it.

  • 'XX' is the checksum value.

"Warm" white color

The bulb contains RGB leds as well as some white leds that give a warmer color than what the RGB leds can produce.

A "warm white" color message looks like this: 31000000ff0f0fXX

Again, we see '31', no idea. I'm guessing '000000' indicates and RGB value of 0, since we aren't using RGB color. 'ff' is the brightness, from 0-255 in hex. '0f0f' are magic bytes. 'XX' is the checksum value.

_sendmessage

I've included a method with WifiLight that will automatically add the checksum at the end of your message, and then will send it. It can be used for testing patterns easily, without dealing with checksum values.

# sends that data, with checksum at the end
# I *think* this was for some pattern I haven't recognized yet
bulb._sendmessage("31ffc39200f00f")

pythonwifibulb's People

Contributors

chris-johnston avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pythonwifibulb's Issues

Color setting doesn't work

Hi there, I've tried copying the samples and creating my own bulb.setColor's but they wont change the color of the light(s). It says it connects properly and I dont get any error logs but the colors only change to white when it first connects

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.