为什么我的Arduino无法连接到我的Mosca经纪人?
我正在学习MQTT,并将开源mosca代理部署到azure web应用程序中。问题是代理在2台电脑之间工作,但当我尝试将arduino nano连接到代理时,总是失败。这是我的服务器代码:为什么我的Arduino无法连接到我的Mosca经纪人?,arduino,mqtt,azure-web-app-service,broker,mosca,Arduino,Mqtt,Azure Web App Service,Broker,Mosca,我正在学习MQTT,并将开源mosca代理部署到azure web应用程序中。问题是代理在2台电脑之间工作,但当我尝试将arduino nano连接到代理时,总是失败。这是我的服务器代码: //Mosca const mosca = require('mosca') const settings = { http: { // port for websockets, MQTT is running in default port 1883 port: 8000, b
//Mosca
const mosca = require('mosca')
const settings = {
http: {
// port for websockets, MQTT is running in default port 1883
port: 8000,
bundle: true,
static: './public'
}
}
// start mosca
const moscaServer = new mosca.Server(settings)
moscaServer.on('ready', setup)
// fired when the mqtt server is ready
function setup() {
console.log('Mosca server is up and running in port 1883!')
console.log('Using port 8000 for MQTT over Web-Sockets!')
}
// fired when a client is connected
moscaServer.on('clientConnected', function(client) {
console.log('client connected', client.id)
})
// fired when a message is received
moscaServer.on('published', function(packet, client) {
//if (packet.topic == '/example') {
console.log(packet.payload.toString('utf-8'))
//}
})
// fired when a client subscribes to a topic
moscaServer.on('subscribed', function(topic, client) {
console.log('subscribed : ', topic)
})
// fired when a client unsubscribes to a topic
moscaServer.on('unsubscribed', function(topic, client) {
console.log('unsubscribed : ', topic)
})
// fired when a client is disconnecting
moscaServer.on('clientDisconnecting', function(client) {
console.log('clientDisconnecting : ', client.id)
})
// fired when a client is disconnected
moscaServer.on('clientDisconnected', function(client) {
console.log('clientDisconnected : ', client.id)
})
从Azure应用程序服务WebApp站点-默认情况下,应用程序服务假定您的自定义容器正在侦听端口80。如果您的容器侦听不同的端口,请在应用程序服务应用程序中设置网站\端口应用程序设置 通过已经公开的HTTP(80)和HTTPS(443)TCP端口,可以通过internet访问WebApp 应用程序服务当前只允许容器为HTTP请求公开一个端口。 我对-MQTT代理不太确定。还有,你到底是如何尝试连接的 从应用程序服务-Docker Compose选项中,请签出受支持和不受支持的配置。 •只能打开一个容器进行访问 •仅可访问端口80和8080(暴露端口) 详情请参阅
注意:Linux应用程序上支持Web套接字。如果你说这在PC上工作,为什么你认为mosca代码出错而不是Arduino中运行的代码?是的,hardilib说的。哪个代码有错误?发布代码!告诉我们“总是失败”到底是什么意思?什么错误?有错误代码吗?它怎么会失败?!?