Compare commits

...

11 Commits
v1.0.5 ... main

Author SHA1 Message Date
henry 8a80c8a609 Don't do this:
log.Println("[INFO] Reading version: ", string(buildBytes))
	} else {
		log.Println("[ERROR] Unable to read /opt/build_version.json file:", err)
Generates too much spam
2025-03-02 21:52:30 -08:00
henry 94940f66c9 syncing up BLE between Go and Python 2024-12-29 16:33:06 -08:00
Henry Seurer 88ddf0d9c0 Merge remote-tracking branch 'origin/main' 2024-12-17 20:36:55 -08:00
Henry Seurer 95d3db9196 Cleaning up BLE messages 2024-12-17 20:36:50 -08:00
henry b52c585528 Merge remote-tracking branch 'origin/main'
# Conflicts:
#	messages.go
2024-12-08 08:51:38 -08:00
henry 7810772cb5 Added Services 2024-12-08 08:50:20 -08:00
Henry Seurer a693a92115 Added Company Name 2024-11-21 09:42:31 -08:00
Henry Seurer 7b85cb03bc Typo Devices => Device 2024-11-21 09:25:13 -08:00
Henry Seurer 1de06f272c Manufacture Data Update 2024-11-21 09:17:20 -08:00
henry 6816ebdb73 Send one device at a time instead of an array. 2024-11-21 07:58:42 -08:00
Henry Seurer 2cc64731f1 change how we handle ble bluetooth messages. 2024-11-19 08:31:47 -08:00
2 changed files with 14 additions and 39 deletions

15
go.mod
View File

@ -1,18 +1,3 @@
module git.bellaerba.dev/henry/farm-messages module git.bellaerba.dev/henry/farm-messages
go 1.23 go 1.23
require tinygo.org/x/bluetooth v0.10.0
require (
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/saltosystems/winrt-go v0.0.0-20241030114511-98be01919aa6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/soypat/cyw43439 v0.0.0-20241116210509-ae1ce0e084c5 // indirect
github.com/soypat/seqs v0.0.0-20240527012110-1201bab640ef // indirect
github.com/tinygo-org/cbgo v0.0.4 // indirect
github.com/tinygo-org/pio v0.0.0-20240901140349-27cbe9d986eb // indirect
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
golang.org/x/sys v0.27.0 // indirect
)

View File

@ -28,14 +28,12 @@ package messages
import ( import (
"encoding/json" "encoding/json"
"log"
"math" "math"
"math/rand" "math/rand"
"os" "os"
"strings" "strings"
"sync/atomic" "sync/atomic"
"time" "time"
"tinygo.org/x/bluetooth"
) )
type BuildVersion struct { type BuildVersion struct {
@ -967,46 +965,38 @@ type StatusMessage struct {
States map[string]bool `json:"states,omitempty"` States map[string]bool `json:"states,omitempty"`
} }
type BleCompany struct { type BleServiceData struct {
CompanyId uint16 `json:"company_id,omitempty"` UUID string `json:"uuid,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Data []byte `json:"data,omitempty"`
} }
type BleAdvertisementPayload struct { type BleManufacturerData struct {
LocalName string `json:"localName,omitempty"` CompanyId uint16 `json:"company_id,omitempty"`
Companies []BleCompany `json:"companies,omitempty"` Name string `json:"name,omitempty"`
Bytes []byte `json:"bytes,omitempty"` Data []byte `json:"data,omitempty"`
ManufacturerData []bluetooth.ManufacturerDataElement `json:"manufacturerData,omitempty"`
} }
type BleDevice struct { type BleDevice struct {
Address string `json:"address,omitempty"` Address string `json:"address,omitempty"`
RSSI int16 `json:"rssi,omitempty"` RSSI int16 `json:"rssi,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Advertisement BleAdvertisementPayload `json:"advertisement,omitempty"` ManufacturerData []BleManufacturerData `json:"companies,omitempty"`
} }
type BleDevicesMap map[string]BleDevice
type BleDevices []BleDevice
type BleAdvertisementMessage struct { type BleAdvertisementMessage struct {
Header MessageHeader `json:"header,omitempty"` Header MessageHeader `json:"header,omitempty"`
Devices BleDevices `json:"devices,omitempty"` Device BleDevice `json:"device,omitempty"`
} }
// noinspection GoUnusedExportedFunction // noinspection GoUnusedExportedFunction
func CreateHeader(status int, location string) MessageHeader { func CreateHeader(status int, location string) MessageHeader {
// Do we have a build version? // Do we have a build version?
// //
var build BuildVersion var build BuildVersion
buildBytes, err := os.ReadFile("/opt/build_version.json") buildBytes, err := os.ReadFile("/opt/build_version.json")
if err == nil { if err == nil {
err = json.Unmarshal(buildBytes, &build) err = json.Unmarshal(buildBytes, &build)
log.Println("[INFO] Reading version: ", string(buildBytes))
} else {
log.Println("[ERROR] Unable to read /opt/build_version.json file:", err)
} }
// Build Message Header // Build Message Header