I created an Electron App using the mqttjs module. My Electron app just sends a mqtt message every 30 seconds with updates about the status of my computer.
Electron App code:
const shutdown = require('electron-shutdown-command');
var lockYourWindows = require('lock-your-windows');
var mqtt = require('mqtt');
var client = mqtt.connect('mqtt://192.168.0.17', [{protocolId: 'MQTT'}]);
client.on('connect', function () {
client.subscribe('#');
})
client.on('message', function (topic, message) {
// message is Buffer
var msg = message.toString();
//console.log(topic.toString());
if(msg == "lockscreen") {
var isLocked = lockYourWindows.isLocked();
lockYourWindows.lock();
}
if(msg == "shutdown") {
//shutdown.logoff();
}
if(msg == "logoff") {
shutdown.logoff();
}
});
function isScreenLocked() {
var isLocked = lockYourWindows.isLocked();
var v = isLocked ? 1 : 0;
client.publish('/mydevice/lockscreen/status', v.toString());
}
// Ever 30 seconds send a MQTT msg to nodered to update the Lockscreen Status Guage
setInterval(isScreenLocked, 30000);
1533770037: New connection from 192.168.0.18 on port 1883. 1533770037:
New client connected from 192.168.0.18 as 4de309a8004f (c1, k60).
1533770095: Client a7c51f6bdcc7 has exceeded timeout, disconnecting.
1533770095: Socket error on client a7c51f6bdcc7, disconnecting.
1533770363: New connection from 192.168.0.9 on port 1883. 1533770363:
New client connected from 192.168.0.9 as mqttjs_6ce48170 (c1, k60).
1533770480: Client 4de309a8004f has exceeded timeout, disconnecting.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
192.168.0.18
I created an Electron App using the mqttjs module. My Electron app just sends a mqtt message every 30 seconds with updates about the status of my computer.
Electron App code:
Espruino IDE console:
Here is a new log:
1533770037: New connection from 192.168.0.18 on port 1883. 1533770037:
New client connected from 192.168.0.18 as 4de309a8004f (c1, k60).
1533770095: Client a7c51f6bdcc7 has exceeded timeout, disconnecting.
1533770095: Socket error on client a7c51f6bdcc7, disconnecting.
1533770363: New connection from 192.168.0.9 on port 1883. 1533770363:
New client connected from 192.168.0.9 as mqttjs_6ce48170 (c1, k60).
1533770480: Client 4de309a8004f has exceeded timeout, disconnecting.