diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..849ddff --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..70c975b --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,40 @@ +# This is an example .goreleaser.yml file with some sane defaults. +# Make sure to check the documentation at http://goreleaser.com +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy +builds: + - env: + - CGO_ENABLED=1 + goos: + - linux +archives: + - replacements: + darwin: Darwin + linux: Linux + windows: Windows + 386: i386 + amd64: x86_64 +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' +nfpms: +- vendor: Coaxial Flutter Labs + maintainer: Will Gorman + description: HTTP server for exporting metrics from Bluetooth sensors + formats: + - deb + - rpm + files: + "scripts/systemd/sensor-bridge.service": "/etc/systemd/system/sensor-bridge.service" + scripts: + postinstall: "scripts/systemd/postinstall.sh" + preremove: "scripts/systemd/preremove.sh" diff --git a/govee.go b/govee.go index a4695d0..e354c17 100644 --- a/govee.go +++ b/govee.go @@ -33,6 +33,7 @@ func (p H5102Parser) Parse(a ble.Advertisement) (*Reading, error) { }, nil } +// https://github.com/Home-Is-Where-You-Hang-Your-Hack/sensor.goveetemp_bt_hci func decodeReading(a ble.Advertisement) (float32, float32, error) { data := a.ManufacturerData()[4:7] hex := fmt.Sprintf("%X", data) diff --git a/main.go b/main.go index 7e1a2cd..b382c58 100644 --- a/main.go +++ b/main.go @@ -169,6 +169,8 @@ func init() { viper.AutomaticEnv() viper.SetDefault("Scanner.Duration", 15*time.Second) viper.SetDefault("Scanner.Interval", 5*time.Minute) + viper.SetDefault("prometheus.port", 2112) + viper.AddConfigPath("/etc/sensor-bridge") viper.AddConfigPath("$HOME/.sensorbridge") viper.AddConfigPath(".") viper.SetConfigName("config") @@ -206,7 +208,7 @@ func main() { } http.Handle("/metrics", promhttp.Handler()) - go http.ListenAndServe(":2112", nil) + go http.ListenAndServe(fmt.Sprintf(":%d", viper.GetInt("prometheus.port")), nil) go func() { for { diff --git a/scripts/systemd/postinstall.sh b/scripts/systemd/postinstall.sh new file mode 100644 index 0000000..9e32fd9 --- /dev/null +++ b/scripts/systemd/postinstall.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +systemctl enable sensor-bridge +systemctl restart sensor-bridge diff --git a/scripts/systemd/preremove.sh b/scripts/systemd/preremove.sh new file mode 100644 index 0000000..21e6305 --- /dev/null +++ b/scripts/systemd/preremove.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +systemctl stop sensor-bridge +systemctl disable sensor-bridge + +rm -rf /etc/sensor-bridge diff --git a/scripts/systemd/sensor-bridge.service b/scripts/systemd/sensor-bridge.service new file mode 100644 index 0000000..5e3d4f0 --- /dev/null +++ b/scripts/systemd/sensor-bridge.service @@ -0,0 +1,8 @@ +[Unit] +Description=Bluetooth Sensor Bridge Service + +[Service] +ExecStart=/usr/local/bin/sensor-bridge + +[Install] +WantedBy=multi-user.target