new: implemented optional websocket for /api/events

This commit is contained in:
evilsocket 2018-03-06 13:54:37 +01:00
commit 5ad1a17118
4 changed files with 66 additions and 36 deletions

View file

@ -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)
}