我正在尝试从运行在我的raspberry pi上的Paho库发布到运行在windows机器上的nodejs服务器上的moscamqtt代理,但没有发生任何事情 那么问题是什么 注意:当我从nodejs客户机连接到代理时,它可以工作 这是我的nodejs代码
var mosca = require('mosca');
var settings = {
port: 1883
};
//here we start mosca
var server = new mosca.Server(settings);
server.on('ready', setup);
// fired when the mqtt server is ready
function setup() {
console.log('Mosca server is up and running');
}
// fired whena client is connected
server.on('clientConnected', function(client) {
console.log('client connected', client.id);
});
// fired when a message is received
server.on('published', function(packet, client) {
console.log('Published : ', packet.payload);
});
// fired when a client subscribes to a topic
server.on('subscribed', function(topic, client) {
console.log('subscribed : ', topic);
});
// fired when a client subscribes to a topic
server.on('unsubscribed', function(topic, client) {
console.log('unsubscribed : ', topic);
});
// fired when a client is disconnecting
server.on('clientDisconnecting', function(client) {
console.log('clientDisconnecting : ', client.id);
});
// fired when a client is disconnected
server.on('clientDisconnected', function(client) {
console.log('clientDisconnected : ', client.id);
});
// this is my client request
var mqtt = require('mqtt');
client = mqtt.connect('mqtt://192.168.10.99:1883');
client.subscribe('presence');
console.log('Client publishing.. ');
client.publish('presence', 'Client 1 is alive.. Test Ping! ' + Date());
client.end();
这是运行在我的raspberry pi上的python代码
^{pr2}$我的python错误是:
sudo python clientpaho.py
Traceback (most recent call last):
File "clientpaho.py", line 40, in <module>
mqttc.loop_forever()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1481, in loop_forever
rc = self.loop(timeout, max_packets)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1003, in loop
rc = self.loop_read(max_packets)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1284, in loop_read
rc = self._packet_read()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1849, in _packet_read
rc = self._packet_handle()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2311, in _packet_handle
return self._handle_connack()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2372, in _handle_connack
self.on_connect(self, self._userdata, flags_dict, result)
TypeError: on_connect() takes exactly 3 arguments (4 given)
最后,这是我解决的问题:
Paho客户端无法连接到nodejs==>;在windows上禁用防火墙
由在连接函数上引起的错误它需要4个参数而不是像这样的3个参数
on_connect(self, self._userdata, flags_dict, result)
谢谢你
相关问题 更多 >
编程相关推荐