This commit is contained in:
parent
3064e13c4f
commit
3bcc552249
20
main.go
20
main.go
|
|
@ -11,7 +11,6 @@ import (
|
||||||
|
|
||||||
"github.com/paypal/gatt"
|
"github.com/paypal/gatt"
|
||||||
"github.com/paypal/gatt/examples/option"
|
"github.com/paypal/gatt/examples/option"
|
||||||
"gorm.io/gorm"
|
|
||||||
"myschools.me/suguo/ble-ibeacon/model"
|
"myschools.me/suguo/ble-ibeacon/model"
|
||||||
"myschools.me/suguo/ble-ibeacon/sqlite"
|
"myschools.me/suguo/ble-ibeacon/sqlite"
|
||||||
)
|
)
|
||||||
|
|
@ -33,8 +32,6 @@ func NewiBeacon(data []byte) (*IBeancon, error) {
|
||||||
return beacon, nil
|
return beacon, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var db *gorm.DB
|
|
||||||
|
|
||||||
func onPerhipheralDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
|
func onPerhipheralDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
|
||||||
// if p.ID() != "78:2C:29:16:F2:78" {
|
// if p.ID() != "78:2C:29:16:F2:78" {
|
||||||
// return
|
// return
|
||||||
|
|
@ -46,12 +43,17 @@ func onPerhipheralDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int)
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
fmt.Println("NAME:", a.LocalName, "T:", time.Now(), "MAC:", p.ID(), "RSSI:", rssi, "LEN:", len(a.ManufacturerData))
|
fmt.Println("NAME:", a.LocalName, "T:", time.Now(), "MAC:", p.ID(), "RSSI:", rssi, "LEN:", len(a.ManufacturerData))
|
||||||
if db == nil {
|
|
||||||
var err error
|
sqlite.Init(&sqlite.Config{
|
||||||
db, err = sqlite.New()
|
DBFile: fmt.Sprintf("./ble%s.db", p.ID()),
|
||||||
if err != nil {
|
})
|
||||||
log.Fatalln(err.Error())
|
|
||||||
}
|
if err := sqlite.Migrate(&model.Rssi{}); err != nil {
|
||||||
|
log.Fatalln(err.Error())
|
||||||
|
}
|
||||||
|
db, err := sqlite.New()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err.Error())
|
||||||
}
|
}
|
||||||
if err := db.Save(&model.Rssi{
|
if err := db.Save(&model.Rssi{
|
||||||
MAC: p.ID(),
|
MAC: p.ID(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue