Added basic pairing workflow
This commit is contained in:
parent
c48dfdf1cc
commit
db944fc3c3
1 changed files with 15 additions and 4 deletions
|
@ -1,5 +1,7 @@
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
from dbHelper import MaDbHelper
|
from dbHelper import MaDbHelper
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
class MlmAccess:
|
class MlmAccess:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -29,6 +31,16 @@ class MlmAccess:
|
||||||
|
|
||||||
self.mqtt.loop_forever()
|
self.mqtt.loop_forever()
|
||||||
|
|
||||||
|
def _handleActorPairRequest(self, id):
|
||||||
|
print(f"Pair request for type actor with ID {id}")
|
||||||
|
if not self.db.userExists(id):
|
||||||
|
password = ''.join(random.choices(string.ascii_uppercase + string.digits, k=10))
|
||||||
|
self.db.addUser(f"actor-{id}", password, [f"mlmAccess/actor/{id}/status"], [f"mlmAccess/actor/{id}/action"])
|
||||||
|
|
||||||
|
self.mqtt.publish("mlmAccess/pair/response/actor", password)
|
||||||
|
else:
|
||||||
|
self.mqtt.publish("mlmAccess/pair/response/actor", "")
|
||||||
|
|
||||||
def _mqttOnConnect(self, client, userdata, flags, rc):
|
def _mqttOnConnect(self, client, userdata, flags, rc):
|
||||||
print("Connected with result code "+str(rc))
|
print("Connected with result code "+str(rc))
|
||||||
|
|
||||||
|
@ -38,10 +50,9 @@ class MlmAccess:
|
||||||
print(client.subscribe("mlmAccess/pair/request/actor"))
|
print(client.subscribe("mlmAccess/pair/request/actor"))
|
||||||
|
|
||||||
def _mqttOnMessage(self, client, userdata, message):
|
def _mqttOnMessage(self, client, userdata, message):
|
||||||
print("message received " ,str(message.payload.decode("utf-8")))
|
if message.topic == "mlmAccess/pair/request/actor":
|
||||||
print("message topic=",message.topic)
|
self._handleActorPairRequest(str(message.payload.decode("utf-8")))
|
||||||
print("message qos=",message.qos)
|
|
||||||
print("message retain flag=",message.retain)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue