command check - fix subscriber
This commit is contained in:
32
wallet_api/mqtt.py
Normal file
32
wallet_api/mqtt.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
MQTT_SERVER="10.211.114.214"
|
||||
MQTT_PORT=1883
|
||||
MQTT_KEEPALIVE=60
|
||||
MQTT_USER="pippo"
|
||||
MQTT_PASSWORD="batt1l0"
|
||||
MQTT_DS_TOPIC="$CONTROL/dynamic-security/v1"
|
||||
|
||||
def on_connect(mqtt_client, userdata, flags, rc, properties):
|
||||
if rc == 0:
|
||||
print('Connected successfully. Properties:', properties)
|
||||
mqtt_client.subscribe(MQTT_TOPIC)
|
||||
else:
|
||||
print('Bad connection. Code:', rc)
|
||||
|
||||
def on_disconnect(mqtt_client, obj, flags, rc, properties):
|
||||
print('disconnected. Code:', rc)
|
||||
|
||||
def on_message(mqtt_client, userdata, msg):
|
||||
print(f'Received message on topic: {msg.topic} with payload: {msg.payload}')
|
||||
|
||||
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, protocol=mqtt.MQTTv5)
|
||||
client.on_connect = on_connect
|
||||
client.on_disconnect = on_disconnect
|
||||
client.on_message = on_message
|
||||
client.username_pw_set(MQTT_USER, MQTT_PASSWORD)
|
||||
client.connect(
|
||||
host=MQTT_SERVER,
|
||||
port=MQTT_PORT,
|
||||
keepalive=MQTT_KEEPALIVE
|
||||
)
|
||||
Reference in New Issue
Block a user