X-Git-Url: https://git.realraum.at/?p=svn42.git;a=blobdiff_plain;f=go%2Fr3-netstatus%2Fmain.go;h=f3877895cfac151847bf7f810f559e8d158927f2;hp=ff94189eb58a5fa9f2f214b9dccb10d3ed64898d;hb=ff98cdc53bc87b9d4f3215df248c188a84cb2fb1;hpb=2416b163f05370fcffb2f62bea000265d10aac42 diff --git a/go/r3-netstatus/main.go b/go/r3-netstatus/main.go index ff94189..f387789 100644 --- a/go/r3-netstatus/main.go +++ b/go/r3-netstatus/main.go @@ -26,6 +26,7 @@ var ( xmpp_state_save_dir_ string r3eventssub_port_ string button_press_timeout_ int64 = 3600 + brain_connect_addr_ string ) //------- @@ -36,6 +37,7 @@ func init() { flag.StringVar(&xmpp_bot_authstring_, "xbotauth", "", "String that user use to authenticate themselves to the bot") flag.StringVar(&xmpp_state_save_dir_,"xstatedir","/flash/var/lib/r3netstatus/", "Directory to save XMPP bot state in") flag.StringVar(&r3eventssub_port_, "eventsubport", "tcp://wuzzler.realraum.at:4244", "zmq address to subscribe r3events") + flag.StringVar(&brain_connect_addr_, "brainconnect", "tcp://wuzzler.realraum.at:4245", "address to ask about most recent stored events") flag.Parse() } @@ -123,6 +125,7 @@ func main() { var xmpperr error var bot *r3xmppbot.XmppBot bot, xmpp_presence_events_chan_, xmpperr = r3xmppbot.NewStartedBot(xmpp_login_.jid, xmpp_login_.pass, xmpp_bot_authstring_, xmpp_state_save_dir_, true) + ps := pubsub.New(1) defer ps.Shutdown() //~ brn := brain.New() @@ -137,8 +140,15 @@ func main() { fmt.Println("XMPP Bot disabled") } - ticker := time.NewTicker(time.Duration(7) * time.Minute) + // --- get update on most recent events --- + answ := ZmqsAskQuestionsAndClose(zmqctx, brain_connect_addr_, [][][]byte{[][]byte{[]byte("DoorLockUpdate")}, [][]byte{[]byte("DoorAjarUpdate")}, [][]byte{[]byte("DoorCommandEvent")}, [][]byte{[]byte("PresenceUpdate")}, [][]byte{[]byte("IlluminationSensorUpdate")}, [][]byte{[]byte("TempSensorUpdate")}}) + for _, a := range(answ) { + //~ fmt.Println("recent event:", a) + ParseZMQr3Event(a, ps) + } + // --- receive and distribute events --- + ticker := time.NewTicker(time.Duration(7) * time.Minute) for { select { case e := <-zmqsub.In():