Bonjour,
J’utilise un script Shelly pour récupérer les publications bluetooth de mes ShellyBLU Button1.
//0.0.2 debug
let debug = false;
//let genTopic = 'shellies/script/bluetooth/';
let genTopic = 'TheengsGateway/undecoded/';
let uuidsBan = ['fe9f', 'fea0', 'fdf7', '3802'];
//let uuidsBan = ['fea0'];
let nutsName = {
"11:11:11:11:11:11": "Nut 01",
"22:22:22:22:22:22": "Nut 02",
"33:33:33:33:33:33": "Nut 03",
"44:44:44:44:44:44": "Nut 04",
"55:55:55:55:55:55": "Shelly Rouge",
"66:66:66:66:66:66": "Shelly Bleu",
"77:77:77:77:77:77": "Shelly Blanc",
"88:88:88:88:88:88": "Shelly Noir"
};
let macList = Object.keys(nutsName);
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 (status !== BLE.Scanner.SCAN_RESULT) return; //exit if Scan status stopped
//if (!isMacValid(response.addr)) return;
if (macList.indexOf(response.addr) === -1) 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, false);
//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('pacLog' + e);}
}
print('Status: started Script');
BLE.Scanner.Start({ duration_ms: BLE.Scanner.INFINITE_SCAN, active: true}, ScanCB);
Je récupère le JSON suivant :
{
"id":"88:88:88:88:88:88",
"mac_type":1,
"advertisementdata":"0201061216d2fc45b3c2e261863eb7d076660d129bc1",
"rssi":-66,
"flags":6,
"servicedatauuid":"fcd2",
"servicedata":"45b3c2e261863eb7d076660d129bc1"
}
Lorsque je colle le JSON sur le site https://parser.theengs.io/, j’ai une erreur.
Une aide de la part de @DigiH ou de @1technophile serait la bienvenue.
Merci.