Skip to content

Commit 5bb5de4

Browse files
authored
Merge pull request #19 from grunskis/simplify-readme
Describe how to use setuptools to install the SDK
2 parents cf93b0d + ba59957 commit 5bb5de4

File tree

1 file changed

+24
-101
lines changed

1 file changed

+24
-101
lines changed

README.md

Lines changed: 24 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Nuimo Python SDK
22

3+
The **Nuimo** SDK is a single Python source file. It has been tested with Python 2.7 and Python 3.4.
4+
35
## Installation
46
These instructions assume a Debian-based Linux.
57

@@ -51,122 +53,43 @@ sh examples/install.sh scan
5153
```
5254
sh examples/install.sh connect
5355
```
54-
### 2. Install Pygattlib
55-
[Pygattlib](https://bitbucket.org/OscarAcena/pygattlib) is a Python library to use the GATT Protocol for Bluetooth LE devices. It is a wrapper around the implementation used by gatttool in the bluez package. Unlike some other Python Bluetooth libraries, Pygattlib does not need invoke any external programs.
56-
57-
**Known Issues**
58-
Pygattlib may not be reliable on your platform. We are investigating these issues at Senic.
59-
1. The library sometimes appears to get 'stuck', especially when executing `discover_characteristics`.
60-
61-
To install Pygattlib automatically run the following commands. The steps are also described below should you wish to follow them manually.
62-
```
63-
sh examples/install.sh pygattlib # For Python 2.x
64-
sh examples/install.sh py3gattlib # For Python 3.x
65-
```
66-
#### Install the dependencies
67-
1. `sudo apt-get install pkg-config libboost-python-dev libboost-thread-dev libbluetooth-dev libglib2.0-dev python-dev python-setuptools`
68-
69-
#### Installing Pygattlib
70-
1. `hg clone https://bitbucket.org/OscarAcena/pygattlib`
71-
2. `cd pygattlib`
72-
3. `sudo python setup.py install` (Installs **gattlib.so** to **/usr/local/lib/python2.7/dist-packages**)
73-
4. `sudo python3 setup.py install` (Installs **gattlib.cpython-34m.so** and support files to **/usr/local/lib/python3.4/dist-packages/gattlib*.egg**)
74-
75-
### 3. Install Nuimo Python SDK
76-
1. `cp nuimo.py <your project directory> # The Nuimo SDK is a single file`
77-
78-
## Usage
79-
The **Nuimo** SDK is a single Python source file. It has been tested with Python 2.7 and Python 3.4.
80-
81-
#### Testing
82-
To test, run the following command (note that it must be run as root because on Linux, Bluetooth discovery is a restricted operation).
83-
```
84-
sudo PYTHONPATH=. python examples/test.py
85-
```
86-
#### Usage
87-
```python
88-
89-
import time
90-
import sys
91-
from nuimo import NuimoDiscoveryManager
92-
93-
94-
def main():
95-
# Uncomment the next 2 lines to enable detailed logging
96-
# import logging
97-
# logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
98-
99-
# Discover Nuimo Controllers
100-
# Note:
101-
# 1) Discovery is a synchronous operation i.e. other Python activity is paused
102-
# 2) Discovery must be run as the root user
103-
# 3) If the Nuimo MAC address is known, the NuimoController can be instantiated directly.
104-
# For example:
105-
# nuimo = NuimoController('D0:DF:D2:8F:49:B6')
106-
107-
adapter = 'hci0' # Typical bluetooth adapter name
108-
nuimo_manager = NuimoDiscoveryManager(bluetooth_adapter=adapter, delegate=DiscoveryLogger())
109-
nuimo_manager.start_discovery()
110-
111-
# Were any Nuimos found?
112-
if len(nuimo_manager.nuimos) == 0:
113-
print('No Nuimos detected')
114-
sys.exit(0)
115-
116-
# Take the first Nuimo found.
117-
nuimo = nuimo_manager.nuimos[0]
11856

119-
# Set up handling of Nuimo events.
120-
# In this case just log each incoming event.
121-
# NuimoLogger is defined below.
122-
nuimo_event_delegate = NuimoLogger()
123-
nuimo.set_delegate(nuimo_event_delegate)
57+
### 2. Install Nuimo Python SDK
12458

125-
# Attach to the Nuimo.
126-
nuimo.connect()
59+
#### Install the system dependencies
12760

128-
# Display an icon for 2 seconds
129-
interval = 2.0
130-
print("Displaying LED Matrix...")
131-
nuimo.write_matrix(MATRIX_SHUFFLE, interval)
61+
sudo apt-get install build-essential pkg-config libboost-python-dev libboost-thread-dev libbluetooth-dev libglib2.0-dev python-dev python-setuptools`
13262

133-
# Nuimo events are dispatched in the background
134-
time.sleep(100000)
63+
#### Install Nuimo SDK & it's Python dependencies
13564

136-
nuimo.disconnect()
65+
If you're using Python 2.X run:
13766

138-
# Example matrix for the Nuimo display
139-
# Must be 9x9 characters.
140-
MATRIX_SHUFFLE = (
141-
" " +
142-
" " +
143-
" .. .. " +
144-
" . . " +
145-
" . " +
146-
" . . " +
147-
" .. .. " +
148-
" " +
149-
" ")
67+
sudo python setup.py install
15068

69+
If you're using Python 3.X run:
15170

152-
class DiscoveryLogger:
153-
""" Handle Nuimo Discovery callbacks. """
154-
def controller_added(self, nuimo):
155-
print("added Nuimo: {}".format(nuimo))
71+
sudo python3 setup.py install
15672

73+
This will install Nuimo SDK package and it's dependency Gattlib (see
74+
note about Gattlib below) to Python package directory.
15775

158-
class NuimoLogger:
159-
""" Handle Nuimo Controller event callbacks by printing the events. """
76+
#### Running the example script
16077

161-
def received_gesture_event(self, event):
162-
print("received event: name={}, gesture_id={}, value={}".format(event.name, event.gesture, event.value))
163-
164-
if __name__ == '__main__':
165-
main()
78+
To test if your setup is working, run the following command (note that it must be run as root because on Linux, Bluetooth discovery is a restricted operation).
16679

16780
```
81+
sudo python examples/test.py
82+
```
83+
84+
You can find the example script here: [examples/test.py](/examples/test.py)
16885

16986
#### Tested on
17087
1. Raspberry Pi Model 3 - Raspbian Jessie Full (raspberrypi 4.1.18)
17188
2. Linux Mint 17.3 Rosa
17289

90+
### Note about Pygattlib
91+
[Pygattlib](https://bitbucket.org/OscarAcena/pygattlib) is a Python library to use the GATT Protocol for Bluetooth LE devices. It is a wrapper around the implementation used by gatttool in the bluez package. Unlike some other Python Bluetooth libraries, Pygattlib does not need invoke any external programs.
92+
93+
**Known Issues**
94+
Pygattlib may not be reliable on your platform. We are investigating these issues at Senic.
95+
1. The library sometimes appears to get 'stuck', especially when executing `discover_characteristics`.

0 commit comments

Comments
 (0)