Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mosca = require('mosca')
- var settings = {
- port: 1885
- };
- //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.toString());
- var b = new Buffer(packet.payload);
- console.log('str' + b);
- console.log('str' + b.toString());
- });
- // 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);
- });
Add Comment
Please, Sign In to add comment