X-Git-Url: https://git.realraum.at/?p=svn42.git;a=blobdiff_plain;f=go%2Fr3-netstatus%2Fmain.go;h=66763ff7a816362320c9190f0f8ff811ef81f1a6;hp=c897e2953867df3b89ff709be16667cc839a34f2;hb=114821ef8e7567df37044ecd77b4d807216b0946;hpb=36c81737d355f02eb05b150472c9bf44fbf46120 diff --git a/go/r3-netstatus/main.go b/go/r3-netstatus/main.go index c897e29..66763ff 100644 --- a/go/r3-netstatus/main.go +++ b/go/r3-netstatus/main.go @@ -66,7 +66,7 @@ func composeDoorLockMessage(locked bool, frontshut r3events.DoorAjarUpdate, door } } -func EventToXMPP(events <- chan interface{}, xmpp_presence_events_chan chan <- interface{}) { +func EventToXMPP(bot *r3xmppbot.XmppBot, events <- chan interface{}, xmpp_presence_events_chan chan <- interface{}) { defer func() { if x := recover(); x != nil { @@ -120,6 +120,7 @@ func EventToXMPP(events <- chan interface{}, xmpp_presence_events_chan chan <- i xmpp_presence_events_chan <- present_status last_buttonpress = 0 } + case r3events.DoorProblemEvent: xmpp_presence_events_chan <- r3xmppbot.XMPPMsgEvent{Msg: fmt.Sprintf("Door Problem: %s. SeverityLevel: %d (%s)",event.Problem, event.Severity, time.Unix(event.Ts,0).String()), DistributeLevel: r3xmppbot.R3OnlineOnlyInfo, RememberAsStatus: false} } @@ -130,12 +131,16 @@ func RunXMPPBot(ps *pubsub.PubSub, zmqctx *zmq.Context) { var xmpperr error var bot *r3xmppbot.XmppBot var xmpp_presence_events_chan chan interface{} - psevents := ps.Sub("presence","door","buttons","updateinterval") for { bot, xmpp_presence_events_chan, xmpperr = r3xmppbot.NewStartedBot(xmpp_login_.jid, xmpp_login_.pass, xmpp_bot_authstring_, xmpp_state_save_dir_, true) if xmpperr == nil { + Syslog_.Printf("Successfully (re)started XMPP Bot") + // subscribe before QueryLatestEventsAndInjectThem and EventToXMPP + psevents := ps.Sub("presence","door","buttons","updateinterval") QueryLatestEventsAndInjectThem(ps, zmqctx) - EventToXMPP(psevents, xmpp_presence_events_chan) + EventToXMPP(bot, psevents, xmpp_presence_events_chan) + // unsubscribe right away, since we don't known when reconnect will succeed and we don't want to block PubSub + ps.Unsub(psevents, "presence","door","buttons","updateinterval") bot.StopBot() } else { Syslog_.Printf("Error starting XMPP Bot: %s", xmpperr.Error())