Skip to content

Commit

Permalink
Make the HCI device index configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrin committed Mar 3, 2022
1 parent 97598c6 commit 44b0150
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions config.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ gw_mac: 00:00:00:00:00:00
# Whether to include all advertisements (true) or just those from RuuviTags (false)
all_advertisements: false

# HCI device index for the bluetooth adapter to use. 0 by default, which should correspond to the hci0 device
hci_index: 0

# Publish the data to MQTT in Ruuvi Gateway format
mqtt:
# Flag to enable or disable publishing the data to a MQTT server
Expand Down
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Logging struct {
type Config struct {
GwMac string `yaml:"gw_mac"`
AllAdvertisements bool `yaml:"all_advertisements"`
HciIndex int `yaml:"hci_index"`
MQTT *MQTT `yaml:"mqtt,omitempty"`
HTTP *HTTP `yaml:"http,omitempty"`
Logging Logging `yaml:"logging"`
Expand All @@ -46,7 +47,7 @@ type Config struct {

func ReadConfig(configFile string, strict bool) (Config, error) {
if _, err := os.Stat(configFile); errors.Is(err, os.ErrNotExist) {
return Config{}, errors.New(fmt.Sprintf("No config found! Tried to open \"%s\"", configFile))
return Config{}, fmt.Errorf("no config found! Tried to open \"%s\"", configFile)
}

f, err := os.Open(configFile)
Expand Down
12 changes: 8 additions & 4 deletions gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ func Run(config config.Config) {
log.Fatal("Neither MQTT nor HTTP is configured, check the config")
}

device, err := dev.NewDevice("default", ble.OptScanParams(cmd.LESetScanParameters{
LEScanType: 0, // passive scan
}))
device, err := dev.NewDevice("default",
ble.OptDeviceID(config.HciIndex),
ble.OptScanParams(cmd.LESetScanParameters{
LEScanType: 0, // passive scan
}))
if err != nil {
log.WithError(err).Fatal("Can't setup default bluetooth device")
log.WithError(err).WithFields(log.Fields{
"hci_index": config.HciIndex,
}).Fatal("Can't setup bluetooth device")
}
ble.SetDefaultDevice(device)
advHandler := func(adv ble.Advertisement) {
Expand Down

0 comments on commit 44b0150

Please sign in to comment.