-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-firmware-version.py
47 lines (36 loc) · 1.43 KB
/
get-firmware-version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import sys
import time
import uuid
import Adafruit_BluefruitLE
from Adafruit_BluefruitLE.services import DeviceInformation
# Get the BLE provider for the current platform.
ble = Adafruit_BluefruitLE.get_provider()
def main(nuimo_uuid):
print nuimo_uuid
# Clear previously received data from the controller/adapter
ble.clear_cached_data()
# Connect to the default or first adapter and start scan
adapter = ble.get_default_adapter()
adapter.power_on()
adapter.start_scan()
# It needs bit of time to scan the devices. Some Peripherals advertise in different
time.sleep(2)
# Find all the ble devices with the name nuimo,this filtering part is done by Adafruit
# devices -> interfaces/device/bluez-device, properties and method can be found there
# id is MAC on Linux and on OSX uuid generated by OSX
devices = ble.find_devices()
for device in devices:
print('Found device: {0}, id: {1}'.format(device.name, device.id))
if device.id == uuid.UUID(nuimo_uuid):
device.connect()
DeviceInformation.discover(device)
dis = DeviceInformation(device)
print('Firmware Revision: {0}'.format(dis.fw_revision))
device.disconnect()
adapter.power_off()
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Please enter UUID of Nuimo")
sys.exit()
ble.initialize()
ble.run_mainloop_with(main(sys.argv[1]))