Documentation
¶
Overview ¶
Package efmq provides basic MQTT like functionality for message publishing and subscriptions within a local area network
Example (Publisher) ¶
This example starts publishing to a topic every second via the network interface "wlan0".
package main
import (
"log"
"time"
"github.com/olliephillips/efmq"
)
func main() {
mq, err := efmq.NewEFMQ("wlan0")
if err != nil {
log.Fatal(err)
}
t := time.NewTicker(1 * time.Second)
for range t.C {
if err := mq.Publish("fermenter", "20.5"); err != nil {
log.Fatalln(err)
}
}
}
Output:
Example (Subscriber) ¶
This example sets up a subscription to a topic and starts listening for messages from a device on the same network.
package main
import (
"fmt"
"log"
"github.com/olliephillips/efmq"
)
func main() {
mq, err := efmq.NewEFMQ("wlan0")
if err != nil {
log.Fatal(err)
}
mq.Subscribe("fermenter")
mq.Listen()
for msg := range mq.Message {
fmt.Println("topic:", msg.Topic)
fmt.Println("message:", msg.Payload)
}
}
Output: fermenter 20.5 fermenter 20.5 fermenter 20.5
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EFMQ ¶
type EFMQ struct {
Message chan Message
// contains filtered or unexported fields
}
EFQM represents a connection
func (*EFMQ) Listen ¶
func (mq *EFMQ) Listen()
Listen announces the subscriptions to which we are subscribed and then starts listener func in goroutine
func (*EFMQ) Publish ¶
Publish broadcasts a message on the network which comprises topic and payload
func (*EFMQ) Subscriptions ¶
Subscriptions returns list of topics currently subscribed to
func (*EFMQ) Unsubscribe ¶
Unsubscribe removes subscription from slice store