go-ibbq

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2019 License: Apache-2.0

README

Go-BLE library for iBBQ Devices

This library builds on top of go-ble to read temperatures and battery level from bluetooth thermometers such as the Inkbird IBT-2X.

Usage

The below sections are taken from the datalogger example app

Configuration

connectTimeout := 60*time.Second
batteryPollingInterval := 5*time.Minute
config, err := ibbq.NewConfiguration(connectTimeout, batteryPollingInterval)

Notification Handlers / Callbacks

Data received from the device is sent asynchronously to registered callback functions. There is also a callback fired when the device disconnects.

logger := log.New("main")

temperatureReceived := func(temperatures []float64) {
	logger.Info("Received temperature data", "temperatures", temperatures)
}
batteryLevelReceived := func (batteryLevel int) {
	logger.Info("Received battery data", "batteryPct", strconv.Itoa(batteryLevel))
}

disconnectedHandler := func(cancel func(), done chan struct{}) func() {
	return func() {
		logger.Info("Disconnected")
		cancel()
		close(done)
	}
}

Instantiating and Connecting

ctx1, cancel := context.WithCancel(context.Background())
defer cancel()

ctx := ble.WithSigHandler(ctx1, cancel)

if bbq, err := ibbq.NewIbbq(ctx, config, disconnectedHandler(cancel, done), temperatureReceived, batteryLevelReceived); err != nil {
    return err
}

err = bbq.Connect()

Directories

Path Synopsis
examples
os

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL