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

UUID String() method not accessible? #336

Open
ssokol opened this issue Jan 20, 2025 · 2 comments
Open

UUID String() method not accessible? #336

ssokol opened this issue Jan 20, 2025 · 2 comments

Comments

@ssokol
Copy link

ssokol commented Jan 20, 2025

Using version 0.10.0, the following line:

fmt.Printf("Subscribing to notifications on characteristic %s...\n", targetChar.UUID.String())

causes the following error:

./fvFlightBar.go:76:87: targetChar.UUID.String undefined (type func() bluetooth.UUID has no field or method String)

Both the docs and the code seem to think there's a String() method but the compiler begs to differ.

For more context, here's more of the code:

	// 6. Discover the characteristic within that service
	chars, err := targetService.DiscoverCharacteristics([]bluetooth.UUID{charUUID})
	if err != nil {
		log.Fatalf("Failed to discover characteristics: %v", err)
	}
	if len(chars) == 0 {
		log.Fatalf("Characteristic %s not found", charUUID.String())
	}
	targetChar := chars[0]

	// 7. Subscribe to notifications on the found characteristic
	fmt.Printf("Subscribing to notifications on characteristic %s...\n", targetChar.UUID.String())
	err = targetChar.EnableNotifications(func(value []byte) {
		// Convert received bytes to a hexadecimal string
		hexData := hex.EncodeToString(value)
		fmt.Printf("Notification data (hex): %s\n", hexData)
	})
	if err != nil {
		log.Fatalf("Failed to subscribe to notifications: %v", err)
	}
@deadprogram
Copy link
Member

What is the target OS you are trying to run on?

@kortschak
Copy link
Contributor

@ssokol You need to call .UUID on DeviceCharacteristic; it does not have a UUID field, it has a method (type func() bluetooth.UUID has no field or method String).

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

3 participants