Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

le-connection-abort-by-local on Raspberry Pi 4 #206

Open
k2sebeom opened this issue Dec 18, 2023 · 1 comment
Open

le-connection-abort-by-local on Raspberry Pi 4 #206

k2sebeom opened this issue Dec 18, 2023 · 1 comment

Comments

@k2sebeom
Copy link

I am running on Raspberry Pi 4 Model B to connect with BLE devices.

When I run adapter.Connect, it always returns error "le-connection-abort-by-local."

BlueZ version = 5.66

package main

import (
	"fmt"
	"strings"
	"time"

	"tinygo.org/x/bluetooth"
)

func main() {
	adapter := bluetooth.DefaultAdapter

	if err := adapter.Enable(); err != nil {
		panic(err)
	}

	scanCh := make(chan bluetooth.ScanResult, 1)

	err := adapter.Scan(func(adapter *bluetooth.Adapter, device bluetooth.ScanResult) {
		println("found device:", device.Address.String(), device.RSSI, device.LocalName())
		if strings.Contains(device.LocalName(), "PD") {
			scanCh <- device
			adapter.StopScan()
		}
	})

	device := <- scanCh
	close(scanCh)
	adapter.SetConnectHandler(func(device bluetooth.Address, connected bool) {
		fmt.Printf("Connected to %s with %v\n", device.String(), connected)
	})

	time.Sleep(time.Second * 1)

	_, err = adapter.Connect(device.Address, bluetooth.ConnectionParams{
		ConnectionTimeout: bluetooth.NewDuration(time.Second * 100),
	})

	if err != nil {
		fmt.Printf("Failed to Connect %s\n", err.Error())
	} else {
		fmt.Printf("Connected to %s\n", device.Address)
	}
}
@aykevl
Copy link
Member

aykevl commented Dec 27, 2023

Have you tried connecting manually through bluetoothctl? Does it work there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants