Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const aedes = require('aedes')();
- const ws = require('websocket-stream');
- const config = require('../config');
- // fired when a client connects
- aedes.on('client', function (client) {
- console.log('Client Connected: \x1b[33m' + (client ? client.id : client) + '\x1b[0m', 'to broker', aedes.id);
- });
- // fired when a client disconnects aedes.on('clientDisconnect', function (client) {
- console.log('Client Disconnected: \x1b[31m' + (client ? client.id : client) + '\x1b[0m', 'to broker', aedes.id);
- });
- // TCP/IP server
- const server = require('net').createServer(aedes.handle);
- const port = config.features.mqtt.broker.port;
- server.listen(port, function () {
- console.log(`MQTT broker server started and listening on TCP/IP port ${port}`);
- });
- // WebSocket server
- const httpServer = require('http').createServer();
- const wsPort = config.features.mqtt.broker.wsPort;
- ws.createServer({ server: httpServer }, aedes.handle);
- httpServer.listen(wsPort, function () {
- console.log(`MQTT broker server websocket listening on port ${wsPort}`);
- });
- // vvvv add the below lines in server.js vvvv
- const config = require('./config');
- app.get('/iot/features', function (req, res, next) {
- res.json(config.features);
- });
- require('./services/MqttBroker');
Add Comment
Please, Sign In to add comment