/homie-go

Homie MQTT convention in golang

Primary LanguageGo

# homie-go

Homie (https://homieiot.github.io/specification/) MQTT convention in golang.

Example

package main

import (
	"time"

	homie "github.com/masgari/homie-go/homie"
)

func main() {
	device := homie.NewDevice("homie-go", &homie.Config{
		Mqtt: homie.MqttConfig{
			Host:     "localhost",
			Port:     1883,
			Username: "user",
			Password: "password",
		},
		BaseTopic:           "devices/",
		StatsReportInterval: 60,
	})

	timeNode := device.NewNode("time", "TimeNode")
	timeNode.NewProperty("currentTime", "time")

	publisher := homie.NewPeriodicPublisher(1 * time.Second)
	publisher.AddNodePublisher(timeNode, func(n homie.Node) {
		n.GetProperty("currentTime").
			SetValue(time.Now().String())
		n.Publish()
	})

	device.Run(true) // block forever
}

More examples: