- Add Dockerfile

- Add Config in backend using env vars
- Clean up mock actor
This commit is contained in:
Dorian Zedler 2021-08-19 11:27:39 +02:00
parent cbffbc92a6
commit b6f8b54bc2
Signed by: dozedler
GPG key ID: 989DE36109AFA354
9 changed files with 121 additions and 36 deletions

View file

@ -3,7 +3,7 @@ import logging, coloredlogs
coloredlogs.install(level='INFO', fmt='%(asctime)s - [%(levelname)s] %(message)s')
PAIR_ID = "106"
PAIR_ID = "101"
def on_connect(client, userdata, flags, rc):
global PAIR_ID

View file

@ -1,28 +1,36 @@
import paho.mqtt.client as mqtt
import logging, coloredlogs
coloredlogs.install(level='INFO', fmt='%(asctime)s - [%(levelname)s] %(message)s')
ACTOR_ID = "101"
ACTOR_PASSWORD = "MgUiSW1dloFt9TVKJM5E"
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
print("Subscribing to topic","mlmAccess/pair/response/actor")
print(client.subscribe("mlmAccess/actor/102/action"))
print("Publishing message to topic","mlmAccess/pair/request/actor")
print(client.publish("mlmAccess/actor/102/status", "0", retain=True))
global ACTOR_ID
if rc != 0:
logging.error(f"Error connecting to MQTT broker: {rc}")
return
logging.info("Successfully connected to MQTT broker")
client.subscribe(f"mlmAccess/actor/{ACTOR_ID}/action")
client.publish(f"mlmAccess/actor/{ACTOR_ID}/status", "0", retain=True)
def on_message(client, userdata, message):
print("message received " ,str(message.payload.decode("utf-8")))
print("message topic=",message.topic)
print("message qos=",message.qos)
print("message retain flag=",message.retain)
messageContent = str(message.payload.decode("utf-8"))
logging.info(f"Got request to perform action: {messageContent}")
# report back action to let the backend know that it was executed successfully
client.publish(f"mlmAccess/actor/{ACTOR_ID}/status", messageContent, retain=True)
client = mqtt.Client(client_id="actor-102")
client.username_pw_set("actor-102", "YWT2JPOEZH")
client = mqtt.Client(client_id=f"actor-{ACTOR_ID}")
client.username_pw_set(f"actor-{ACTOR_ID}", ACTOR_PASSWORD)
client.on_connect = on_connect
client.on_message = on_message
print("connecting to broker")
print(client.connect("localhost", 1883, 60))
logging.info("Initializing MQTT")
client.connect("localhost", 1883, 60)
client.loop_forever()