start making kiosk mode
This commit is contained in:
parent
d7ea0508cf
commit
d22da95cce
29
kiosk/kiosk.go
Normal file
29
kiosk/kiosk.go
Normal file
@ -0,0 +1,29 @@
|
||||
package kiosk
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type handler func(area string, present bool)
|
||||
|
||||
type configObj struct {
|
||||
logger *slog.Logger
|
||||
broker string
|
||||
username string
|
||||
password string
|
||||
presenceTopic string
|
||||
}
|
||||
|
||||
var config = configObj{}
|
||||
|
||||
func Run(rootLogger *slog.Logger, exitch chan bool) {
|
||||
config.logger = rootLogger.With("component", "kiosk")
|
||||
config.broker = viper.GetString("mqtt_broker_url")
|
||||
config.username = viper.GetString("mqtt_broker_user")
|
||||
config.password = viper.GetString("mqtt_broker_password")
|
||||
config.presenceTopic = viper.GetString("mqtt_presence_topic")
|
||||
brokerConsume()
|
||||
exitch <- true
|
||||
}
|
||||
27
kiosk/mqtt.go
Normal file
27
kiosk/mqtt.go
Normal file
@ -0,0 +1,27 @@
|
||||
package kiosk
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
MQTT "github.com/eclipse/paho.mqtt.golang"
|
||||
)
|
||||
|
||||
func brokerConsume() {
|
||||
opts := MQTT.NewClientOptions()
|
||||
opts.AddBroker(config.broker)
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
opts.SetClientID(fmt.Sprintf("hasskiosk-%s-%d", hostname, os.Getpid()))
|
||||
opts.SetUsername(config.username)
|
||||
opts.SetPassword(config.password)
|
||||
opts.SetDefaultPublishHandler(func(client MQTT.Client, msg MQTT.Message) {
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func defaultMQTTHandler(client MQTT.Client, msg MQTT.Message) {
|
||||
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
package mqtt
|
||||
|
||||
import mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
|
||||
func init() {
|
||||
mqtt.NewClient()
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user