Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions config/test-bluetooth_signal.json
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",
Copy link
Member

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

"in": [],
"out": ["signalStrength"]
Copy link
Member

Choose a reason for hiding this comment

The 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 signal

}
},
"links": []
}
}
58 changes: 58 additions & 0 deletions subt/bluetooth_signal.py
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)
Copy link
Member

Choose a reason for hiding this comment

The 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. bluetoothscan