ALLTERCO / shelly-script-examples

Shelly Scripts for Gen2 Shelly devices
Apache License 2.0
188 stars 55 forks source link

local_name empty #47

Open ayasystems opened 1 year ago

ayasystems commented 1 year ago

My blu has not local name so all scripts are not working....

Whats the way to rename the local_name of blu device?

Regards

taulfsime commented 1 year ago

What scan are you doing? Active or passive?

ayasystems commented 1 year ago

Hi

I'm ussing the follow example:

`/**

// Shelly BLU devices: // SBBT - Shelly BLU Button // SBDW - Shelly BLU DoorWindow

let ALLTERCO_DEVICE_NAME_PREFIX = ["SBBT", "SBDW"];

let ALLTERCO_MFD_ID_STR = "0ba9"; let BTHOME_SVC_ID_STR = "fcd2";

let SCAN_DURATION = BLE.Scanner.INFINITE_SCAN; let ACTIVE_SCAN = true;

let SHELLY_BLU_CACHE = {};

function scanCB(ev, res) { if (ev !== BLE.Scanner.SCAN_RESULT) return; // skip if there is no service_data member if (typeof res.service_data === 'undefined' || typeof res.service_data[BTHOME_SVC_ID_STR] === 'undefined') return; // skip if we have already found this device if (typeof SHELLY_BLU_CACHE[res.addr] !== 'undefined') return; //if (typeof res.local_name !== 'string') return; let shellyBluNameIdx = 0; console.log(res); for (shellyBluNameIdx in ALLTERCO_DEVICE_NAME_PREFIX) { if (res.local_name.indexOf(ALLTERCO_DEVICE_NAME_PREFIX[shellyBluNameIdx]) === 0) { console.log('New device found:'); console.log('Address: ', res.addr, ' Name: ', res.local_name); SHELLY_BLU_CACHE[res.addr] = res.local_name; } } }

BLE.Scanner.Start({ duration_ms: SCAN_DURATION, active: true }, scanCB);`

Local name is empty always

Note that i commented the line that checks local_name

image

taulfsime commented 1 year ago

From what device you are receding this data?

Update the device to latest beta firmware version.

ayasystems commented 1 year ago

Receiver is: Shelly PlusPlugS 1.0.0-beta4

Blu button: image

image

taulfsime commented 1 year ago

Thanks it's an issue with the beta4, unfortunately you have to wait for fix to use it

taulfsime commented 1 year ago

Ops, the scanner can be used with stable 0.14.1, just downgrade from the app

tv4you2016 commented 4 months ago

Hello @taulfsime in "SNGW-BT01","gen" : 2,"fw_id" : "20240425-141307/1.3.0-ga3fdd3d", "ver" : "1.3.0", + Shelly BLU Door Window version 20240408-184602/V1.0.16@716b307b

local name doesn't work either used the https://github.com/ALLTERCO/shelly-script-examples/blob/main/ble-shelly-scanner.js

sciestep commented 3 months ago

Hi @taulfsime, I am getting undefined local name, too, when scanning for Bluetooth devices. I used shelly plus 1pm and 2pm as gateway, in version 1.3.2 and 1.2.2, both getting no local_name, which I use for forwarding to openhab. Firmware on BLU-Device D/W and Motion is also 1.0.16 but also tried with older version 1.0.9-rc How to fix it or is there a working version, on which I can downgrade?

taulfsime commented 3 months ago

@sciestep can you post the output of Shelly.GetConfig here?

sciestep commented 3 months ago

Hi @taulfsime, here is the output of http://192.168.0.29/rpc/Shelly.GetConfig

{ "ble": { "enable": true, "rpc": { "enable": true }, "observer": { "enable": true } }, "cloud": { "enable": true, "server": "shelly-80-eu.shelly.cloud:6022/jrpc" }, "cover:0": { "id": 0, "name": "Rolladen Arbeitszimmer EG", "motor": { "idle_power_thr": 2, "idle_confirm_period": 0.25 }, "maxtime_open": 60, "maxtime_close": 60, "initial_state": "stopped", "invert_directions": false, "in_mode": "dual", "swap_inputs": false, "safety_switch": { "enable": false, "direction": "both", "action": "stop", "allowed_move": null }, "power_limit": 2800, "voltage_limit": 280, "undervoltage_limit": 0, "current_limit": 10, "obstruction_detection": { "enable": false, "direction": "both", "action": "stop", "power_thr": 2503, "holdoff": 1 } }, "input:0": { "id": 0, "name": null, "type": "button", "enable": true, "invert": false, "factory_reset": true }, "input:1": { "id": 1, "name": null, "type": "button", "enable": true, "invert": false, "factory_reset": true }, "mqtt": { "enable": false, "server": null, "client_id": "shellyplus2pm-80646fc7a8d4", "user": null, "ssl_ca": null, "topic_prefix": "shellyplus2pm-80646fc7a8d4", "rpc_ntf": true, "status_ntf": false, "use_client_cert": false, "enable_rpc": true, "enable_control": true }, "script:2": { "id": 2, "name": "script_2", "enable": false }, "script:1": { "id": 1, "name": "oh-blu-scanner.js", "enable": true }, "sys": { "device": { "name": "Rolladen Arbeitszimmer EG", "mac": "80646FC7A8D4", "fw_id": "20240522-112837/1.3.2-g34c651b", "discoverable": true, "eco_mode": true, "profile": "cover", "addon_type": null }, "location": { "tz": "Europe/Berlin", "lat": 48.9075, "lon": 9.1371 }, "debug": { "level": 2, "file_level": null, "mqtt": { "enable": false }, "websocket": { "enable": true }, "udp": { "addr": null } }, "ui_data": {}, "rpc_udp": { "dst_addr": null, "listen_port": null }, "sntp": { "server": "time.google.com" }, "cfg_rev": 27 }, "wifi": { "ap": { "ssid": "ShellyPlus2PM-80646FC7A8D4", "is_open": true, "enable": false, "range_extender": { "enable": false } }, "sta": { "ssid": "Vodafone-3984", "is_open": false, "enable": true, "ipv4mode": "static", "ip": "192.168.0.29", "netmask": "255.255.255.0", "gw": "192.168.0.1", "nameserver": null }, "sta1": { "ssid": null, "is_open": true, "enable": false, "ipv4mode": "dhcp", "ip": null, "netmask": null, "gw": null, "nameserver": null }, "roam": { "rssi_thr": -80, "interval": 60 } }, "ws": { "enable": false, "server": null, "ssl_ca": "ca.pem" } }

taulfsime commented 3 months ago

Thanks, @sciestep.

Could you please open the web page of the device, disable the ble gateway option, reboot the device and check again?

sciestep commented 3 months ago

Hi @taulfsime , this works, thanks. Local name is defined as String, now: res.local_name= SBDW-002C So, I have to decide to send the signal to Cloud or use it in the internal network?

taulfsime commented 3 months ago

Yeah, as for now you can not change the default scan stared by the firmware which is used to forward the packets to the cloud. If you need only packets from some devices, you can make a map in the script for each bluetooth device as Mac address and its type. furthermore its not good running always active scan because this will drain the battery of the device faster.

taulfsime commented 3 months ago

@ayasystems Please check the conversation above, I know that probably this isn't the answer you were looking for, but this is how it works for now. Let's close the issue, as it isn't related to the script directly. Thank you.