This commit is contained in:
suguo.yao 2021-12-16 10:59:48 +08:00
commit 4cfb26b1aa
5 changed files with 73 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
go.sum
ble-ibeacon
*.exe
*.bin
logs/
.vscode/

8
Makefile Normal file
View File

@ -0,0 +1,8 @@
.PHONY: arm
arm:
go mod tidy
GOOS=linux GOARCH=arm GOARM=7 go build
.PHONY: release
release: arm
scp ./ble-ibeacon pi@192.168.0.21:~/

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module myschools.me/suguo/ble-ibeacon
go 1.17
require github.com/paypal/gatt v0.0.0-20151011220935-4ae819d591cf

33
main.go Normal file
View File

@ -0,0 +1,33 @@
package main
import (
"fmt"
"log"
"github.com/paypal/gatt"
"github.com/paypal/gatt/examples/option"
)
func onPerhipheralDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
fmt.Println(string(a.ManufacturerData))
}
func onStateChanged(device gatt.Device, s gatt.State) {
switch s {
case gatt.StatePoweredOn:
device.Scan([]gatt.UUID{}, true)
return
default:
device.StopScanning()
}
}
func main() {
dev, err := gatt.NewDevice(option.DefaultClientOptions...)
if err != nil {
log.Fatalf("Failed to open device, err:%s\n", err)
}
dev.Handle(gatt.PeripheralDiscovered(onPerhipheralDiscovered))
dev.Init(onStateChanged)
select {}
}

21
readme.md Normal file
View File

@ -0,0 +1,21 @@
# 蓝牙通讯例子
### 概述
希望用于通过蓝牙RSSI值判断距离的研究。
### 组件
- github.com/paypal/gatt
### 部署
- sudo hciconfig hci0 down
- sudo service bluetooth stop
### QA
- Failed to open device, err:no supported devices available
> 执行权限不够导致设备找不到记得sudo
- 查看raspberrypi几位系统
> getconf LONG_BIT
- 查看操作系统信息
> lsb_release -a
- 直接查看系统的架构
> arch