mqtt: broker logging

This commit is contained in:
Koushik Dutta
2021-09-20 14:45:34 -07:00
parent d2836c8cee
commit ac6fd6ac0d
3 changed files with 20 additions and 13 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/mqtt",
"version": "0.0.11",
"version": "0.0.14",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/mqtt",
"version": "0.0.11",
"version": "0.0.14",
"dependencies": {
"@types/node": "^16.6.1",
"aedes": "^0.46.1",

View File

@@ -35,5 +35,5 @@
"devDependencies": {
"@scrypted/sdk": "file:../../sdk"
},
"version": "0.0.11"
"version": "0.0.14"
}

View File

@@ -28,7 +28,7 @@ class MqttDevice extends ScryptedDeviceBase implements Scriptable, Settings {
client: Client;
handler: any;
pathname: string;
constructor(nativeId: string) {
super(nativeId);
@@ -246,15 +246,22 @@ class MqttProvider extends ScryptedDeviceBase implements DeviceProvider, Setting
this.netServer?.close();
if (this.storage.getItem('enableBroker') !== 'true')
return;
const instance = aedes();
this.netServer = net.createServer(instance.handle);
const tcpPort = parseInt(this.storage.getItem('tcpPort')) || 1883;
const httpPort = parseInt(this.storage.getItem('httpPort')) || 8888;
this.netServer.listen(tcpPort);
this.httpServer = http.createServer();
ws.createServer({ server: this.httpServer}).on('connection', instance.handle);
this.httpServer.listen(httpPort);
return;
const instance = aedes();
this.netServer = net.createServer(instance.handle);
const tcpPort = parseInt(this.storage.getItem('tcpPort')) || 1883;
const httpPort = parseInt(this.storage.getItem('httpPort')) || 8888;
this.netServer.listen(tcpPort);
this.httpServer = http.createServer();
ws.createServer({ server: this.httpServer }).on('connection', instance.handle);
this.httpServer.listen(httpPort);
instance.on('publish', packet => {
if (!packet.payload)
return;
const preview = packet.payload.length > 512 ? '[large payload suppressed]' : packet.payload.toString();
this.console.log('mqtt message', packet.topic, preview);
});
}
async putSetting(key: string, value: string | number) {