}
}
-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 {
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}
}
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())
my_login_password_ string
xmppclient_ *xmpp.Client
presence_events_ *chan interface{}
+ ping_reply_ chan bool
}
if inmsg.Body == nil || inmsg.GetHeader() == nil {
return
}
+ if inmsg.GetHeader().Error != nil {
+ Syslog_.Printf("XMPP Message Error: %s", inmsg.GetHeader().Error.Error())
+ }
bodytext :=inmsg.Body.Chardata
if botdata.isAuthenticated(inmsg.GetHeader().From) {
switch bodytext {
case *xmpp.Message:
botdata.handleIncomingMessageDialog(*stanza, xmppout, jabber_events)
case *xmpp.Presence:
- if stanza.GetHeader() == nil {
- continue
+ if stanza.GetHeader() == nil { continue }
+ if stanza.GetHeader().Error != nil {
+ Syslog_.Printf("XMPP Presence Error: %s", stanza.GetHeader().Error.Error())
}
switch stanza.GetHeader().Type {
case "subscribe":
jabber_events <- JabberEvent{stanza.GetHeader().From, true, R3NoChange, false}
}
case *xmpp.Iq:
- if stanza.GetHeader() == nil {
- continue
+ if stanza.GetHeader() == nil { continue }
+ if stanza.GetHeader().Error != nil {
+ Syslog_.Printf("XMPP Iq Error: %s", stanza.GetHeader().Error.Error())
}
}
}
botdata.my_jid_ = loginjid
botdata.my_login_password_ = loginpwd
botdata.auth_timeout_ = 3600*2
+ botdata.ping_reply_ = make(chan bool)
botdata.config_file_ = path.Join(state_save_dir, "r3xmpp."+removeJIDResource(loginjid)+".json")