简体   繁体   English

Python MQTT 发布者不发布

[英]Python MQTT publisher doesn't publish

Trying to publish some data from a raspberry pi, but nothing gets through.试图从树莓派发布一些数据,但没有通过。 However, publishing via MQTT.fx works fine.但是,通过 MQTT.fx 发布可以正常工作。 This is my python script:这是我的 python 脚本:

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".这可能很重要:在 MQTT.fx 中,我无法连接,除非导航到“SSL/TLS”,在“启用 SSL/TLS”旁边打叉,然后在“CA 签名服务器证书”旁边打叉”。

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. publish.single不需要任何mqtt.Client()东西。 It is designed to to EVERYTHING in a single function call.它设计用于在单个 function 调用中处理所有内容。

publish.single() takes options for everything. publish.single()接受所有选项。 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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM