Trying to publish some data from a raspberry pi, but nothing gets through. However, publishing via MQTT.fx works fine. This is my python script:
import paho.mqtt.client as mqtt
import paho.mqtt.publish as publish
publish.single("example_topic", payload="example message", qos=0, retain=False,\
hostname="example.com",port=8883, client_id="random_number", \
keepalive=60, will=None,auth = {'username':"example_username",\
'password':"example_password"}, tls=None, protocol=mqtt.MQTTv311, transport="tcp")
This might be important to know: In MQTT.fx I wasn't able to connect without navigating to "SSL/TLS", making a cross next to "Enable SSL/TLS" and then making a cross next to "CA signed server certificate".
Can someone tell me what I'm doing wrong? :)
You seem to be mixing different things up here. The publish.single
doesn't need any of the mqtt.Client()
stuff. It is designed to to EVERYTHING in a single function call.
publish.single()
takes options for everything. The docs are here
import paho.mqtt.publish as publish
publish.single(topic, payload=None, qos=0, retain=False, hostname="localhost",
port=1883, client_id="", keepalive=60, will=None,
auth={username:"user", password:"pass"}, tls=None,
protocol=mqtt.MQTTv311, transport="tcp")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.