getsenic / nuimo-linux-python Goto Github PK
View Code? Open in Web Editor NEWNuimo Python SDK for Linux to connect and communicate with Nuimo controllers made by Senic
Home Page: https://senic.com
License: MIT License
Nuimo Python SDK for Linux to connect and communicate with Nuimo controllers made by Senic
Home Page: https://senic.com
License: MIT License
Hi,
did you ever get it running on a raspberry pi 1?
The discover_characteristics part hangs here.
Interestingly enough, the raspberry pi demo script you provided here https://github.com/getsenic/nuimo-raspberrypi-demo worked fine on the same device..
Jochen
Hi!
The linux sdk is not working on ubuntu 16.04.
The test program fails with the following errors:
$ sudo PYTHONPATH=./nuimo python examples/test.py started discovery Traceback (most recent call last): File "examples/test.py", line 92, in <module> main() File "examples/test.py", line 29, in main nuimo_manager.start_discovery() File "/home/dominik/workspace_other/nuimo-linux-python/nuimo/nuimo.py", line 324, in start_discovery self.nuimos = self.create_nuimos(all_discovered_devices) File "/home/dominik/workspace_other/nuimo-linux-python/nuimo/nuimo.py", line 338, in create_nuimos return [NuimoController(device) for device in self.filter_nuimos(devices)] File "/home/dominik/workspace_other/nuimo-linux-python/nuimo/nuimo.py", line 335, in filter_nuimos return [addr for addr, attrs in devices.items() if attrs.get('name') == 'Nuimo'] AttributeError: 'str' object has no attribute 'get'
Python is installed from the default sources (2.7.12), the sdk was installed as specified in the Readme with pygattlib from the specified sources.
The issue appears to be this:
issue 27
If pygattlib is installed from https://bitbucket.org/OscarAcena/pygattlib everything works fine.
The fix: diff
Hi Lars,
just upgraded to 0.24 via pip3....-U.
Now, nuimoctl throws an error:
volumio@volumio:~$ sudo nuimoctl --discover
Traceback (most recent call last):
File "/usr/local/bin/nuimoctl", line 9, in
load_entry_point('nuimo==0.2.4', 'console_scripts', 'nuimoctl')()
File "/usr/local/lib/python3.4/dist-packages/nuimoctl.py", line 108, in main
controller_manager = nuimo.ControllerManager(adapter_name=args.adapter)
File "/usr/local/lib/python3.4/dist-packages/nuimo/nuimo.py", line 18, in init
super().init(adapter_name)
TypeError: object.init() takes no parameters
I've restarted the bluetooth daemon but did not change the outcome.
Do I have to restart the whole system?
Jochen
Installing pygattlib using the install.sh script fails on a raspberry pi 1.
The bluetooth setup was successful and tests with the gatttool as well.
The original nuimo-raspberrypi-demo project also worked on the same pi.
pi@raspberrypi:~/nuimo-linux-python $ sh examples/install.sh pygattlib
Installing Pygattlib and dependencies
+ sudo apt-get install pkg-config libboost-python-dev libboost-thread-dev libbluetooth-dev libglib2.0-dev python-dev
Paketlisten werden gelesen... Fertig
Abhängigkeitsbaum wird aufgebaut.
Statusinformationen werden eingelesen.... Fertig
libboost-python-dev ist schon die neueste Version.
libboost-thread-dev ist schon die neueste Version.
libglib2.0-dev ist schon die neueste Version.
pkg-config ist schon die neueste Version.
python-dev ist schon die neueste Version.
libbluetooth-dev ist schon die neueste Version.
0 aktualisiert, 0 neu installiert, 0 zu entfernen und 0 nicht aktualisiert.
+ [ ! -d pygattlib ]
+ cd pygattlib
+ sudo python setup.py install
running install
running bdist_egg
running egg_info
creating gattlib.egg-info
writing gattlib.egg-info/PKG-INFO
writing top-level names to gattlib.egg-info/top_level.txt
writing dependency_links to gattlib.egg-info/dependency_links.txt
writing manifest file 'gattlib.egg-info/SOURCES.txt'
reading manifest file 'gattlib.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'gattlib.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv6l/egg
running install_lib
running build_ext
building 'gattlib' extension
creating build
creating build/temp.linux-armv6l-2.7
creating build/temp.linux-armv6l-2.7/src
creating build/temp.linux-armv6l-2.7/src/bluez
creating build/temp.linux-armv6l-2.7/src/bluez/lib
creating build/temp.linux-armv6l-2.7/src/bluez/attrib
creating build/temp.linux-armv6l-2.7/src/bluez/src
creating build/temp.linux-armv6l-2.7/src/bluez/src/shared
creating build/temp.linux-armv6l-2.7/src/bluez/btio
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -DVERSION="5.25" -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -Isrc/bluez -I/usr/include/python2.7 -c src/gattservices.cpp -o build/temp.linux-armv6l-2.7/src/gattservices.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -DVERSION="5.25" -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -Isrc/bluez -I/usr/include/python2.7 -c src/beacon.cpp -o build/temp.linux-armv6l-2.7/src/beacon.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -DVERSION="5.25" -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -Isrc/bluez -I/usr/include/python2.7 -c src/bindings.cpp -o build/temp.linux-armv6l-2.7/src/bindings.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
arm-linux-gnueabihf-gcc: internal compiler error: Getötet (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.9/README.Bugs> for instructions.
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 4
pi@raspberrypi:~/nuimo-linux-python $
Traceback:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/dbus/connection.py", line 230, in maybe_handle_message
self._handler(*args, **kwargs)
File "/srv/senic_hub/venv/lib/python3.4/site-packages/gatt/gatt_linux.py", line 152, in _interfaces_added
self._device_discovered(path, interfaces)
File "/srv/senic_hub/venv/lib/python3.4/site-packages/gatt/gatt_linux.py", line 166, in _device_discovered
self.device_discovered(device)
File "/srv/senic_hub/venv/lib/python3.4/site-packages/nuimo/nuimo.py", line 49, in device_discovered
self.listener.controller_discovered(device)
File "/srv/senic_hub/venv/lib/python3.4/site-packages/senic_hub/backend/nuimo_setup.py", line 89, in controller_discovered
self._controller.connect()
File "/srv/senic_hub/venv/lib/python3.4/site-packages/nuimo/nuimo.py", line 125, in connect
super().connect()
File "/srv/senic_hub/venv/lib/python3.4/site-packages/gatt/gatt_linux.py", line 253, in connect
self._connect()
File "/srv/senic_hub/venv/lib/python3.4/site-packages/gatt/gatt_linux.py", line 270, in _connect
self._connect()
File "/srv/senic_hub/venv/lib/python3.4/site-packages/gatt/gatt_linux.py", line 270, in _connect
self._connect()
File "/srv/senic_hub/venv/lib/python3.4/site-packages/gatt/gatt_linux.py", line 270, in _connect
self._connect()
File "/srv/senic_hub/venv/lib/python3.4/site-packages/gatt/gatt_linux.py", line 270, in _connect
self._connect()
File "/srv/senic_hub/venv/lib/python3.4/site-packages/gatt/gatt_linux.py", line 276, in _connect
self.connect_failed(_error_from_dbus_error(e))
File "/srv/senic_hub/venv/lib/python3.4/site-packages/nuimo/nuimo.py", line 132, in connect_failed
super.connect_failed(error)
AttributeError: type object 'super' has no attribute 'connect_failed'
It would be nice to add the possibility of completely deactivating FLY events so that the user cannot mistakenly enter the "fly over" mode which consumes much battery and (in my tests) also seems to make the recognition of other events (especially SWIPE_UP and SWIPE_DOWN) more inaccurate. I already had the case that visitors mistakenly entered the "fly over" mode which caused a little bit of confusion ("Why is there suddenly a LED blinking?", "Now swiping UP/DOWN does not really work anymore", ...).
I think for many use cases the "fly over" mode is not really necessary (e.g. if the Nuimo is used as a wall switch) and for those, it would be cool to have the option completely deactivating it. So I'd suggest:
Of course even more sophisticated would be if the developer has complete control if and when "fly over" mode is activated.
sudo nuimoctl --discover ERROR:dbus.connection:Unable to set arguments ({'Transport': 'le', 'UUIDs': ['f29b1525-cb19-40f3-be5c-7241ecb82fd2', 'f29b1523-cb19-40f3-be5c-7241ecb82fd1', '00001801-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', '0000180f-0000-1000-8000-00805f9b34fb']},) according to signature None: <class 'TypeError'>: Expected a string or unicode object Traceback (most recent call last): File "/usr/local/bin/nuimoctl", line 9, in <module> load_entry_point('nuimo==0.3.2', 'console_scripts', 'nuimoctl')() File "/usr/local/lib/python3.4/dist-packages/nuimoctl.py", line 112, in main controller_manager.start_discovery() File "/usr/local/lib/python3.4/dist-packages/nuimo/nuimo.py", line 35, in start_discovery super().start_discovery(service_uuids=Controller.SERVICE_UUIDS) File "/usr/local/lib/python3.4/dist-packages/gatt/gatt_linux.py", line 128, in start_discovery self._adapter.SetDiscoveryFilter(discovery_filter) File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 70, in __call__ return self._proxy_method(*args, **keywords) File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 145, in __call__ **keywords) File "/usr/lib/python3/dist-packages/dbus/connection.py", line 641, in call_blocking message.append(signature=signature, *args) TypeError: Expected a string or unicode object
I am using a raspberry pi. Discovery and connecting with blueZ works like a charm. My Pi runs the stated BlueZ 5.44.
Home Assistant is using nuimo-linux-python at https://github.com/getsenic/nuimo-linux-python/tree/29fc42987f74d8090d0e2382e8f248ff5990b8c9 (Dec 2016)
We would like to switch to a pypi version. Where there backwards incompatible changes since then or should 0.3.6 from pypi work?
The readme shows the following commands to install pygattlib:
sh examples/test.py pygattlib # For Python 2.x
sh examples/test.py py3gattlib # For Python 3.x
while it probably should be
sh examples/install.sh pygattlib
sh examples/install.sh py3gattlib
Hi Lars,
I've followed your guide to upgrade bluez from 5,23 to 5.43 closely but it is not working correctly for me.
I'm on a raspberry pi 3 with the integrated bluetooth module and started out with a clean install of raspbian lite (image from January 2017).
Initially, bluez 5,23 is already installed and the bluetoothctl command shows the controller itself and discovers the nuimo just fine. Then, I carried out the bluez upgrade steps and immediately after, everything is still ok. Nuimo can be disovered etc.
However, after a "sudo reboot", bluetooth is not working anymore. The MAC address of the bluetooth controller is set to AA:AA:AA:AA:AA:AA and also the discovery is not working.
pi@raspberrypi:~ $ sudo bluetoothctl
[NEW] Controller AA:AA:AA:AA:AA:AA raspberrypi [default]
pi@raspberrypi:~ $ sudo hciconfig -a
hci0: Type: Primary Bus: UART
BD Address: AA:AA:AA:AA:AA:AA ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING
RX bytes:1496 acl:0 sco:0 events:160 errors:0
TX bytes:2624 acl:0 sco:0 commands:142 errors:0
Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH SNIFF
Link mode: SLAVE ACCEPT
Name: 'raspberrypi'
Class: 0x000000
Service Classes: Unspecified
Device Class: Miscellaneous,
HCI Version: 4.1 (0x7) Revision: 0x0
LMP Version: 4.1 (0x7) Subversion: 0x2209
Manufacturer: Broadcom Corporation (15)
I've tried this procedure twice - once on the raspbian lite and once in a volumio installation which is my actual target system.
Any hints?
Jochen
I've tested this library with BlueZ 4.44 and the LED matrix gets updated with according method calls. However, when using BlueZ 5.50 the LED matrix won't get updated. I've switched forth and back between both versions and could reliably reproduce this bug. This said, BlueZ 5.50 (and maybe even prior versions) are not yet recommended to use. I suspect the bug in this library's dependency at https://github.com/getsenic/gatt-python.
Hi Lars,
how can several matrix displays be displayed after another?
Before the 0.1.0 release I had something like this in place:
self.controller.write_matrix(MyNuimoDelegate.DOTMATRIX_STRINGS['RASPBERRY'], duration)
time.sleep(1)
self.controller.write_matrix(MyNuimoDelegate.DOTMATRIX_STRINGS['HI'], duration)
time.sleep(1)
self.controller.write_matrix(MyNuimoDelegate.DOTMATRIX_STRINGS['JO'], duration)
where duration is 3 (seconds). This worked. Each "image" was displayed for a little while before the next one.
Now I have this:
nuimoController.display_matrix(nuimo.LedMatrix(self.DOTMATRIX_STRINGS['RASPBERRY']), duration, brightness, fading)
time.sleep(1)
nuimoController.display_matrix(nuimo.LedMatrix(self.DOTMATRIX_STRINGS['HI']), duration, brightness, fading)
time.sleep(1)
nuimoController.display_matrix(nuimo.LedMatrix(self.DOTMATRIX_STRINGS['JO']), duration, brightness, fading)
with duration = 3.0 , brightness=1.0 and fading = true.
I would expect the 3 images to be displayed 3 seconds each as before. However, I can only see the first one which immediately blends over to the last one which equally quickly disappears.
So it seems that the duration parameter is not working properly.
What am I doing wrong?
Thanks
Jochen
EDIT: it was an error regarding to the iOS simulator. Now I'm using a real nuimo and everything works.
TypeError: list indices must be integers, not str
This occurs in swipe_event and rotation_event.
Traceback (most recent call last):
File "/home/naimo/nuimo-linux-python/examples/nuimo.py", line 247, in on_notification
event = self.event_factory(data, uuid)
File "/home/naimo/nuimo-linux-python/examples/nuimo.py", line 256, in event_factory
event = item['constructor'](received_data)
File "/home/naimo/nuimo-linux-python/examples/nuimo.py", line 228, in swipe_event
event_kind = directions[swipe_direction]
A quick fix for me, as a beginner in python, is to rewrite the nuimo.py code to
directions = [NuimoGestureEvent.SWIPE_LEFT, NuimoGestureEvent.SWIPE_RIGHT,
NuimoGestureEvent.SWIPE_UP, NuimoGestureEvent.SWIPE_DOWN]
swipe_direction = "".join(format(ord(c),"02x") for c in received_data[3])
event_kind = directions[int(swipe_direction)]
event = NuimoGestureEvent(event_kind, swipe_direction)
return event
Now it works for about 10 seconds and then nothing happens. No event is received, no error occurs. I have to restart the python script and it works again for this timespan. What am I doing wrong?
Tested with python 2.7 and 3.4 on a Raspberry Pi 3 with the built-in Bluetooth adapter, Nuimo iOS Simulator
I can't get the LED matrix writer to work with my Nuimo. Also the dots.py demo code isn't displaying anything
After debugging the Nuimo code, I found that _matrix_writer.led_matrix_characteristic is None
In the code I see this:
self._matrix_writer.led_matrix_characteristic = next((
characteristic for characteristic in nuimo_service.characteristics
if characteristic.uuid == self.LED_MATRIX_CHARACTERISTIC_UUID), None)
# TODO: Fallback to legacy led matrix service
# This is needed for older Nuimo firmware were the LED characteristic was a separate service)
I've updated the firmware with the iPhone app, but it doesn't change anything.
Is it possible that the firmware is still old even after I updated it with the iPhone app?
Hello yhis is my error:
Nuimo controller C7:BC:F2:F9:48:79 connecting...
Nuimo controller C7:BC:F2:F9:48:79 connect failed: No such property 'ServicesResolved'
In one of the latest versions adapter_name
was moved from Controller
into ControllerManager
Most of the time, it takes 2 or 3 tries, to get the script running. The first error occurs very often.
Python 3.5.0 (default, Sep 14 2016, 20:23:07)
naimo:~ $ sudo python3 /opt/nuimo/examples/test.py
*** Error in `python3': double free or corruption (fasttop): 0x75b016e8 ***
naimo:~ $ sudo python3 /opt/nuimo/examples/test.py
Traceback (most recent call last):
File "/opt/nuimo/examples/test.py", line 55, in <module>
main()
File "/opt/nuimo/examples/test.py", line 27, in main
nuimo.connect()
File "/opt/nuimo/examples/nuimo.py", line 194, in connect
GATTRequester.connect(self, wait=True, channel_type="random")
RuntimeError: Could not update HCI connection: Connection timed out
naimo:~ $ sudo python3 /opt/nuimo/examples/test.py
Displaying LED Matrix...
Waiting for Nuimo events, use CTRL+C to quit
I don't know, if it's related to this problem, but gatttool also has a problem
Connection successful [FA:B7:DD:4A:BE:1B][LE]> characteristics Error: Discover all characteristics failed: Internal application error: I/O [FA:B7:DD:4A:BE:1B][LE]> (gatttool:28989): GLib-CRITICAL **: g_queue_pop_head: assertion 'queue != NULL' failed
or another one
[FA:B7:DD:4A:BE:1B][LE]> connect Attempting to connect to FA:B7:DD:4A:BE:1B Error: connect error: Connection timed out (110)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.