2016-10-25 8 views
1

내가 모스카의 MQTT 브로커를 포함하는 명시 응용 프로그램을 만들었습니다 </p> <p>Heroku가

const express = require('express'); 
 
const helmet  = require('helmet'); 
 
const bodyParser = require('body-parser'); 
 
const morgan  = require('morgan'); 
 
const path  = require('path'); 
 
const server  = require('./modules/server'); 
 
const dashboard = require('./modules/dashboard'); 
 
const config = require('./config'); 
 
const routes = require('./routes'); 
 

 
const app = express(); 
 

 
app.use(helmet()); // secure http communication middleware 
 
app.use(bodyParser.urlencoded({ extended: true })); 
 
app.use(bodyParser.json()); 
 
app.use(morgan('tiny')); // http request logger 
 
app.use('/', routes); 
 
app.use('/public', express.static(path.join(__dirname, '/public'))); 
 

 
// Serve the Parse API on the /parse URL prefix 
 
const mountPath = process.env.PARSE_MOUNT || '/parse'; 
 
app.use(mountPath, server); 
 
app.use('/dashboard', dashboard); 
 

 
/** 
 
* Mosca Server Settings below 
 
*/ 
 
var mosca = require('mosca'); 
 
var http = require('http'); 
 
var httpServer = http.createServer(app); 
 

 
var moscaSettingss = { 
 
    type: 'mongo', 
 
    url: 'mongodb://***:31157/mqtt', 
 
    pubsubCollection: 'pub_sub', 
 
    mongo: {} 
 
}; 
 

 
httpServer= new mosca.Server({ 
 
    backend: moscaSettingss, 
 
    persistence: { 
 
    factory: mosca.persistence.Mongo, 
 
    url: 'mongodb://***:31157/mqtt' 
 
    } 
 
}, function() { 
 
    httpServer.attachHttpServer(app); 
 
}); 
 

 
httpServer.on('ready', function() { 
 
    console.log('Mosca is running'); 
 
}); 
 

 
httpServer.on('clientConnected', function(client) { 
 
    console.log('client connected', client.id); 
 
}); 
 

 
httpServer.on('published', function(packet, client) { 
 
    console.log('Published : ', packet.payload); 
 
}); 
 

 
httpServer.on('subscribed', function(topic, client) { 
 
    console.log('subscribed : ', topic); 
 
}); 
 

 
httpServer.on('unsubscribed', function(topic, client) { 
 
    console.log('unsubscribed : ', topic); 
 
}); 
 

 
httpServer.on('clientDisconnecting', function(client) { 
 
    console.log('clientDisconnecting : ', client.id); 
 
}); 
 

 
httpServer.on('clientDisconnected', function(client) { 
 
    console.log('clientDisconnected : ', client.id); 
 
}); 
 

 
/** 
 
* End of Mosca Server Settings 
 
*/ 
 

 
app.listen(config.server.port,() => { 
 
    console.log(`Magic happens on port ${config.server.port}`); 
 
}); 
 

 
module.exports = app;
에 배포 모스카의 MQTT 브로커에 액세스 할 수 없습니다. 어떤 방법으로 그 mqtt에 연결할 수 없습니다. 가능한 모든 URL을 사용해 보았습니다.

express 앱에서 mqtt 클라이언트를 만들었습니다.이 클라이언트는 브로커와 성공적으로 연결됩니다. 그러나 옆쪽 Heroku, 내 장치를 연결할 수 없습니다.

응답을 기다리고 있습니다.

+0

도움이 될 수도 있습니다. https://github.com/mcollina/mosca/issues/392 – Molda

+0

@Molda 시도했지만 작동하지 않았습니다. –

+0

코드를 보지 않고도 문제가 어디 있는지 알기가 정말 어렵습니다. 질문에 mosca와 express를 설치하는 방법을 추가 할 수 있습니까? – Molda

답변

0

Heroku는 MQTT에 필요한 포트를 열지 않습니다. 이것이 익스프레스가 로컬에서 액세스 할 수 있지만 귀하의 장치가 액세스 할 수없는 이유입니다.

0

나는 또한 ws : //mevris-cloud.herokuapp.com : 80을 시도한다. 그것은 작동합니다!