python - RaspberryPi 零 W Paho-mqtt 无法与本地主机一起使用
问题描述
我刚刚设置了我的 rpi 零 w。我一直在尝试使以下脚本正常工作。该脚本在我的 rpi 3B 中确实有效,但由于某种原因它不适用于零 w。当我连接到除“localhost”之外的任何其他地址时,该脚本确实有效。
脚本:
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe("help/hi")
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("localhost", 1883, 60)
client.loop_forever()
我得到的错误是:
Traceback (most recent call last):
File "sample_client.py", line 19, in <module>
client.connect("localhost", 1883, 60)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 768, in connect
return self.reconnect()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 895, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File "/usr/lib/python2.7/socket.py", line 575, in create_connection
raise err
socket.error: [Errno 111] Connection refused
当我改变localhost
它的iot.eclipse.org
工作。知道会发生什么吗?还有什么我需要安装的吗?
更多细节:
Python 2.7.13
内容pip show paho-mqtt
:
Name: paho-mqtt
Version: 1.3.1
Summary: MQTT version 3.1.1 client class
Home-page: http://eclipse.org/paho
Author: Roger Light
Author-email: roger@atchoo.org
License: Eclipse Public License v1.0 / Eclipse Distribution License v1.0
Location: /usr/local/lib/python2.7/dist-packages
Requires:
拉斯比版本:
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
解决方案
推荐阅读
- spring - 使用存储库启动应用程序时出错 - IllegalAccessError: class com.acme.$Proxy53 cannot access its superinterface com.acme.UserRepository
- php - SQL 时区问题
- parameters - 如何将名称和值传递给 VueJS 函数?
- javascript - D3强制有向图点击事件不起作用
- javascript - 使用 JavaScript 模仿占位符行为
- r - gganimate 在将地图保持为背景的同时放大数据不起作用
- sql - 创建 volatile 表并在一个请求中对其进行查询(使用 teradata sql 助手)
- javascript - 突出显示字符串对象内的字符串元素
- javascript - 命名动态创建的 javascript 类型
- symfony - 如何在不使用防火墙的情况下添加/激活 AuthenticationProvider?