start making kiosk mode

This commit is contained in:
Mike Bloy 2024-09-15 00:51:34 -05:00
parent d7ea0508cf
commit d22da95cce
3 changed files with 56 additions and 7 deletions

29
kiosk/kiosk.go Normal file
View 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
View 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) {
}

View File

@ -1,7 +0,0 @@
package mqtt
import mqtt "github.com/eclipse/paho.mqtt.golang"
func init() {
mqtt.NewClient()
}