Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions mqtt-pub/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,13 @@
KEEP_ALIVE_INTERVAL = 45


def on_connect(client, userdata, rc):
if rc != 0:
def on_connect(mqttc, obj, flags, reason_code, properties):
if reason_code != 0:
print("Unable to connect to MQTT Broker...")
else:
print("Connected with MQTT Broker: ", str(MQTT_BROKER))


def on_publish(client, userdata, mid):
pass


def on_disconnect(client, userdata, rc):
pass


# faking
def prepare_data():
# return "100"
Expand All @@ -57,10 +49,8 @@ def publish_fake_data():
threading.Timer(3.0, publish_fake_data).start()
publish_now(prepare_data())

mqttc = mqtt.Client()
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
mqttc.on_connect = on_connect
mqttc.on_disconnect = on_disconnect
mqttc.on_publish = on_publish

try:
mqttc.connect(MQTT_BROKER, int(MQTT_PORT), int(KEEP_ALIVE_INTERVAL))
Expand Down
Loading