mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
new: implemented optional websocket for /api/events
This commit is contained in:
parent
b243e67828
commit
5ad1a17118
4 changed files with 66 additions and 36 deletions
|
@ -4,6 +4,7 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/bettercap/gatt"
|
||||
|
@ -11,10 +12,18 @@ import (
|
|||
|
||||
type BLEDevice struct {
|
||||
LastSeen time.Time
|
||||
Device gatt.Peripheral
|
||||
Vendor string
|
||||
Advertisement *gatt.Advertisement
|
||||
RSSI int
|
||||
Device gatt.Peripheral
|
||||
Advertisement *gatt.Advertisement
|
||||
}
|
||||
|
||||
type bleDeviceJSON struct {
|
||||
LastSeen time.Time `json:"last_seen"`
|
||||
Name string `json:"name"`
|
||||
MAC string `json:"mac"`
|
||||
Vendor string `json:"vendor"`
|
||||
RSSI int `json:"rssi"`
|
||||
}
|
||||
|
||||
func NewBLEDevice(p gatt.Peripheral, a *gatt.Advertisement, rssi int) *BLEDevice {
|
||||
|
@ -26,3 +35,15 @@ func NewBLEDevice(p gatt.Peripheral, a *gatt.Advertisement, rssi int) *BLEDevice
|
|||
RSSI: rssi,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *BLEDevice) MarshalJSON() ([]byte, error) {
|
||||
doc := bleDeviceJSON{
|
||||
LastSeen: d.LastSeen,
|
||||
Name: d.Device.Name(),
|
||||
MAC: d.Device.ID(),
|
||||
Vendor: d.Vendor,
|
||||
RSSI: d.RSSI,
|
||||
}
|
||||
|
||||
return json.Marshal(doc)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue