Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple python example using paho #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions scripts/sup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import paho.mqtt.client as mqtt
import ssl
import re

client = mqtt.Client()

MQTT_HOST = 'localhost'

client.tls_set('/etc/ssl/private/ca.crt',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by convention, the ca cert is in /etc/ssl/certs/ not /etc/ssl/private

certfile='/etc/ssl/certs/localhost.crt',
keyfile='/etc/ssl/private/localhost.ckey',
cert_reqs=ssl.CERT_REQUIRED,
tls_version=ssl.PROTOCOL_TLSv1)


def on_message(client, userdata, message):
if re.match(r'^sup?', message.lower()):
client.publish('not much.')


def on_connect(client, userdata, flags, rc):
client.subscribe("#")
client.publish('Hello mqtt')


client.on_connect = on_connect
client.on_message = on_message

client.connect(MQTT_HOST)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to specify port 8883 here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client.connect(MQTT_HOST,8883) seems to not error out.