我在尝试连接到MQTT服务器时遇到了一个奇怪的问题NODEJS:
如果我连接到MQTT服务器但没有连接,它就会挂起。
如果我使用命令行执行此操作,我会看到数据,因此网络、服务器等都很好。
如果我使用错误的端口,那么命令行会给我一个有效的拒绝消息,但 NODE 只是挂起。
命令行是:
mosquitto_sub -h 10.10.10.30 -p 1883 -t sim
Run Code Online (Sandbox Code Playgroud)
我的代码是完全基本的:
var mqtt = require('mqtt');
var MQTT_TOPIC = "sim";
var MQTT_ADDR = "10.10.10.30";
var MQTT_PORT = 1883;
var client = mqtt.connect({host: MQTT_ADDR, port : MQTT_PORT, debug: true});
client.on('connect', function() {
console.log('Connected');
client.subscribe(MQTT_TOPIC, function() {
client.on('message', function(topic, message, packet) {
console.log(topic + ": '" + message);
});
});
});
Run Code Online (Sandbox Code Playgroud) 我试图通过TLS 确保arduino pubsub客户端和mosquitto代理(在公共服务器上运行)之间的连接.
通常(在Windows等),我可以在给出证书文件的同时发布/订阅如下.(证书和密钥文件在我的工作目录中).
mosquitto_pub -h myhost.com -p 8883 -t "/test" -m "your secure message" --cafile ca.crt --cert client.crt --key client.key
mosquitto_sub -h myhost.com -p 8883 -t "/test" --cafile ca.crt --cert client.crt --key client.key
但有没有办法在arduino中做到这一点?
由于我在 Ubuntu 16.04 上更新了 Mosquitto v2.0.3,用户无法连接到代理。
\n当我尝试运行/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf它时,抛出以下消息。\n2020-12-22|12:37:02: Error: Unable to write pid file.
我看到有人有同样的问题,所以我添加了pid_file /var/run/mosquitto/mosquitto.pid 了 mosquitto 配置,但问题并没有消失。
我有这个/lib/systemd/system/mosquitto.service:
[Unit]\nDescription=Mosquitto MQTT Broker\nDocumentation=man:mosquitto.conf(5) man:mosquitto(8)\nAfter=network.target\nWants=network.target\n\n[Service]\nType=notify\nNotifyAccess=main\nExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf\nExecReload=/bin/kill -HUP $MAINPID\nRestart=on-failure\nExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto\nExecStartPre=/bin/chown mosquitto: /var/log/mosquitto\nExecStartPre=/bin/mkdir -m 740 -p /var/run/mosquitto\nExecStartPre=/bin/chown mosquitto: /var/run/mosquitto\n\n[Install]\nWantedBy=multi-user.target\nRun Code Online (Sandbox Code Playgroud)\nmosquitto.conf 文件配置为:
\n# Place your local configuration in /etc/mosquitto/conf.d/\n#\n# A full description of the configuration file is at\n# /usr/share/doc/mosquitto/examples/mosquitto.conf.example\n\npid_file /var/run/mosquitto/mosquitto.pid\n\npersistence true\npersistence_location /var/lib/mosquitto/\n\nlog_dest file /var/log/mosquitto/mosquitto.log\n\ninclude_dir /etc/mosquitto/conf.d\n\nlistener 1883\n\nlog_type error\nlog_type …Run Code Online (Sandbox Code Playgroud) static String[] meandgroup = new String[]{"timentask/c/u000000000005", "timentask/c/u0000000GRP85", "timentask/c/u000000GRP107", "timentask/c/u0000000GRP84", "timentask/c/u000000GRP100"};
public static List<MqttClient> mqttConnect(Object topicId) {
try {
mqttClient = new ArrayList<MqttClient>();
for (int i = 0; i < meandgroup.length; i++) {
//if (mqttClient.get(i) == null || !mqttClient.get(i).isConnected()){
if (!globalData.GlobalDataSetGet.MQTT_SERVER_HOST_NAME.equals("") && !globalData.GlobalDataSetGet.MQTT_SERVER_USER_NAME.equals("")) {
String topicName = meandgroup[i];
mqttClient.add(MqttMgr.subscriber(globalData.GlobalDataSetGet.MQTT_SERVER_HOST_NAME,
globalData.GlobalDataSetGet.MQTT_SERVER_PORT_NUMBER, globalData.GlobalDataSetGet.MQTT_SERVER_USER_NAME,
globalData.GlobalDataSetGet.MQTT_SERVER_USER_PASSWORD, Constants.MQTT_CONNECTION_KEEP_ALIVE_SECS, topicName, "client" + globalData.GlobalDataSetGet.getUserIdValue, new ChatPaneWrite()));
}
}
} catch (MqttException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return mqttClient;
}
Run Code Online (Sandbox Code Playgroud) 我想恢复 MQTT 消息发布时间戳,但在订阅者库中找不到支持。另一方面,我看到 MQTT.fx 客户端能够恢复此信息。有谁知道如何处理?

我有一个在Ubuntu 16.04中运行的MQTT代理。我的问题是,在代理运行时如何添加用户?当我使用添加用户时
mosquitto_passwd -c /etc/mosquito/pwfile user2
Run Code Online (Sandbox Code Playgroud)
该用户确实显示在pwfile中,但是直到重新启动代理后,我才能从外部源访问该用户。我尝试使用
sudo mosquitto -c /etc/mosquitto/mosquitto.conf
Run Code Online (Sandbox Code Playgroud)
重新加载mosquitto.conf文件,但出现此错误
1483102542: Config loaded from /etc/mosquitto/mosquitto.conf.
1483102542: Opening ipv4 listen socket on port 1883.
1483102542: Error: Address already in use
Run Code Online (Sandbox Code Playgroud)
因此,我该怎么做才能将用户添加到代理中并在不重新启动代理的情况下加载它们呢?访问)
我一直在尝试进行 4 点透视变换,以便开始进行一些 OCR。
从下图开始,我可以检测到车牌号
并用绿色框作为边界框和红点作为我想要方形的矩形的角来裁剪它。
这是变换的输出。
乍一看,似乎已经完成了由内而外的变换(将部件取到两侧而不是点之间)。
我使用的是imutils包做转换和从工作这个和这个作为指导。我确定这是我缺少的相对简单的东西。
#!/usr/bin/python
import numpy as np
import cv2
import imutils
from imutils import contours
from imutils.perspective import four_point_transform
img = cv2.imread("sample7-smaller.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blurred = cv2.bilateralFilter(gray,15,75,75)
v = np.median(blurred)
lower = int(max(0, (1.0 - 0.33) * v))
upper = int(min(255, (1.0 + 0.33) * v))
edged = cv2.Canny(blurred, lower, upper, 255)
conts = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
conts = conts[0] if imutils.is_cv2() else conts[1]
conts = sorted(conts, …Run Code Online (Sandbox Code Playgroud) 我有一个在 IBM BlueMix 上运行的用 Python 编写的烧瓶服务器。我希望此服务器侦听 MQTT 通道并在收到消息时发布消息。我有以下代码,但从未调用过 on_connect 和 on_message。
app = Flask(__name__)
def on_connect(client):
client.publish(topic2, "CONNECTED")
def on_message(client, userdata, msg):
client.publish(topic2, "MESSAGE")
@app.route('/')
def hello_world():
return 'Hello World! I am running on port ' + str(port)
if __name__ == '__main__':
client = mqtt.Client()
client.username_pw_set(username, password)
client.on_connect = on_connect
client.on_message = on_message
client.connect('broker.example.com')
client.subscribe(topic)
client.publish(topic2, "STARTING SERVER")
app.run(host='0.0.0.0', port=port)
Run Code Online (Sandbox Code Playgroud)
我试过 client.loop 和 client.loop_forever 但它不起作用。
编辑:client.publish(topic2, "STARTING SERVER") 正在工作,我的凭据被删除。
我是 MQTT 的新手,遇到了一个令人沮丧的问题。
我一直在使用 MQTT.fx 订阅主题;我已经设置了:

这很有效,但是我想使用 mosquitto_sub。我正在尝试通过以下方式订阅同一主题:
mosquitto_sub -h host -p 8883 -t topic -i client id
Run Code Online (Sandbox Code Playgroud)
这对我不起作用。我在 Ubuntu VM 上使用它。
我的观察力告诉我应该启用 TLS,但是我不太确定如何做到这一点,我已经塞满了证书并以多种方式启用了 TLS,但没有得到正确的组合。我知道这是必需的,就像我取消选中 MQTT.fx 中的 SSL/TLS 框一样,我无法连接。
我真的很想用 mosquitto 复制我在 MQTT.fx 中的内容。
我正在尝试使用MQTT-Client Framework实现一个 MQTT 客户端。我想确保我尝试发布的每条消息都会到达代理。我无法弄清楚 QOS2 的确切含义:它指出一条消息将只发送一次。是不是意味着当连接丢失时,它会在重新连接后自动尝试重传消息?或者这应该由应用程序处理?
同样在这个库中,重新连接是默认自动完成的吗?或者需要检查connectionLost是否发生,然后尝试重新连接?