1#!/usr/local/bin/python3.8 2# -*- coding: utf-8 -*- 3 4# Copyright (c) 2016 James Myatt <james@jamesmyatt.co.uk> 5# 6# All rights reserved. This program and the accompanying materials 7# are made available under the terms of the Eclipse Distribution License v1.0 8# which accompanies this distribution. 9# 10# The Eclipse Distribution License is available at 11# http://www.eclipse.org/org/documents/edl-v10.php. 12# 13# Contributors: 14# James Myatt - initial implementation 15 16# This shows a simple example of standard logging with an MQTT subscriber client. 17 18import context # Ensures paho is in PYTHONPATH 19import paho.mqtt.client as mqtt 20 21import logging 22logging.basicConfig(level=logging.DEBUG) 23 24# If you want to use a specific client id, use 25# mqttc = mqtt.Client("client-id") 26# but note that the client id must be unique on the broker. Leaving the client 27# id parameter empty will generate a random id for you. 28mqttc = mqtt.Client() 29 30logger = logging.getLogger(__name__) 31mqttc.enable_logger(logger) 32 33mqttc.connect("mqtt.eclipse.org", 1883, 60) 34mqttc.subscribe("$SYS/#", 0) 35 36mqttc.loop_forever() 37