-
Notifications
You must be signed in to change notification settings - Fork 12
bluetooth detector for subt #940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "version": 2, | ||
| "robot": { | ||
| "modules": { | ||
| "wifi": { | ||
| "driver": "subt.bluetooth_signal:Bluetooth_signal", | ||
| "in": [], | ||
| "out": ["signalStrength"] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here on the other hand I would use only small letters with underscores ... and again maybe just shorter |
||
| } | ||
| }, | ||
| "links": [] | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #!/usr/bin/env python3 | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
| Created on Mon Sep 13 20:14:48 2021 | ||
|
|
||
| @author: linux-mint | ||
| """ | ||
|
|
||
| import subprocess | ||
|
|
||
| from osgar.node import Node | ||
|
|
||
|
|
||
| def bluetooth_scan(): | ||
| while True: | ||
| with subprocess.Popen('hcitool scan', shell=True, stdout=subprocess.PIPE) as data: | ||
| for line in data.stdout: | ||
| line = line.decode() | ||
| if "CubeArtifact" in line: | ||
| #print(line) | ||
| device = line.split()[0] | ||
| print(device) | ||
| signalStrength = bluetooth_rssi_scan(device) | ||
| return signalStrength | ||
|
|
||
|
|
||
| def bluetooth_rssi_scan(device): | ||
| rssi_find = True | ||
| while rssi_find: | ||
| with subprocess.Popen('bluetoothctl scan on', shell=True, stdout=subprocess.PIPE) as data: | ||
| for line in data.stdout: | ||
| line = line.decode() | ||
| #print(line) | ||
| if device in line: | ||
| if "RSSI: " in line: | ||
| mac_adress = line.split()[2] | ||
| if mac_adress in device: | ||
| rssi_find = False | ||
| signalStrength = line.split("RSSI: ")[1] | ||
| try: | ||
| signalStrength = int(signalStrength) | ||
| print(signalStrength) | ||
| return signalStrength | ||
| except "e": | ||
| pass | ||
| #print(e) | ||
|
|
||
|
|
||
| class Bluetooth_signal(Node): | ||
| def __init__(self, config, bus): | ||
| super().__init__(config, bus) | ||
| bus.register('bluetoothscan') | ||
|
|
||
| def run(self): | ||
| while self.is_bus_alive(): | ||
| signalStrength = bluetooth_scan() | ||
| now = self.publish("bluetoothscan", signalStrength) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the name in configuration should correspond to your registered (and published) name, i.e. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the class name should be CamelCase, i.e. BluetoothSignal ... and I would maybe just use shorter version
bluetooth:Bluetooth