Socket
Book a DemoInstallSign in
Socket

github.com/infiniteloopcloud/bluetooth-go

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/infiniteloopcloud/bluetooth-go

Source
Go
Version
v0.3.1
Version published
Created
Source

Raw bluetooth for Go

This is a raw bluetooth library which connects to a MAC address by using syscall on Linux and Windows.

Features

  • Implements a simple Read/Write interface.
  • Same behavior on Linux and Windows.
  • Zero-dependency (expect Go's x/sys)
  • Built-in scanner for devices
    • Linux: using the hcitool
    • Windows: no dependency (WSALookupService)

Roadmap

  • Rewrite Linux scan not to use hcitool
  • Add Darwin supports to Communicator

Usage

package main

import (
	"fmt"

	"github.com/infiniteloopcloud/bluetooth-go"
)

func main() {
	// Connect
	conn, err := bluetooth.Connect(bluetooth.Params{
		Address: "58:CF:0A:BB:28:FC",
	})
	if err != nil {
		// handle err
	}

	// Write data into the connection
	_, err = conn.Write([]byte("data"))
	if err != nil {
		// handle err
	}

	// Read from connection
	_, data, err := conn.Read(500)
	if err != nil {
		// handle err
	}
	fmt.Println(string(data))
	
	// Close connection
	err = conn.Close()
	if err != nil {
		// handle err
	}
}

Implement custom logger

package main

import (
	"fmt"

	"github.com/infiniteloopcloud/bluetooth-go"
)

type Logger struct{}

func (Logger) Print(a ...interface{}) {
	fmt.Println(a...)
}

func main() {
	// Connect
	_, err := bluetooth.Connect(bluetooth.Params{
		Address: "58:CF:0A:BB:28:FC",
		Log: Logger{},
	})
	if err != nil {
		// handle err
	}
	//....
}

Scanner

package main

import (
	"fmt"

	"github.com/infiniteloopcloud/bluetooth-go"
)

func main() {
	devices, err := bluetooth.NewScanner().Scan()
	if err != nil {
		// handle err
	}
	fmt.Println(devices)
}

FAQs

Package last updated on 31 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts