MQTT Event
Event that fires when the server receives an MQTT message.
Event name
Request
Response
Response contains the Event Log entry.
Field | Type | Description |
---|---|---|
_id | String | ID of the entry. |
type | Integer | Message type. 1 for SNMP Trap, 2 for MQTT message. |
timestamp | Integer | Timestamp of when the MQTT message was sent. |
payload | Object | MQTT message. |
payload.topic | String | MQTT topic. |
payload.message | String | MQTT message. |
entity | Array<Object> | List of entities that the MQTT message belongs to. |
entity.entityId | String | ID of the entity. |
entity.entityType | Integer | Type of the entity. 1 is an Object, 2 is a Link. |
entity.entityName | String | Name of the entity. |
Example
Request
const comet = require('socket.io-client');
// Comet settings
const COMET_CONNECT_TIMEOUT = 5000;
const sessionId = "..."
const conf = {
cometHost: 'https://example.com',
cometPort: '1234',
};
const url = `${conf.cometHost}` + (conf.cometPort ? `:${conf.cometPort}` : '');
const cn = comet.connect(url, {
query: { forceNew: true, sessionId },
timeout: COMET_CONNECT_TIMEOUT,
});
cn.emit('add-topics', 'mqtt');
cn.on('mqtt', msg => {
console.log(msg);
});