test: enable mosquitto password auth; add mqttping endpoint; use credentials in subscriber; publish defaults
This commit is contained in:
@@ -6,6 +6,8 @@ import paho.mqtt.client as mqtt
|
||||
|
||||
broker = os.getenv('MQTT_BROKER', 'localhost:1883')
|
||||
topic = os.getenv('MQTT_TOPIC', 'lambdaiot')
|
||||
username = os.getenv('MQTT_USERNAME')
|
||||
password = os.getenv('MQTT_PASSWORD')
|
||||
|
||||
if broker.startswith('tcp://'):
|
||||
broker = broker[len('tcp://'):]
|
||||
@@ -28,6 +30,8 @@ def on_message(client, userdata, msg):
|
||||
client = mqtt.Client()
|
||||
client.on_connect = on_connect
|
||||
client.on_message = on_message
|
||||
if username:
|
||||
client.username_pw_set(username, password)
|
||||
|
||||
try:
|
||||
client.connect(host, port, 60)
|
||||
|
||||
Reference in New Issue
Block a user