Git Product home page Git Product logo

timebox's Introduction

Divoom Timebox CLI

Control the divoom timebox using your terminal. Thanks to derHeinz and his divoom-aurabox code for giving some hints on how to interpret the protocol.

Project status

This project is WIP, so not every feature might work as expected yet. Also this tools is communicating with the timebox unidirectional. This means, that no answers from the box will be processed at the moment.

What works

  • Switching "screens" : "clock","temp","anim","graph","image","stopwatch","scoreboard
  • display images, most formats should be supported thanks to pillow. The images will be scaled to fit the 11x11 matrix
  • display animations, either load a series of images from a directory OR a GIF animation. The loaded frames will also be scaled
  • display clock and set 12h/24h format as well as color. There are a dozen of possebilities to describe a color, take a look at colour
  • display temperature set °C/°F as well as the color
  • switch radio on/off
  • setting time

What does not work (or needs improvements)

  • Setting the radios frequency does not yet work
  • animations with a shorter framelength "as usual" (I am about to investigate this) might be "glued together" resulting in two or more animations shown after each other
  • Error handling is bad at the moment, so be careful what you type. The CLI might not inform you about what went wrong yet.
  • Python3 support
  • ... Documentation ;) ...
  • ... No Tests, only tested on my Linux boxes ...

Windows integration

To use this library on Windows, you need to install a version of the pybluez library that contains a fix for getpeername support. A pre-built binary for the library supporting Python 2.7 and AMD64 can be downloaded here.

Future plans

  • split CLI and library
  • support text "rendering" and marquees
  • support everything that could be done using the "original" android app
  • web server providing a timebox api

timebox's People

Contributors

c-w avatar scr4tch 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

timebox's Issues

Host is down

Hi @ScR4tCh ,

I'm using Timebox to show personalized messages or custom images, but I have a problem that has always afflicted me. Every day I have to restart the Timebox at least once, as it no longer allows connections from any device (Mac, Android smartphone or Raspberry)

Issue with timebox itself

Can you prevent it from displaying the Bluetooth logo continuously?

I have succesfully sent images to the Timebox Mini from Raspberry, but then Bluetooth logo comes on and off.

can use for aurabox

as you said it is reference divoom-aurabox project, can it use for aurabox?

Bluetooth icon / how to keep it connected

Hi guys,
to report the issue is the only way how to share some data. I spent a lot of time to solve the issue regarding disconnect just after the command was sent to timebox.

How to solve it.
using bluetoothctl part of bluez package pair and trust your device.

  1. scan on
  2. wait to find the timebox
  3. scan off
  4. pair 00:00:00:00:00 <= mac address of your timebox
  5. trust 00:00:00:00:00 <= mac address of your timebox
  6. quit
  7. each time you want to do permanent connection use command /bin/echo -e "connect 00:00:00:00:00 \nquit | sudo bluetoothctl (instead of 00:00:00... please use mac address of your timebox)

Hope it helps

Error with Timebox mini

When running with a Timebox mini on Ubuntu 18.04.4 and python 3.6:

$ python3 timebox.py --debug --address 11:75:58:xx:xx:xx clock
connecting to 11:75:58:xx:xx:xx
-> ['01', '04', '00', '45', '00', '49', '00', '02']
Traceback (most recent call last):
File "timebox.py", line 546, in
dev, disconnect = cli(sys.argv[1:], obj={})
File "/home/robin/.local/lib/python3.6/site-packages/click/core.py", line 829, in call
return self.main(*args, **kwargs)
File "/home/robin/.local/lib/python3.6/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/robin/.local/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/robin/.local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/robin/.local/lib/python3.6/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/robin/.local/lib/python3.6/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "timebox.py", line 206, in clock
ctx.obj['dev'].send(switch_view("clock"))
File "timebox.py", line 79, in send
ret = [ord(c) for c in self.sock.recv(256)]
File "timebox.py", line 79, in
ret = [ord(c) for c in self.sock.recv(256)]
TypeError: ord() expected string of length 1, but int found

Guide to running on macOS - 10.15 RC & 10.14 (Mojave)

By trial and error (lots of both 🤯) I have now managed to assemble a complete guide for running the timebox CLI on macOS in a virtual enviroment with Python 2.7.

For this guide, I'll just assume that you clone this repository or extract its zip to ~/timebox (/Users/yourusername/timebox). Here we go:

First, check that pip is up to date:

python -m pip install --user --upgrade pip
  1. Install virtualenv. As far as I know, all Macs ship with easy_install, so
sudo easy_install virtualenv
  1. From your home dir:
git clone https://github.com/ScR4tCh/timebox.git 

or extract the zip and copy/move its contents to ~/timebox

cd ~/timebox
  1. Create the virtual enviroment and activate it:
virtualenv ~/timebox // or simply "virtualenv timebox"
source bin/activate
  1. Install (some of) the dependencies
sudo -H pip install -r requirements.txt
cd ~/timebox (cd ..)

Now for the tedious part.

  1. You'll need the "osx" folder from the PyBluez rep later on, so we'll start with cloning it and install the fundamentals.
git clone https://github.com/karulis/pybluez.git
cd pybluez
python setup.py install
  1. (Important!) Use the force and pull off some jedi mind tricks on macOS:
cd ~/timebox 
pip install --upgrade git+https://github.com/karulis/pybluez.git#egg=pybluez
sudo -H cp -R pybluez/osx pybluez/lightblue
sudo -H cp -R pybluez/lightblue lib/python2.7/site-packages/
  1. Clean up (delete the temporary pybluez folder)
rm -R pybluez
  1. Do a quick test to check if Bluetooth is working. Save the following to a new .py file and name it bluetooth-test.py. Run the test with python bluetooth-test.py
# simple inquiry example
import bluetooth
import sys

nearby_devices = bluetooth.discover_devices(lookup_names=True)
print("found %d devices" % len(nearby_devices))

for addr, name in nearby_devices:
    print("  %s - %s" % (addr, name))

If there's no error messages, and you are presented a Bluetooth device status report, Bluetooth and Python 2 are now best friends, and you are hereby a certified Jedi. The rest is in the help function and the README (Thanks! @ScR4tCh )

Example:

cd timebox
python timebox.py clock --color #FF0000

Hope this helps anyone. I'm off to see where I can take this further 🙂

Best regards,

Andreas

Notifications

Would it be possible to somehow get the notifications also to display? The biggest thing missing right now.
As it is only connected to the Linux and not to a phone at the same time, we would need to catch social media notifications from internet.
After this is would be pretty easy script to send a pre made (social media)picture for a given time to the timebox.

MacOS Support

I was playing around with MacOS, hopefully this helps someone or me in the future.

git clone https://github.com/ScR4tCh/timebox.git
cd timebox
virtualenv env
source env/bin/activate
pip install pyobjc
pip install git+https://github.com/0-1-0/lightblue-0.4.git
pip install git+https://github.com/karulis/pybluez.git
pip install -r requirements.txt 

You'll need to change the source a bit:

    self.addr, _ = self.sock.getpeername()

to

	self.addr, _ = self.sock.getsockname()

Disconnect the timebox and make sure it's waiting for a pairing.

python timebox/timebox.py settime now

I got these errors randomly when installing/uninstalling lightblue and pybluez, I had to fiddle around installing/reinstalling them until it worked.

  • AttributeError: 'module' object has no attribute 'setSignatureForSelector'
  • ImportError: Cannot load LightAquaBlue framework:

At some point, this folder got created:

/env/lib/python2.7/site-packages/lightblue/LightAquaBlue.framework/

A popup will come up asking you to pair with the Timebox, meanwhile the script will error out so you need to kill the shell and start over.

cd timebox
source env/bin/activate
python timebox/timebox.py settime now

It will show a error, but it will work!

(env) MarkBookPro:timebox marko$ python timebox/timebox.py settime now
-checking device 11:75:58:D8:91:51
2018-04-17 10:44:25.455 python[2601:273300] [establishKernelConnection] Received an error from IOServiceOpen() - 0xe00002c7.  NULLing out io_service_t.

Brightness to max combined with view type "off" = Full color view

From what I can understand, the view type "off" (0x02) is the same as "Full color (spectrum) light" in the app, except the brightness is set to 0 in the header somehow.

From the README in https://github.com/derHeinz/divoom-adapter:

Following static byte array can be sent to show bright, dark and to deactivate display: 01 04 00 32 3f 75 00 02, 01 04 00 32 d2 08 03 04 02, 01 04 00 32 00 36 00 02

I added the following code (just out of curiousity), and it actually worked:

@cli.command(short_help='display full color light')
@click.option('--color', nargs=1)
@click.pass_context
def fullcolor(ctx, color):
    if (color):
        c = color_convert(Color(color).get_rgb())
        ctx.obj['dev'].send(set_full_color(c[0], c[1], c[2], 0xff))
    else:
        ctx.obj['dev'].send(set_full_color(0xff, 0xff, 0xff, 0xff))

def set_full_color(r, g, b, x):
    head = [0x09, 0x00, 0x45, 0x02, 0xFF]
    s = sum(head) + sum([r, g, b, x])
    ck1, ck2 = checksum(s)

    # create message mask 0x01,0x02,0x03
    msg = [0x01] + mask(head) + mask([r, g, b, x]) + mask([ck1, ck2]) + [0x02]

    return msg

Well, it ALMOST worked - because there's some odd offset somewhere in the rgb/hex conversion that I don't quite understand, so that's for someone else to find out, I guess.
If you pass the raw hex data to set full brightness (according to derHeinz) while in this view:

python timebox.py raw "01040032d208030402" 
  • you'll see that the "--color" argument works, although there's something weird going on with my message mask.

Additional information about commands

(creating an issue, because I do not another way to communicate.)
Thanks for the information and the code on your page.
I have also been trying to decode the communications between the app and the Timebox.
Below some of my findings that might be interesting.

command structure

  • After removal of the 0x01 head and 0x02 tail and checksum and after unmasking, the bare command remains.
  • All commands (both to and from the Timebox) start with the command length, coded in two bytes, LSB first. For example, in the command to view the clock: 04 00 45 00, The initial bytes 04 00 indicate the command length (4)
  • The command length is followed by one byte indicating the actual command (45, switch view in the example)
  • The remainder of the command depends on the main command (00=clock in the example) and sometimes has optional extensions (such as specifying the color of the clock)
  • The responses from the Timebox have a similar structure. They start with the two byte command length. The third byte has as far as I have observed always the value 0x04. The fourth byte is the command number. The fifth byte seems always 0x55, command dependent data follows after the fifth byte
  • Responses are typically returned after commands to the Timebox with the same command, followed by 55, possibly followed by additional information. For instance, when some information was requested from the Timebox such as the current radio frequency. Or without additional information as an acknowledgement.
  • The response to a malformed command is a negative acknowledgement of the form XX AA, where XX is the command number that was erroneous.
  • The initial communication from the Timebox does not follow the usual structure. It is always 00 05 48 45 4C 4C 4F 00 (which spells 'HELLO')

command list

Some of the known commands:

  • 0x05 Turn radio on/off
    Followed by 0x00 = off, or 0x01 = on.
  • 0x08 Set volume
    Followed by the volume between 0x00 and 0x10.
  • 0x09 Get current volume
  • 0x0a Set mute state
    Followed by 0x00 = mute, or 0x01 = unmute.
  • 0x0b Get mute state
  • 0x18 Set date and time
    Followed by year (last two digits), year (first two digits), month, day, hours, minutes, seconds, and another number hundredths?
  • 0x44 Set static image
  • 0x45 Set view
  • 0x49 Set image in an animation
  • 0x59 Get temperature
  • 0x60 Get current radio frequency
    Returns two bytes XX YY, which represent the frequency YX.X MHz, for instance, 0x03 0x0a represents 100.3Mhz.
  • 0x61 Set radio frequency
    Uses the same encoding of the frequency

Instructions unclear

Hi!
Sorry for the noob question, but could somebody explain to me how to use this?

I just need some basic guidelines, like how to figure out how to use the commands and the such.

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.