Je laisse ici l’ébauche du script (je remercie De kat du forum Shelly qui m’a été d’une grande aide).
Le script évoluera certainement dès que j’aurai pu faire des tests avec mes Shelly BLU qui, à priori, ne sont pas encore dans la dernière stable de TheengsGateway.
TheengsDecoder #351 v1.5.0 9 juin
TheengsGateway v1.1.0 11 juin Bump TheengsDecoder to 150
TheengsDecoder #370 ShellyBLU But1 22 juin
TheengsDecoder #375 v1.5.5 24 juin
TheengsDecoder #386 v1.5.7 1 juillet
TheengsDecoder #396 ShellyBLU D/W 26 juillet
TheengsDecoder #431 ShellyBLU Motion 24 octobre
TheengsDecoder #453 v1.6.3 16 novembre
TheengsDecoder #460 v1.6.4 6 décembre
Si il y a un intérêt pour certains, j’ouvrirai un post spécifique sur ma mise en place.
let debug = false;
//let genTopic = 'shellies/script/bluetooth/';
let genTopic = 'TheengsGateway/undecoded/';
//let uuidsBan = ['fea0', 'fdf7', '3802'];
let uuidsBan = ['fea0'];
function isMacValid(mac) {
if (mac.length !== 17) {
return false;
}
for (let i=0; i<17; i++) {
if (i%3 === 2) {
if (mac.at(i) !== 0x3a) { //0x3a = :
return false;
}
} else {
//0x30 = 0, 0x39 = 9, 0x61 = a et 0x66 = f
if (mac.at(i) < 0x30 || (mac.at(i) > 0x39 && mac.at(i) < 0x61) || mac.at(i) > 0x66) {
return false;
}
}
}
return true;
}
function ScanCB(status, response) {
if (status !== BLE.Scanner.SCAN_RESULT || !response.service_data) return; //exit if Scan status stopped or no Sevice Data
if (!isMacValid(response.addr)) return;
try{
let uuids = Object.keys(response.service_data);
uuids.forEach(function (uuid) {
if (uuidsBan.indexOf(uuid) !== -1) return;
//if (uuid === 'fea0') return;
let manuuuids = Object.keys(response.manufacturer_data);
let manudata;
if (typeof manuuuids[0] !== 'undefined') manudata = btoh(response.manufacturer_data[manuuuids[0]]);
let mqttData = {
id: response.addr, //ok theengs
mac_type: response.addr_type, //ok theengs
advertisementdata: btoh(response.advData),
scanRsp: response.scanRsp,
rssi: response.rssi, //ok theengs
flags: response.flags,
localname: response.local_name,
manufacturerdatauuid: manuuuids[0],
manufacturerdata: manudata, //ok theengs
servicedatauuid: uuid,
servicedata: btoh(response.service_data[uuid]), //Convert into Base16 to get around utf8 Error.
txpower: response.tx_power_level, //ok theengs
};
if(debug) print('Debug: ',mqttData);
let unixtime = (Shelly.getComponentStatus("sys").unixtime + 2 * 3600) * 1000;
let dateScan = new Date(unixtime);
if(MQTT.isConnected()){
if(debug) print('Debug: sending MQTT Data');
topic = genTopic + response.addr + ':' + uuid;
MQTT.publish(topic + '/undecoded', JSON.stringify(mqttData), 0, true);
//MQTT.publish(topic + '/date', dateScan.toLocaleString(), 0, true);
//MQTT.publish(topic + '/date', JSON.stringify(dateScan), 0, true);
return;
}
print('Error: MQTT is not Ready, cant send MQTT Data');
});
}catch(e){print(e);}
}
print('Status: started Script');
BLE.Scanner.Start({ duration_ms: BLE.Scanner.INFINITE_SCAN, active: true}, ScanCB);