Support for commands handling
This commit is contained in:
+5
-5
@@ -2,23 +2,22 @@ import time
|
||||
from interruptingcow import timeout
|
||||
|
||||
from mqtt import MqttMessage
|
||||
from workers.base import BaseWorker
|
||||
|
||||
REQUIREMENTS = ['bluepy']
|
||||
|
||||
|
||||
# Bluepy might need special settings
|
||||
# sudo setcap 'cap_net_raw,cap_net_admin+eip' /usr/local/lib/python3.6/dist-packages/bluepy/bluepy-helper
|
||||
|
||||
class MiscaleWorker():
|
||||
def __init__(self, mac):
|
||||
self._mac = mac
|
||||
|
||||
class MiscaleWorker(BaseWorker):
|
||||
def status_update(self):
|
||||
return [MqttMessage(topic='weight/kg', payload=self._get_weight())]
|
||||
|
||||
def _get_weight(self):
|
||||
from bluepy import btle
|
||||
|
||||
scan_processor = ScanProcessor(self._mac)
|
||||
scan_processor = ScanProcessor(self.mac)
|
||||
scanner = btle.Scanner().withDelegate(scan_processor)
|
||||
scanner.scan(5, passive=True)
|
||||
|
||||
@@ -29,6 +28,7 @@ class MiscaleWorker():
|
||||
|
||||
return -1
|
||||
|
||||
|
||||
class ScanProcessor():
|
||||
def __init__(self, mac):
|
||||
self._mac = mac
|
||||
|
||||
Reference in New Issue
Block a user