Leiaz/python-awox-mesh-light

EGLO Connect Salobrena C - AWOX Chipset - control via gatttool

Opened this issue ยท 7 comments

Hi,

I bought an EGLO Connect Salobrena C LED Panel with AWOX Chipset. I can run your scripts and set the different colors and adjust brightness from commandline. Works fine but is very slow, so I tried to set the values by gatttool, but this doesn't work.

A few examples:

Lamp turned off via mylight.off()

write commands from hcidump

ATT: Write cmd (0x52)
  handle 0x001b value  0x0c 0xbe 0x63 0x12 0x58 0x8d 0x3d 0xd4 0xec 0x1a 0x5d 0x64 0x3d 0x6d 0x66 0x00 0x42
handle 0x001b value  0cbe6312588d3dd4ec1a5d643d6d660042

ATT: Write cmd (0x52)
  handle 0x0012 value  0x00
handle 0x0012 value  00

ATT: Write cmd (0x52)
  handle 0x0015 value  0xcd 0x9c 0x4c 0x7f 0x40 0x5a 0xb4 0xec 0xbd 0xb8 0x0a 0x88 0xda 0xb9 0xff 0xa1 0x64 0xec 0x57 0xa3
handle 0x0015 value  cd9c4c7f405ab4ecbdb80a88dab9ffa164ec57a3
[XX:XX:XX:XX:XX:XX][LE]> connect
Attempting to connect to XX:XX:XX:XX:XX:XX
Connection successful
[XX:XX:XX:XX:XX:XX][LE]> char-read-hnd 0x0012
Characteristic value/descriptor: 00
[XX:XX:XX:XX:XX:XX][LE]>

Lamp turned on via mylight.on()

write commands from hcidump

ATT: Write cmd (0x52)
  handle 0x001b value  0x0c 0x1c 0x28 0xe3 0x09 0x4b 0xb5 0x36 0xef 0x3f 0x96 0x25 0xc9 0x14 0xe3 0x37 0x39
handle 0x001b value  0c1c28e3094bb536ef3f9625c914e33739

ATT: Write cmd (0x52)
  handle 0x0012 value  0x01
handle 0x0012 value  01

ATT: Write cmd (0x52)
  handle 0x0015 value  0xf0 0x6d 0x0a 0x6c 0x19 0xd4 0x69 0x03 0x6c 0xd1 0xe4 0x48 0x6f 0x20 0xbc 0x02 0x64 0x4f 0x3b 0xc4
handle 0x0015 value  f06d0a6c19d469036cd1e4486f20bc02644f3bc4
[XX:XX:XX:XX:XX:XX][LE]> connect
Attempting to connect to XX:XX:XX:XX:XX:XX
Connection successful
[XX:XX:XX:XX:XX:XX][LE]> char-read-hnd 0x0012
Characteristic value/descriptor: 01
[XX:XX:XX:XX:XX:XX][LE]>

So this seems to work, the values are set when lamp is on or off. Next i tried to turn on the Panel from gatttool.

[XX:XX:XX:XX:XX:XX][LE]> char-write-req 0x0012 01
Characteristic value was written successfully
[XX:XX:XX:XX:XX:XX][LE]>

I think this should turn on the lamp, but nothing happens, same with following command.

[XX:XX:XX:XX:XX:XX][LE]> char-write-cmd 0x0012 01

Am I missing something? I don't know if i have to set the other values like "0x001b" and "0x0015" before and/or after setting the ON value.

Can someone please point me into the right direction? ๐Ÿ˜•

THX

Leiaz commented

I think this should turn on the lamp

If your panel works like the light bulb, it doesn't work this way. The device doesn't have a "on/off characteristic" that you can write to. It has a "command" characteristic to which you send command messages crafted specifically for it. In the on function in my __init__.py, the writeCommand used is the one defined above. You can see how the command message is built in make_command_packet in packetutils.py. It is really not convenient to write the commands manually with gattools.

Do you stay connected to the panel between commands ? Connecting can be slow, so if you have a "on" script that does mylight.connect() mylight.on() mylight.disconnect() and same for off that could be the reason.

Hi, thanks for replying ๐Ÿ˜Š

I tried several ways to connect to the Panel, connection is fine but if i try to write values, they are not accepted by the panel. Maybe that's because the lack of authentication from bluez tools.

I try to implement the AWOX Panel into homebridge for use with homekit. Primary goal is to control the panel via HomeKit and set the states (on, off) and change color via HomeKit colorpicker. For now it works with scripts that are called when an action in HomeKit is triggered, but the colorpicker doesn't work.

Tried to use your scripts directly from nodejs, but no luck. I will try to port your code to nodejs so that anyone can use this in homebridge and/or HomeKit.

Leiaz commented

Ok. I don't know homebridge but don't hesitate to ask if there is something you don't understand about my code.

Do you stay connected to the panel between commands ? Connecting can be slow, so if you have a "on" script that does mylight.connect() mylight.on() mylight.disconnect() and same for off that could be the reason.

Tried that, but i can't declare mylight as global var inside my python webservice. This is my first try with python and that's what i have so far

from flask import Flask,request,session,redirect,jsonify
from traceback import format_exc
import awoxmeshlight
import logging
import time
import struct
import os
import sys
import json
import atexit
import logging

logger = logging.getLogger (__name__)
app = Flask(__name__)

@app.route('/awox', methods=['GET', 'POST'])
def GET():
	action = request.args.get('action')
	value= request.args.get('value')
        if action == 'on':
          mylight.on()
        elif action == 'off':
          mylight.off()
        else:
          print('nothing to do')

def start_awox_service():
	print('starting service')
	mylight.connect()
		
def stop_awox_service():
	print('stopping service')
	mylight.disconnect()
	
# Register the function to be called on exit
atexit.register(stop_awox_service)
	
if __name__ == '__main__':
	app.secret_key = '1111122222333334444455555'
	mylight = awoxmeshlight.AwoxMeshLight("XX:XX:XX:XX:XX:XX", "MyLamp", "0000")
	start_awox_service()
	app.run(debug=True,host='0.0.0.0', port=3000)	

Starting:

 starting service
 mesh_name value : MyLamp
 mesh_password value : 0000
 Connected.
  * Serving Flask app "awox" (lazy loading)
  * Environment: production
    WARNING: Do not use the development server in a production environment.
    Use a production WSGI server instead.
  * Debug mode: on
  * Running on http://0.0.0.0:3000/ (Press CTRL+C to quit)
  * Restarting with stat
  * Debugger is active!
  * Debugger PIN: xxx-xxx-xxx

Trigger a command from webservice:

127.0.0.1 - - [12/Feb/2019 16:16:23] "GET /awox?action=state&value=0 HTTP/1.1" 200 -

mylight.off()
File "/usr/local/lib/python2.7/dist-packages/awoxmeshlight/__init__.py", line 290, in off
  self.writeCommand (C_POWER, b'\x00')
File "/usr/local/lib/python2.7/dist-packages/awoxmeshlight/__init__.py", line 211, in writeCommand
  assert (self.session_key)
AssertionError

Using the service with this code works great, but connecting is slow and i have to connect everytime i want to change values.

@app.route('/awox', methods=['GET', 'POST'])
def GET():
	action = request.args.get('action')
	value= request.args.get('value')
        if action == 'on':
          mylight.connect()
          mylight.on()
          mylight.disconnect()
        elif action == 'off':
          mylight.connect()
          mylight.off()
          mylight.disconnect()
        else:
          print('nothing to do')

Looks like an error in Connection State. mylight.on connects to the Panel, but I can't use mylight commands in further context to set colors or brightness. Maybe is missed something, like i said, this is my first python script, would be great if you can help me ๐Ÿ˜ž

Thx

Leiaz commented

If mylight.session_key doesn't exist, it means connect failed or did not happen. I don't know Flask except for what I just read about it, but a web server can spawn new threads or processes to answer requests, so you can't just use a "global" mylight like that.

I'd say you need to have just one thread (or process) that connect and talks to the light. The other part of your app (other threads, where you get the commands from users) send messages to this thread to control the light.

You could also try using the logger to view debug messages.

rzr commented

hi, for whoever care,

I implemented also a REST API to control the light using mozilla webthing API ,
then I was able to make this demo:

https://purl.org/rzr/weboftwins

Please let me know if EGLO is also compatible with it

Hi, thanks for replying ๐Ÿ˜Š

I tried several ways to connect to the Panel, connection is fine but if i try to write values, they are not accepted by the panel. Maybe that's because the lack of authentication from bluez tools.

I try to implement the AWOX Panel into homebridge for use with homekit. Primary goal is to control the panel via HomeKit and set the states (on, off) and change color via HomeKit colorpicker. For now it works with scripts that are called when an action in HomeKit is triggered, but the colorpicker doesn't work.

Tried to use your scripts directly from nodejs, but no luck. I will try to port your code to nodejs so that anyone can use this in homebridge and/or HomeKit.

So did you manage to make it working for HomeKit?