From 3a898f22bc8da0abc9805673caaa56c46992fad0 Mon Sep 17 00:00:00 2001 From: pTommyed Date: Sat, 25 Sep 2021 06:01:55 +0200 Subject: [PATCH 1/2] config/test-bluetooth_signal.json: config of subt bluetooth scanerA --- config/test-bluetooth_signal.json | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 config/test-bluetooth_signal.json diff --git a/config/test-bluetooth_signal.json b/config/test-bluetooth_signal.json new file mode 100644 index 000000000..895aa0745 --- /dev/null +++ b/config/test-bluetooth_signal.json @@ -0,0 +1,13 @@ +{ + "version": 2, + "robot": { + "modules": { + "wifi": { + "driver": "subt.bluetooth_signal:Bluetooth_signal", + "in": [], + "out": ["signalStrength"] + } + }, + "links": [] + } +} From f3d1cb8505ad65e1d3be66dde2b773e5f179105c Mon Sep 17 00:00:00 2001 From: pTommyed Date: Sat, 25 Sep 2021 06:20:51 +0200 Subject: [PATCH 2/2] subt/bluetooth_signal.py --- subt/bluetooth_signal.py | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 subt/bluetooth_signal.py diff --git a/subt/bluetooth_signal.py b/subt/bluetooth_signal.py new file mode 100644 index 000000000..f786fe5bc --- /dev/null +++ b/subt/bluetooth_signal.py @@ -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) +