new: ble.show shows device names if available for at least one of the devices

This commit is contained in:
evilsocket 2019-02-15 13:41:39 +01:00
commit a72801f9b5
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
2 changed files with 46 additions and 14 deletions

View file

@ -40,14 +40,21 @@ func NewBLEDevice(p gatt.Peripheral, a *gatt.Advertisement, rssi int) *BLEDevice
}
}
func (d *BLEDevice) Name() string {
name := d.Device.Name()
if name == "" && d.Advertisement != nil {
name = d.Advertisement.LocalName
}
return name
}
func (d *BLEDevice) MarshalJSON() ([]byte, error) {
doc := bleDeviceJSON{
LastSeen: d.LastSeen,
Name: d.Device.Name(),
Name: d.Name(),
MAC: d.Device.ID(),
Vendor: d.Vendor,
RSSI: d.RSSI,
}
return json.Marshal(doc)
}