Skip to content

masgari/homie-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

# 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:

About

Homie MQTT convention in golang

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published