You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.
config for MQTT Broker
*/
let ascoltatore = {
//using ascoltatore
type: 'mongo',
url: 'mongodb://localhost:27017/mqtt',
pubsubCollection: 'ascoltatori',
mongo: {}
};
let settings = {
port: 1883, // 8883 for ssl
backend: ascoltatore,
persistence: {
factory: mosca.persistence.Mongo,
url: 'mongodb://localhost:27017/mqtt'
}
};
let mqttBroServer = new mosca.Server(settings); // mqttBroServer i.e, MQTT BROCKER SERVER
/**
only for MQTT brocker server
*/
mqttBroServer.on('ready', () => {
console.log(Mosca Server Listening on Port ${settings.port});
})
/**
MQTT brocker server
*/
// Sending data from mosca to clients
let packet = {
topic: 'myTopic',
payload: 'qjkdhcqhrbqwuoaehdQYFNHOGWAQLJWRHVBQUIWBGEIOQCBWIEUVVYECQTBUPEIRBCUYWNGJDSHGBUHWFEYRVBGEWOB', // or a Buffer
qos: 1, // 0, 1, or 2
retain: false // or true
};
mqttBroServer.on('connection', function (client) {
console.log(client);
console.log('client connected', client.id);
});
// fired when a message is received
mqttBroServer.on('published', function (packet, client) {
console.log('Published', packet.payload);
});
i this code with this error.
:\iot\remote\server\node_modules\ascoltatori\lib\mongo_ascoltatore.js:113
this.collection.insert(messageObj, { w: 1 }, done);
^
TypeError: Cannot read property 'insert' of undefined
at MongoAscoltatore.publish (E:\iot\remote\server\node_modules\ascoltatori\lib\mongo_ascoltatore.js:113:19)
at MongoAscoltatore.newPublish (E:\iot\remote\server\node_modules\ascoltatori\lib\abstract_ascoltatore.js:144:20)
at E:\iot\remote\server\node_modules\mosca\lib\server.js:383:22
at Server.storePacket (E:\iot\remote\server\node_modules\mosca\lib\server.js:488:5)
at Server.publish (E:\iot\remote\server\node_modules\mosca\lib\server.js:377:8)
at Object. (E:\iot\remote\server\mqtt.js:44:15)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
[nodemon] app crashed - waiting for file changes before starting...
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
'use strict'
const mosca = require('mosca');
/**
*/
let ascoltatore = {
//using ascoltatore
type: 'mongo',
url: 'mongodb://localhost:27017/mqtt',
pubsubCollection: 'ascoltatori',
mongo: {}
};
let settings = {
port: 1883, // 8883 for ssl
backend: ascoltatore,
persistence: {
factory: mosca.persistence.Mongo,
url: 'mongodb://localhost:27017/mqtt'
}
};
let mqttBroServer = new mosca.Server(settings); // mqttBroServer i.e, MQTT BROCKER SERVER
/**
*/
mqttBroServer.on('ready', () => {
console.log(
Mosca Server Listening on Port ${settings.port}
);})
/**
*/
// Sending data from mosca to clients
let packet = {
topic: 'myTopic',
payload: 'qjkdhcqhrbqwuoaehdQYFNHOGWAQLJWRHVBQUIWBGEIOQCBWIEUVVYECQTBUPEIRBCUYWNGJDSHGBUHWFEYRVBGEWOB', // or a Buffer
qos: 1, // 0, 1, or 2
retain: false // or true
};
mqttBroServer.publish(packet, null, ()=>{
console.log('published');
});
mqttBroServer.on('connection', function (client) {
console.log(client);
console.log('client connected', client.id);
});
// fired when a message is received
mqttBroServer.on('published', function (packet, client) {
console.log('Published', packet.payload);
});
i this code with this error.
:\iot\remote\server\node_modules\ascoltatori\lib\mongo_ascoltatore.js:113
this.collection.insert(messageObj, { w: 1 }, done);
^
TypeError: Cannot read property 'insert' of undefined
at MongoAscoltatore.publish (E:\iot\remote\server\node_modules\ascoltatori\lib\mongo_ascoltatore.js:113:19)
at MongoAscoltatore.newPublish (E:\iot\remote\server\node_modules\ascoltatori\lib\abstract_ascoltatore.js:144:20)
at E:\iot\remote\server\node_modules\mosca\lib\server.js:383:22
at Server.storePacket (E:\iot\remote\server\node_modules\mosca\lib\server.js:488:5)
at Server.publish (E:\iot\remote\server\node_modules\mosca\lib\server.js:377:8)
at Object. (E:\iot\remote\server\mqtt.js:44:15)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
[nodemon] app crashed - waiting for file changes before starting...
The text was updated successfully, but these errors were encountered: