Documentation
¶
Index ¶
- Constants
- func DecodePayloadBytes(encoded string) ([]byte, error)
- func ExtractDevEUI(metadata map[string]interface{}, lnsType lns.LNSType) string
- func ExtractFPort(metadata map[string]interface{}, lnsType lns.LNSType) int
- func ExtractFrequency(metadata map[string]interface{}, lnsType lns.LNSType) (float64, error)
- func ExtractLNSSource(payload map[string]interface{}) lns.LNSType
- func ExtractPayloadDataFromMetadata(metadata map[string]interface{}, lnsType lns.LNSType) string
- func ExtractRxMetadata(metadata map[string]interface{}, lnsType lns.LNSType) ([]interface{}, error)
- func GenerateEntityID(domain, orgSlug, manufacturer, model, devEUI, entityType string) string
- func GenerateUniqueID(model, devEUI, entityType string) string
- func GetEntityDomain(entityType string) string
- func ValidateCoordinates(lat, lon float64) error
- type ComponentInfo
- type ComponentWithSetup
- type DeviceComponent
- type DeviceInfo
- type DeviceType
- type Entity
- type GatewayInfo
- type Location
- type ParseResult
- type ParsedData
- type RawPayload
Constants ¶
const (
CoordScale = 10000000
)
Variables ¶
This section is empty.
Functions ¶
func DecodePayloadBytes ¶ added in v0.0.2
DecodePayloadBytes decodes hex or base64 encoded payload string to bytes
func ExtractDevEUI ¶
ExtractDevEUI extracts device EUI using LNS-specific handler
func ExtractFPort ¶ added in v0.0.2
ExtractFPort extracts fPort using LNS-specific handler
func ExtractFrequency ¶ added in v0.0.3
ExtractFrequency extracts frequency using LNS-specific handler
func ExtractLNSSource ¶ added in v0.0.3
ExtractLNSSource extracts the LNS type from metadata. MPA service sets metadata.lorawan_source - we use that single source of truth.
func ExtractPayloadDataFromMetadata ¶ added in v0.0.3
ExtractPayloadDataFromMetadata extracts payload data using LNS-specific handler
func ExtractRxMetadata ¶ added in v0.0.3
ExtractRxMetadata extracts rx metadata using LNS-specific handler
func GenerateEntityID ¶
GenerateEntityID creates a descriptive entity ID with model information
func GenerateUniqueID ¶
GenerateUniqueID creates a simple unique ID for entity registry
func GetEntityDomain ¶
GetEntityDomain returns the appropriate domain for an entity type
func ValidateCoordinates ¶ added in v0.0.2
ValidateCoordinates validates that coordinates are reasonable
Types ¶
type ComponentInfo ¶
type ComponentInfo struct {
Name string `json:"name"`
Manufacturer string `json:"manufacturer"`
Version string `json:"version"`
Description string `json:"description"`
DeviceTypes []DeviceType `json:"device_types"`
}
ComponentInfo provides metadata about a component
type ComponentWithSetup ¶
type ComponentWithSetup interface {
DeviceComponent
// Setup is called when the component is loaded
Setup(ctx context.Context) error
// Teardown is called when the component is unloaded
Teardown(ctx context.Context) error
}
ComponentWithSetup extends DeviceComponent with optional setup/teardown
type DeviceComponent ¶
type DeviceComponent interface {
// GetInfo returns component metadata
GetInfo() ComponentInfo
// GetSupportedDevices returns the device types this component supports
GetSupportedDevices() []DeviceType
// CanHandle checks if this component can handle the given device type and payload
CanHandle(deviceType DeviceType, payload *RawPayload) bool
// Parse converts raw payload into structured ParsedData (DEPRECATED: Use ParseToEntities)
Parse(ctx context.Context, deviceType DeviceType, payload *RawPayload) (*ParsedData, error)
// ParseToEntities converts raw payload into multiple entities
// deviceLocation is optional and can be nil (e.g., for GPS devices or when trilateration fails)
ParseToEntities(ctx context.Context, orgSlug, model string, deviceType DeviceType, payload *RawPayload, deviceLocation *Location) (*ParseResult, error)
// Validate performs device-specific validation on the parsed data
Validate(deviceType DeviceType, data *ParsedData) error
// SupportsGPS returns true if the device has built-in GPS
SupportsGPS(deviceType DeviceType) bool
// GetSupportedPorts returns the fPorts this device type uses
GetSupportedPorts(deviceType DeviceType) []int
// GetSupportedEntityTypes returns the entity types this device supports
GetSupportedEntityTypes(deviceType DeviceType) []string
}
DeviceComponent defines the interface that each device component must implement This follows a component/platform pattern
type DeviceInfo ¶
type DeviceInfo struct {
Identifiers []string `json:"identifiers"` // ["70b3d57ed005b847"]
Connections [][]string `json:"connections,omitempty"` // [["mac", "02:5b:26:a8:dc:12"]]
Name string `json:"name"` // "Conference Room Tracker"
Manufacturer string `json:"manufacturer"` // "RAKwireless"
Model string `json:"model"` // "RAK2270"
ModelID string `json:"model_id"` // "rak2270"
SWVersion string `json:"sw_version,omitempty"`
HWVersion string `json:"hw_version,omitempty"`
ViaDevice string `json:"via_device,omitempty"`
}
DeviceInfo represents device metadata
func CreateDeviceInfo ¶
func CreateDeviceInfo(devEUI, name, manufacturer, model, modelID string) DeviceInfo
CreateDeviceInfo creates device info structure
type DeviceType ¶
type DeviceType string
DeviceType represents the model/type of a device
const (
DeviceTypeUnknown DeviceType = "UNKNOWN"
)
Default device type
type Entity ¶
type Entity struct {
UniqueID string `json:"unique_id"` // "acme_70b3d57ed005b847_location"
EntityID string `json:"entity_id"` // "device_tracker.acme_rakwireless_rak2270_70b3d57ed005b847_location"
EntityType string `json:"entity_type"` // "device_tracker", "sensor", "binary_sensor"
DeviceClass string `json:"device_class,omitempty"` // "location", "battery", "temperature"
Name string `json:"name"` // "Location", "Battery Level"
State interface{} `json:"state"` // "home", 85, 22.5
Attributes map[string]interface{} `json:"attributes"` // Additional properties
DisplayType []string `json:"display_type,omitempty"`
UnitOfMeas string `json:"unit_of_measurement,omitempty"` // "%", "°C"
Icon string `json:"icon,omitempty"`
Enabled bool `json:"enabled"` // Default: true
Timestamp time.Time `json:"timestamp"`
}
Entity represents a single device capability
type GatewayInfo ¶
type GatewayInfo struct {
GatewayID string `json:"gateway_id"`
RSSI int `json:"rssi"`
SNR float64 `json:"snr"`
Location Location `json:"location,omitempty"`
}
GatewayInfo contains information about the gateway that received the message
type Location ¶
type Location struct {
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Altitude float64 `json:"altitude,omitempty"`
}
Location represents geographical coordinates
type ParseResult ¶
type ParseResult struct {
DeviceEUI string `json:"device_eui"`
DeviceID string `json:"device_id,omitempty"`
SpaceSlug string `json:"space_slug,omitempty"`
DeviceInfo DeviceInfo `json:"device_info"`
Entities []Entity `json:"entities"`
Timestamp time.Time `json:"timestamp"`
}
ParseResult represents the result of parsing device data into multiple entities
type ParsedData ¶
type ParsedData struct {
DeviceEUI string `json:"device_eui"`
DeviceType DeviceType `json:"device_type"`
Timestamp time.Time `json:"timestamp"`
Location *Location `json:"location,omitempty"`
SensorData map[string]interface{} `json:"sensor_data"`
BatteryLevel *float64 `json:"battery_level,omitempty"`
RawData string `json:"raw_data,omitempty"`
}
ParsedData represents the device-specific parsed data (DEPRECATED: Use ParseResult instead)
type RawPayload ¶
type RawPayload struct {
DeviceEUI string `json:"device_eui"`
FPort int `json:"fport"`
Data string `json:"data"` // Base64-encoded payload
Timestamp time.Time `json:"timestamp"`
RxInfo []GatewayInfo `json:"rx_info"`
Metadata map[string]interface{} `json:"metadata"`
LNSType lns.LNSType `json:"lns_type"` // LNS type for efficient extraction
}
RawPayload represents the incoming device data before parsing