树莓派4B一本通(重写GW 1-建立环境)

pi@raspberrypi:~ $ mkdir mygw
pi@raspberrypi:~ $ cd mygw
pi@raspberrypi:~/mygw $ git clone https://github.com/tinygo-org/bluetooth.git

pi@raspberrypi:~/mygw $ cp bluetooth/ github_bluetooth/ -r

pi@raspberrypi:~/mygw $ rm -rf bluetooth/ 

此时直接执行

不行 因为我还没有自己的代码 

那就del上面出现东西 自己写一个main.go在执行 

参考example的写一个

C:\Users\Koson.Gong\Pictures\bluetooth\examples\nusclient

直接复制过来

   53  cp github_bluetooth/examples/nusclient/main.go main.go
   54  ls -l
   55  go mod init pigw
   56  go mod tidy
   57  cat go.mod 
   58  history

注意看这个:

pi@raspberrypi:~/mygw $ cat go.mod 
module pigw

go 1.17

require tinygo.org/x/bluetooth v0.4.0

require (
        github.com/JuulLabs-OSS/cbgo v0.0.2 // indirect
        github.com/fatih/structs v1.1.0 // indirect
        github.com/go-ole/go-ole v1.2.4 // indirect
        github.com/godbus/dbus/v5 v5.0.3 // indirect
        github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
        github.com/muka/go-bluetooth v0.0.0-20210812063148-b6c83362e27d // indirect
        github.com/sirupsen/logrus v1.6.0 // indirect
        golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
        golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 // indirect
)

 这里有一个知识:我这个项目 是不希望后面github的这个require tinygo.org/x/bluetooth v0.4.0变化影响到我的 或者我会修改这个github项目里面的东西 所以我本地已经拉下来 并且重名了

所以我需要让他隔离出来!!!!

我需要手动修改这个文件

replace tinygo.org/x/bluetooth v0.4.0 => ./github_bluetooth

最后追加一句话就好了!

现在测试一下我们的一个修改

原始mian的85行

    err = tx.EnableNotifications(func(value []byte) { 

这是调用了github仓库源码的一个函数

C:\Users\Koson.Gong\Music\m_izar_rpi_gw\bluetooth_mcube\gattc_linux.go


func (c DeviceCharacteristic) EnableNotifications(callback func(buf []byte)) error {
	ch, err := c.characteristic.WatchProperties()
	if err != nil {
		return err
	}
	go func() {
		for update := range ch {
			if update.Interface == "org.bluez.GattCharacteristic1" && update.Name == "Value" {
				callback(update.Value.([]byte))
			}
		}
	}()
	return c.characteristic.StartNotify()
}

现在修改本地文件夹的这个部分 把这个函数返回值修改一下【多返回一个 用来关闭使能的】 

func (c DeviceCharacteristic) EnableNotifications(callback func(buf []byte)) (chan *bluez.PropertyChanged, error) {
	ch, err := c.characteristic.WatchProperties()
	if err != nil {
		return ch, err
	}
	go func() {
		for update := range ch {
			if update == nil {
				break
			}
			if update.Interface == "org.bluez.GattCharacteristic1" && update.Name == "Value" {
				callback(update.Value.([]byte))
			}
		}
	}()
	return ch, c.characteristic.StartNotify()
}

func (c DeviceCharacteristic) DisableNotifications(ch chan *bluez.PropertyChanged) error {
	err := c.characteristic.UnwatchProperties(ch)
	if err != nil {
		return err
	}
	return nil
}

修改以后 build就会出错!

说明 本地文件夹已经替代了云端的代码了!!

修改85行 _,err = tx.EnableNotifications(func(value []byte) {

这样就可以build通过了!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值