iot

package
v0.32.16 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

IOT is used to translate messages between MQTT and some devices.

Index

Constants

View Source
const (
	Unknown = iota
	Coordinator
	BasicLight
	ColorLight
	Relay
	Leak
	Button
	Motion
	Temperature
)

Variables

View Source
var File_pkg_iot_iot_proto protoreflect.FileDescriptor
View Source
var IOT_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "iot.IOT",
	HandlerType: (*IOTServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "UpdateDevice",
			Handler:    _IOT_UpdateDevice_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "pkg/iot/iot.proto",
}

IOT_ServiceDesc is the grpc.ServiceDesc for IOT service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func NewMQTTClient

func NewMQTTClient(cfg MQTTConfig, logger log.Logger) (mqtt.Client, error)

func ReadMessage

func ReadMessage(objectID string, payload []byte, endpoint ...string) (interface{}, error)

func ReadZigbeeMessage

func ReadZigbeeMessage(objectID string, payload []byte, endpoint ...string) (interface{}, error)

ReadZigbeeMessage implements the payload unmarshaling for zigbee2mqtt https://www.zigbee2mqtt.io/information/mqtt_topics_and_message_structure.html

func RegisterIOTServer

func RegisterIOTServer(s grpc.ServiceRegistrar, srv IOTServer)

Types

type Action

type Action struct {
	Event  string `protobuf:"bytes,1,opt,name=event,proto3" json:"event,omitempty"`
	Device string `protobuf:"bytes,2,opt,name=device,proto3" json:"device,omitempty"`
	Zone   string `protobuf:"bytes,3,opt,name=zone,proto3" json:"zone,omitempty"`
	// contains filtered or unexported fields
}

func (*Action) Descriptor deprecated

func (*Action) Descriptor() ([]byte, []int)

Deprecated: Use Action.ProtoReflect.Descriptor instead.

func (*Action) GetDevice

func (x *Action) GetDevice() string

func (*Action) GetEvent

func (x *Action) GetEvent() string

func (*Action) GetZone

func (x *Action) GetZone() string

func (*Action) ProtoMessage

func (*Action) ProtoMessage()

func (*Action) ProtoReflect

func (x *Action) ProtoReflect() protoreflect.Message

func (*Action) Reset

func (x *Action) Reset()

func (*Action) String

func (x *Action) String() string

type AirMessage

type AirMessage struct {
	Humidity    *float32 `json:"humidity,omitempty"`
	Temperature *float32 `json:"temperature,omitempty"`
	HeatIndex   *float32 `json:"heatindex,omitempty"`
	TempCoef    *float64 `json:"tempcoef,omitempty"`
}

type Config

type Config struct {
	MQTT MQTTConfig `yaml:"mqtt,omitempty"`
}

type DeviceDiscovery

type DeviceDiscovery struct {
	DiscoveryPrefix string   `protobuf:"bytes,1,opt,name=discovery_prefix,json=discoveryPrefix,proto3" json:"discovery_prefix,omitempty"`
	Component       string   `protobuf:"bytes,2,opt,name=component,proto3" json:"component,omitempty"`
	NodeId          string   `protobuf:"bytes,3,opt,name=node_id,json=nodeId,proto3" json:"node_id,omitempty"`
	ObjectId        string   `protobuf:"bytes,4,opt,name=object_id,json=objectId,proto3" json:"object_id,omitempty"`
	Endpoint        []string `protobuf:"bytes,5,rep,name=endpoint,proto3" json:"endpoint,omitempty"`
	Message         []byte   `protobuf:"bytes,6,opt,name=message,proto3" json:"message,omitempty"`
	// contains filtered or unexported fields
}

<discovery_prefix>/<component>/[<node_id>/]<object_id>/config

func ParseDiscoveryMessage

func ParseDiscoveryMessage(topicPath TopicPath, msg mqtt.Message) *DeviceDiscovery

func (*DeviceDiscovery) Descriptor deprecated

func (*DeviceDiscovery) Descriptor() ([]byte, []int)

Deprecated: Use DeviceDiscovery.ProtoReflect.Descriptor instead.

func (*DeviceDiscovery) GetComponent

func (x *DeviceDiscovery) GetComponent() string

func (*DeviceDiscovery) GetDiscoveryPrefix

func (x *DeviceDiscovery) GetDiscoveryPrefix() string

func (*DeviceDiscovery) GetEndpoint

func (x *DeviceDiscovery) GetEndpoint() []string

func (*DeviceDiscovery) GetMessage

func (x *DeviceDiscovery) GetMessage() []byte

func (*DeviceDiscovery) GetNodeId

func (x *DeviceDiscovery) GetNodeId() string

func (*DeviceDiscovery) GetObjectId

func (x *DeviceDiscovery) GetObjectId() string

func (*DeviceDiscovery) ProtoMessage

func (*DeviceDiscovery) ProtoMessage()

func (*DeviceDiscovery) ProtoReflect

func (x *DeviceDiscovery) ProtoReflect() protoreflect.Message

func (*DeviceDiscovery) Reset

func (x *DeviceDiscovery) Reset()

func (*DeviceDiscovery) String

func (x *DeviceDiscovery) String() string

type DeviceType

type DeviceType int

func ZigbeeDeviceType

func ZigbeeDeviceType(z ZigbeeBridgeDevice) DeviceType

func (DeviceType) String

func (d DeviceType) String() string

type Empty

type Empty struct {
	// contains filtered or unexported fields
}

func (*Empty) Descriptor deprecated

func (*Empty) Descriptor() ([]byte, []int)

Deprecated: Use Empty.ProtoReflect.Descriptor instead.

func (*Empty) ProtoMessage

func (*Empty) ProtoMessage()

func (*Empty) ProtoReflect

func (x *Empty) ProtoReflect() protoreflect.Message

func (*Empty) Reset

func (x *Empty) Reset()

func (*Empty) String

func (x *Empty) String() string

type IOTClient

type IOTClient interface {
	UpdateDevice(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*Empty, error)
}

IOTClient is the client API for IOT service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewIOTClient

func NewIOTClient(cc grpc.ClientConnInterface) IOTClient

type IOTServer

type IOTServer interface {
	UpdateDevice(context.Context, *UpdateRequest) (*Empty, error)
	// contains filtered or unexported methods
}

IOTServer is the server API for IOT service. All implementations must embed UnimplementedIOTServer for forward compatibility

type LEDColor

type LEDColor struct {
	State      string `json:"state"`
	Brightness int    `json:"brightness"`
	Effect     string `json:"effect"`
	Color      struct {
		R int `json:"r"`
		G int `json:"g"`
		B int `json:"b"`
	} `json:"color"`
}

type LEDConfig

type LEDConfig struct {
	Schema       string   `json:"schema"`
	Brightness   bool     `json:"brightness"`
	Rgb          bool     `json:"rgb"`
	Effect       bool     `json:"effect"`
	EffectList   []string `json:"effect_list"`
	Name         string   `json:"name"`
	UniqueID     string   `json:"unique_id"`
	CommandTopic string   `json:"command_topic"`
	StateTopic   string   `json:"state_topic"`
	Device       struct {
		Identifiers  string     `json:"identifiers"`
		Manufacturer string     `json:"manufacturer"`
		Model        string     `json:"model"`
		Name         string     `json:"name"`
		SwVersion    string     `json:"sw_version"`
		Connections  [][]string `json:"connections"`
	} `json:"device"`
}

type MQTTConfig

type MQTTConfig struct {
	URL      string `yaml:"url,omitempty"`
	Topic    string `yaml:"topic,omitempty"`
	Username string `yaml:"username,omitempty"`
	Password string `yaml:"password,omitempty"`
}

type MockClient

type MockClient struct {
	LastPublishTopic   string
	LastPublishPayload interface{}
	// contains filtered or unexported fields
}

func (*MockClient) AddRoute

func (mc *MockClient) AddRoute(topic string, handler mqtt.MessageHandler)

func (*MockClient) Connect

func (mc *MockClient) Connect() mqtt.Token

func (*MockClient) Disconnect

func (mc *MockClient) Disconnect(quiesce uint)

func (*MockClient) IsConnected

func (mc *MockClient) IsConnected() bool

func (*MockClient) IsConnectionOpen

func (mc *MockClient) IsConnectionOpen() bool

func (*MockClient) OptionsReader

func (mc *MockClient) OptionsReader() mqtt.ClientOptionsReader

func (*MockClient) Publish

func (mc *MockClient) Publish(topic string, qos byte, retained bool, payload interface{}) mqtt.Token

func (*MockClient) Subscribe

func (mc *MockClient) Subscribe(topic string, qos byte, callback mqtt.MessageHandler) mqtt.Token

func (*MockClient) SubscribeMultiple

func (mc *MockClient) SubscribeMultiple(filters map[string]byte, callback mqtt.MessageHandler) mqtt.Token

func (*MockClient) Unsubscribe

func (mc *MockClient) Unsubscribe(topics ...string) mqtt.Token

type MockToken

type MockToken struct {
	// contains filtered or unexported fields
}

func (*MockToken) Done

func (mt *MockToken) Done() <-chan struct{}

func (*MockToken) Error

func (mt *MockToken) Error() error

func (*MockToken) Wait

func (mt *MockToken) Wait() bool

func (*MockToken) WaitTimeout

func (mt *MockToken) WaitTimeout(time.Duration) bool

type Node

type Node struct {
	IP         string
	NodeID     string
	MACAddress string
}

type Server

type Server struct {
	UnimplementedIOTServer
	// contains filtered or unexported fields
}

Server is the struct to implement the IOTServer.

func NewServer

func NewServer(mqttClient mqtt.Client) (*Server, error)

NewServer receives an mqttClient to return a new Server.

func (*Server) UpdateDevice

func (s *Server) UpdateDevice(ctx context.Context, req *UpdateRequest) (*Empty, error)

UpdateDevice implements the OTA update for zigbee devices.

https://www.zigbee2mqtt.io/information/ota_updates.html#update-to-latest-firmware

type TopicPath

type TopicPath struct {
	DiscoveryPrefix string
	Component       string
	NodeID          string
	ObjectID        string
	Endpoint        []string
}

func ParseTopicPath

func ParseTopicPath(topic string) (TopicPath, error)

type UnimplementedIOTServer

type UnimplementedIOTServer struct {
}

UnimplementedIOTServer must be embedded to have forward compatible implementations.

func (UnimplementedIOTServer) UpdateDevice

type UnsafeIOTServer

type UnsafeIOTServer interface {
	// contains filtered or unexported methods
}

UnsafeIOTServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to IOTServer will result in compilation errors.

type UpdateRequest

type UpdateRequest struct {
	Device string `protobuf:"bytes,1,opt,name=device,proto3" json:"device,omitempty"`
	// contains filtered or unexported fields
}

func (*UpdateRequest) Descriptor deprecated

func (*UpdateRequest) Descriptor() ([]byte, []int)

Deprecated: Use UpdateRequest.ProtoReflect.Descriptor instead.

func (*UpdateRequest) GetDevice

func (x *UpdateRequest) GetDevice() string

func (*UpdateRequest) ProtoMessage

func (*UpdateRequest) ProtoMessage()

func (*UpdateRequest) ProtoReflect

func (x *UpdateRequest) ProtoReflect() protoreflect.Message

func (*UpdateRequest) Reset

func (x *UpdateRequest) Reset()

func (*UpdateRequest) String

func (x *UpdateRequest) String() string

type WaterMessage

type WaterMessage struct {
	Temperature *float32 `json:"temperature,omitempty"`
	TempCoef    *float64 `json:"tempcoef,omitempty"`
}

type WifiMessage

type WifiMessage struct {
	BSSID string `json:"bssid,omitempty"`
	IP    string `json:"ip,omitempty"`
	RSSI  int    `json:"rssi,omitempty"`
	SSID  string `json:"ssid,omitempty"`
}

type ZigbeeBridgeDevice

type ZigbeeBridgeDevice struct {
	IeeeAddress    string `json:"ieee_address"`
	Type           string `json:"type"`
	NetworkAddress int    `json:"network_address"`
	Supported      bool   `json:"supported"`
	FriendlyName   string `json:"friendly_name"`
	Endpoints      struct {
		Num1 struct {
			Bindings             []interface{} `json:"bindings"`
			ConfiguredReportings []interface{} `json:"configured_reportings"`
			Clusters             struct {
				Input  []string      `json:"input"`
				Output []interface{} `json:"output"`
			} `json:"clusters"`
		} `json:"1"`
	} `json:"endpoints"`
	Definition  ZigbeeBridgeDeviceDefinition `json:"definition"`
	PowerSource string                       `json:"power_source"`
	DateCode    string                       `json:"date_code"`
	ModelID     string                       `json:"model_id"`
	Scenes      []struct {
		ID   int    `json:"id"`
		Name string `json:"name"`
	} `json:"scenes"`
	Interviewing       bool   `json:"interviewing"`
	InterviewCompleted bool   `json:"interview_completed"`
	SoftwareBuildID    string `json:"software_build_id,omitempty"`
}

type ZigbeeBridgeDeviceDefinition

type ZigbeeBridgeDeviceDefinition struct {
	Model       string `json:"model"`
	Vendor      string `json:"vendor"`
	Description string `json:"description"`
}

type ZigbeeBridgeLog

type ZigbeeBridgeLog struct {
	Type    string                 `json:"type,omitempty"`
	Message interface{}            `json:"message,omitempty"`
	Meta    map[string]interface{} `json:"meta,omitempty"`
}

ZigbeeBridgeLogMessage https://www.zigbee2mqtt.io/information/mqtt_topics_and_message_structure.html#zigbee2mqttbridgelog zigbee2mqtt/bridge/log {"type":"device_announced","message":"announce","meta":{"friendly_name":"0x0017880104650857"}}

func (*ZigbeeBridgeLog) UnmarshalJSON

func (z *ZigbeeBridgeLog) UnmarshalJSON(data []byte) error

type ZigbeeBridgeState

type ZigbeeBridgeState string
const (
	Offline ZigbeeBridgeState = "offline"
	Online  ZigbeeBridgeState = "online"
)

type ZigbeeMessage

type ZigbeeMessage struct {
	Action       *string  `json:"action,omitempty"`
	Battery      *float64 `json:"battery,omitempty"`
	Illuminance  *int     `json:"illuminance,omitempty"`
	LinkQuality  *int     `json:"linkquality,omitempty"`
	Occupancy    *bool    `json:"occupancy,omitempty"`
	Tamper       *bool    `json:"tamper,omitempty"`
	Temperature  *float64 `json:"temperature,omitempty"`
	Humidity     *float64 `json:"humidity,omitempty"`
	Voltage      *int     `json:"voltage,omitempty"`
	WaterLeak    *bool    `json:"water_leak,omitempty"`
	Co2          *float64 `json:"co2,omitempty"`
	Formaldehyde *float64 `json:"formaldehyd,omitempty"`
	VOC          *int     `json:"voc,omitempty"`
}

type ZigbeeMessageBridgeDevices

type ZigbeeMessageBridgeDevices []ZigbeeBridgeDevice

Jump to

Keyboard shortcuts

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