azureiot

package
v0.2024.5 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

Package azureiot implements data upload to Azure IoT Hub. The driver pulls (or polls) for data from configured Smart Core devices, encodes the data as JSON, and uploads it to Azure IoT Hub via it's MQTT API. Published data is the protojson encoding of the PullTraitResponse message type, for example traits.PullAirQualityResponse. See [traits.go] for supported traits.

Azure IoT Hub has it's own concept of devices that are separate from Smart Core names. When configuring the driver you start by defining the IoT Hub device to publish to, then define which Smart Core devices publish data to that IoT hub device. Finally you define which traits to pull from each Smart Core device.

There are two ways to configure the IoT Hub device: manually via the Hub console, or dynamically via the Device Provisioning Service (DPS). This driver supports both methods. The usual way to configure the IoT Hub device is via a Connection String which can be retrieved from the Hub console. See [config.go] for details.

To reduce configuration overhead in both Smart Core and Azure IoT Hub, it is recommended to setup a single IoT Hub device for each Smart Core node and publish multiple Smart Core devices data to it.

Index

Constants

View Source
const (
	DefaultPollInterval = 5 * time.Minute
	DefaultBacklogSize  = 1000 // in messages per device
)
View Source
const FactoryName = "azureiot"

Variables

View Source
var Factory auto.Factory = factory{}

Functions

This section is empty.

Types

type Auto

type Auto struct {
	*service.Service[Config]
	// contains filtered or unexported fields
}

type Config

type Config struct {
	// Azure IoT Hub dps credentials, used for devices where DeviceConfig.ConnectionString == ""
	GroupKey     string `json:"groupKey"`
	GroupKeyFile string `json:"groupKeyFile"`
	IDScope      string `json:"idScope"`

	Devices []DeviceConfig `json:"devices"`

	// When a device doesn't support pullTraits, use this poll interval.
	// Defaults to DefaultPollInterval, can't be less than minPollInterval.
	PollInterval *jsontypes.Duration `json:"pollInterval"`
	// When present, provides defaults for connecting to all smart core devices.
	RemoteNode *RemoteNodeConfig `json:"remoteNode,omitempty"`
}

func DefaultConfig

func DefaultConfig() Config

func ParseConfig

func ParseConfig(jsonBytes []byte) (Config, error)

type DeviceConfig

type DeviceConfig struct {
	SCDeviceConfig                  // config used when an IoT Hub device maps to one Smart Core device
	Children       []SCDeviceConfig `json:"children,omitempty"` // config used when an IoT Hub device maps to multiple Smart Core devices

	// Azure IoT Hub connection details, one of these must be provided
	RegistrationID   string `json:"registrationID,omitempty"`   // Device Provisioning Service registration ID - usually becomes the device name in the cloud
	ConnectionString string `json:"connectionString,omitempty"` // Use a connection string to directly connect to IoT Hub, bypassing Device Provisioning Service
}

DeviceConfig represents an Azure IoT Hub device. This device may map to one or more Smart Core devices.

type RemoteNodeConfig

type RemoteNodeConfig struct {
	Host                 string `json:"host,omitempty"` // "host[:port]" of the Smart Core node, port defaults to 23557
	*jsontypes.TLSConfig        // How to connect to the remote host, defaults to hub TLS config if enrolled.
}

type SCDeviceConfig

type SCDeviceConfig struct {
	Name                string       `json:"name"`                // Smart Core name to monitor
	Traits              []trait.Name `json:"traits"`              // Traits to pullTraits from
	IgnoreUnknownTraits bool         `json:"ignoreUnknownTraits"` // Ignore unknown traits instead of erroring.

	PollInterval *jsontypes.Duration `json:"pollInterval"`         // Defaults to Config.PollInterval
	RemoteNode   *RemoteNodeConfig   `json:"remoteNode,omitempty"` // Defaults to Config.RemoteNode, if absent (or Host=="") uses local device resolution.
}

SCDeviceConfig represents a Smart Core device information will be pulled from.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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