feat(mqtt): SendDisplayCommand mit retained QoS 1
This commit is contained in:
parent
c359757e31
commit
0d51d951a2
1 changed files with 16 additions and 0 deletions
|
|
@ -95,6 +95,22 @@ func (n *Notifier) RequestScreenshot(screenSlug string) {
|
||||||
token.WaitTimeout(3 * time.Second)
|
token.WaitTimeout(3 * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendDisplayCommand publiziert einen Display-Befehl (display_on/display_off)
|
||||||
|
// auf das Command-Topic des Screens. Retained + QoS 1, damit der Agent den
|
||||||
|
// letzten Sollzustand auch nach einem Reconnect erhält.
|
||||||
|
func (n *Notifier) SendDisplayCommand(screenSlug, action string) error {
|
||||||
|
if n.client == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
topic := fmt.Sprintf("signage/screen/%s/command", screenSlug)
|
||||||
|
payload := []byte(fmt.Sprintf(`{"action":%q}`, action))
|
||||||
|
token := n.client.Publish(topic, 1, true, payload)
|
||||||
|
if !token.WaitTimeout(5 * time.Second) {
|
||||||
|
return fmt.Errorf("mqtt publish display command: timeout")
|
||||||
|
}
|
||||||
|
return token.Error()
|
||||||
|
}
|
||||||
|
|
||||||
func (n *Notifier) publish(screenSlug string) {
|
func (n *Notifier) publish(screenSlug string) {
|
||||||
topic := Topic(screenSlug)
|
topic := Topic(screenSlug)
|
||||||
payload := []byte(fmt.Sprintf(`{"ts":%d}`, time.Now().UnixMilli()))
|
payload := []byte(fmt.Sprintf(`{"ts":%d}`, time.Now().UnixMilli()))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue