Documentation ¶
Overview ¶
Package pubsub hold the interfaces and utilities to work with the PubSub side of the OpenChirp framework
Index ¶
- Constants
- Variables
- func GenMQTTClientID(prefix string) (string, error)
- type Bridge
- func (b *Bridge) AddFwd(deviceid, topica string, ...) error
- func (b *Bridge) AddLinkFwd(deviceid, topica string, topicb ...string) error
- func (b *Bridge) AddLinkRev(deviceid, topicb string, topica ...string) error
- func (b *Bridge) AddRev(deviceid, topicb string, ...) error
- func (b *Bridge) IsDeviceLinked(deviceid string) bool
- func (b *Bridge) IsLinkFwd(deviceid, topica string) bool
- func (b *Bridge) IsLinkRev(deviceid, topicb string) bool
- func (b *Bridge) RemoveLinksAll(deviceid string) error
- type MQTTClient
- func NewMQTTBridgeClient(brokerURI, user, pass string, defaultQoS MQTTQoS, defaultPersistence bool) (*MQTTClient, error)
- func NewMQTTClient(brokerURI, user, pass string, defaultQoS MQTTQoS, defaultPersistence bool) (*MQTTClient, error)
- func NewMQTTWillBridgeClient(brokerURI, user, pass string, defaultQoS MQTTQoS, defaultPersistence bool, ...) (*MQTTClient, error)
- func NewMQTTWillClient(brokerURI, user, pass string, defaultQoS MQTTQoS, defaultPersistence bool, ...) (*MQTTClient, error)
- type MQTTQoS
- type PubSub
Constants ¶
const ( QoSAtMostOnce = MQTTQoS(0) QoSAtLeastOnce = MQTTQoS(1) QoSExactlyOnce = MQTTQoS(2) QoSUnknown = MQTTQoS(0xFF) )
Variables ¶
var ( // Sets whether AutoReconnect will be set AutoReconnect bool = true )
Functions ¶
func GenMQTTClientID ¶
GenMQTTClientID generates a random client id for mqtt
Types ¶
type Bridge ¶
type Bridge struct {
// contains filtered or unexported fields
}
Bridge holds configuration for a PubSub bridge
func NewBridge ¶
NewBridge instantiates a PubSub bridge that allows you to map topics from one pubsub interface to another and the reverse. The log is used to declare errors when publishing asynchronously.
func (*Bridge) AddLinkFwd ¶
func (*Bridge) AddLinkRev ¶
func (*Bridge) IsDeviceLinked ¶
func (*Bridge) RemoveLinksAll ¶
type MQTTClient ¶
type MQTTClient struct {
// contains filtered or unexported fields
}
func NewMQTTBridgeClient ¶
func NewMQTTBridgeClient( brokerURI, user, pass string, defaultQoS MQTTQoS, defaultPersistence bool) (*MQTTClient, error)
NewMQTTBridgeClient creates and connects an MQTT client that implements the PubSub interface. This special variant will indicate to the broker that you are operating as a MQTT bridge. In this case, you will not receive an echo of messages you publish to a topic you have subscribed to. Note, this is not an official MQTT feature and is only supported by a few brokers. Checkout https://github.com/mqtt/mqtt.github.io/wiki/bridge_protocol for more info.
func NewMQTTClient ¶
func NewMQTTClient( brokerURI, user, pass string, defaultQoS MQTTQoS, defaultPersistence bool) (*MQTTClient, error)
NewMQTTClient creates and connects an MQTT client that implements the PubSub interface
func NewMQTTWillBridgeClient ¶
func NewMQTTWillBridgeClient( brokerURI, user, pass string, defaultQoS MQTTQoS, defaultPersistence bool, willTopic string, willPayload []byte) (*MQTTClient, error)
NewMQTTWillBridgeClient creates and connects an MQTT client that implements the PubSub interface and sets a will message. This special variant will indicate to the broker that you are operating as a MQTT bridge. In this case, you will not receive an echo of messages you publish to a topic you have subscribed to. Note, this is not an official MQTT feature and is only supported by a few brokers. Checkout https://github.com/mqtt/mqtt.github.io/wiki/bridge_protocol for more info.
func NewMQTTWillClient ¶
func NewMQTTWillClient( brokerURI, user, pass string, defaultQoS MQTTQoS, defaultPersistence bool, willTopic string, willPayload []byte) (*MQTTClient, error)
NewMQTTWillClient creates and connects an MQTT client that implements the PubSub interface and sets a will message.
func (*MQTTClient) Disconnect ¶
func (c *MQTTClient) Disconnect()
func (*MQTTClient) Publish ¶
func (c *MQTTClient) Publish(topic string, payload interface{}) error
func (*MQTTClient) Subscribe ¶
func (c *MQTTClient) Subscribe(topic string, callback func(topic string, payload []byte)) error
func (*MQTTClient) Unsubscribe ¶
func (c *MQTTClient) Unsubscribe(topics ...string) error