-
Autor
Hi,
Is there a way with a script to create a topic with LWT.
This is to monitor a Bluetooth module (Nut) which gives its presence every minute.
Code
let origine = JSON.stringify(Shelly.getDeviceInfo().name);
function scanCB(ev, res) {
if (ev === BLE.Scanner.SCAN_RESULT) {
if (res.local_name === 'nut') {
let topic = 'shellies/script/bluetooth/nut/' + res.addr + '/';
let unixtime = JSON.stringify(Shelly.getComponentStatus("sys").unixtime);
MQTT.publish(topic + 'rssi', JSON.stringify(res.rssi), 0, false);
MQTT.publish(topic + 'unixtime', unixtime, 0, false);
MQTT.publish(topic + 'presence', unixtime, 0, false);
MQTT.publish(topic + 'origine', origine, 0, false);
}
}
}
BLE.Scanner.Start({ duration_ms: -1}, scanCB);
Alles anzeigen