ibbq

package module
v0.0.0-...-1b39501 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: Apache-2.0 Imports: 9 Imported by: 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()

Documentation

Overview

Copyright 2018 the original author or authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2018 the original author or authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const AccountAndVerify = "fff2"

AccountAndVerify WRITE

View Source
const DeviceName = "iBBQ"

DeviceName is the name we look for when we scan.

View Source
const HistoryData = "fff3"

HistoryData NOTIFY

View Source
const RealTimeData = "fff4"

RealTimeData NOTIFY

View Source
const SettingData = "fff5"

SettingData WRITE

View Source
const SettingResult = "fff1"

SettingResult NOTIFY

Variables

View Source
var (
	// Credentials stores our login credentials for the thermometer.
	Credentials = []byte{0x21, 0x07, 0x06,
		0x05, 0x04, 0x03, 0x02, 0x01, 0xb8, 0x22,
		0x00, 0x00, 0x00, 0x00, 0x00}
)
View Source
var DefaultConfiguration = Configuration{
	ConnectTimeout:         60 * time.Second,
	BatteryPollingInterval: 5 * time.Minute,
}

DefaultConfiguration is a somewhat sane default.

Functions

func NewDevice

func NewDevice(impl string) (d ble.Device, err error)

NewDevice creates a new device

Types

type BatteryLevelReceivedHandler

type BatteryLevelReceivedHandler func(int)

BatteryLevelReceivedHandler is a callback for battery readings. All battery readings are returned as percentages.

type Configuration

type Configuration struct {
	ConnectTimeout         time.Duration `description:"Connection timeout"`
	BatteryPollingInterval time.Duration `description:"Battery level polling interval"`
}

Configuration configures our ibbq session

func NewConfiguration

func NewConfiguration(connectTimeout time.Duration, batteryPollingInterval time.Duration) (Configuration, error)

NewConfiguration creates a configuration

type DisconnectedHandler

type DisconnectedHandler func()

DisconnectedHandler handles disconnection events

type Ibbq

type Ibbq struct {
	// contains filtered or unexported fields
}

Ibbq is an instance of the thermometer

func NewIbbq

func NewIbbq(ctx context.Context, config Configuration, disconnectedHandler DisconnectedHandler, temperatureReceivedHandler TemperatureReceivedHandler, batteryLevelReceivedHandler BatteryLevelReceivedHandler, statusUpdatedHandler StatusUpdatedHandler) (ibbq Ibbq, err error)

NewIbbq creates a new Ibbq

func (*Ibbq) ConfigureTemperatureCelsius

func (ibbq *Ibbq) ConfigureTemperatureCelsius() error

ConfigureTemperatureCelsius changes the device to display temperatures in Celsius on the screen. It does not change the units sent back over the wire, however, which are always in Celsius.

func (*Ibbq) ConfigureTemperatureFahrenheit

func (ibbq *Ibbq) ConfigureTemperatureFahrenheit() error

ConfigureTemperatureFahrenheit changes the device to display temperatures in Fahrenheit on the screen. It does not change the units sent back over the wire, however, which are always in Celsius.

func (*Ibbq) Connect

func (ibbq *Ibbq) Connect() error

Connect connects to an ibbq

func (*Ibbq) Disconnect

func (ibbq *Ibbq) Disconnect(force bool) error

Disconnect disconnects from an ibbq

type Status

type Status string

Status represents our connection status

const (
	// Disconnected means we are not connected
	Disconnected Status = "Disconnected"
	//Connecting means we are establishing a connection/session
	Connecting Status = "Connecting"
	// Connected means we have established a connection/session
	Connected Status = "Connected"
	// Disconnecting means we have requested to disconnect and are awaiting acknowledgement
	Disconnecting Status = "Disconnecting"
)

type StatusUpdatedHandler

type StatusUpdatedHandler func(Status)

StatusUpdatedHandler is a callback for status updates.

type TemperatureReceivedHandler

type TemperatureReceivedHandler func([]float64)

TemperatureReceivedHandler is a callback for temperature readings. All temperature readings are returned in celsius.

Directories

Path Synopsis
Copyright 2018 the original author or authors
Copyright 2018 the original author or authors

Jump to

Keyboard shortcuts

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