Documentation ¶
Overview ¶
IOT is used to translate messages between MQTT and some devices.
Index ¶
- Constants
- Variables
- func NewMQTTClient(cfg MQTTConfig, logger log.Logger) (mqtt.Client, error)
- func ReadMessage(objectID string, payload []byte, endpoint ...string) (interface{}, error)
- func ReadZigbeeMessage(objectID string, payload []byte, endpoint ...string) (interface{}, error)
- func RegisterIOTServer(s grpc.ServiceRegistrar, srv IOTServer)
- type Action
- type AirMessage
- type Config
- type DeviceDiscovery
- func (*DeviceDiscovery) Descriptor() ([]byte, []int)deprecated
- func (x *DeviceDiscovery) GetComponent() string
- func (x *DeviceDiscovery) GetDiscoveryPrefix() string
- func (x *DeviceDiscovery) GetEndpoint() []string
- func (x *DeviceDiscovery) GetMessage() []byte
- func (x *DeviceDiscovery) GetNodeId() string
- func (x *DeviceDiscovery) GetObjectId() string
- func (*DeviceDiscovery) ProtoMessage()
- func (x *DeviceDiscovery) ProtoReflect() protoreflect.Message
- func (x *DeviceDiscovery) Reset()
- func (x *DeviceDiscovery) String() string
- type DeviceType
- type Empty
- type IOTClient
- type IOTServer
- type LEDColor
- type LEDConfig
- type MQTTConfig
- type MockClient
- func (mc *MockClient) AddRoute(topic string, handler mqtt.MessageHandler)
- func (mc *MockClient) Connect() mqtt.Token
- func (mc *MockClient) Disconnect(quiesce uint)
- func (mc *MockClient) IsConnected() bool
- func (mc *MockClient) IsConnectionOpen() bool
- func (mc *MockClient) OptionsReader() mqtt.ClientOptionsReader
- func (mc *MockClient) Publish(topic string, qos byte, retained bool, payload interface{}) mqtt.Token
- func (mc *MockClient) Subscribe(topic string, qos byte, callback mqtt.MessageHandler) mqtt.Token
- func (mc *MockClient) SubscribeMultiple(filters map[string]byte, callback mqtt.MessageHandler) mqtt.Token
- func (mc *MockClient) Unsubscribe(topics ...string) mqtt.Token
- type MockToken
- type Node
- type Server
- type TopicPath
- type UnimplementedIOTServer
- type UnsafeIOTServer
- type UpdateRequest
- type WaterMessage
- type WifiMessage
- type ZigbeeBridgeDevice
- type ZigbeeBridgeDeviceDefinition
- type ZigbeeBridgeLog
- type ZigbeeBridgeState
- type ZigbeeMessage
- type ZigbeeMessageBridgeDevices
Constants ¶
const ( Unknown = iota Coordinator BasicLight ColorLight Relay Leak Button Motion Temperature )
Variables ¶
var File_pkg_iot_iot_proto protoreflect.FileDescriptor
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 ReadMessage ¶
func ReadZigbeeMessage ¶
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) ProtoMessage ¶
func (*Action) ProtoMessage()
func (*Action) ProtoReflect ¶
func (x *Action) ProtoReflect() protoreflect.Message
type AirMessage ¶
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) ProtoMessage ¶
func (*Empty) ProtoMessage()
func (*Empty) ProtoReflect ¶
func (x *Empty) ProtoReflect() protoreflect.Message
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 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 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) 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 Server ¶
type Server struct { UnimplementedIOTServer // contains filtered or unexported fields }
Server is the struct to implement the IOTServer.
func (*Server) UpdateDevice ¶
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 ¶
type UnimplementedIOTServer ¶
type UnimplementedIOTServer struct { }
UnimplementedIOTServer must be embedded to have forward compatible implementations.
func (UnimplementedIOTServer) UpdateDevice ¶
func (UnimplementedIOTServer) UpdateDevice(context.Context, *UpdateRequest) (*Empty, error)
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 WifiMessage ¶
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 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