X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=go%2Fr3-netstatus%2Fmain.go;h=b65e96e8c01f9b04c379134afbf654e384a7949d;hb=b7182b7f1d5dae86d81310beaa6ce6d693696572;hp=f3877895cfac151847bf7f810f559e8d158927f2;hpb=ff98cdc53bc87b9d4f3215df248c188a84cb2fb1;p=svn42.git diff --git a/go/r3-netstatus/main.go b/go/r3-netstatus/main.go index f387789..b65e96e 100644 --- a/go/r3-netstatus/main.go +++ b/go/r3-netstatus/main.go @@ -27,6 +27,7 @@ var ( r3eventssub_port_ string button_press_timeout_ int64 = 3600 brain_connect_addr_ string + enable_syslog_, enable_debug_ bool ) //------- @@ -38,7 +39,11 @@ func init() { 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.BoolVar(&enable_syslog_, "syslog", false, "enable logging to syslog") + flag.BoolVar(&enable_debug_, "debug", false, "enable debug logging") flag.Parse() + if enable_syslog_ { LogEnableSyslog(); r3xmppbot.LogEnableSyslog() } + if enable_debug_ { LogEnableDebuglog(); r3xmppbot.LogEnableDebuglog() } } //------- @@ -61,7 +66,7 @@ func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface defer func() { if x := recover(); x != nil { - fmt.Printf("handleIncomingXMPPStanzas: run time panic: %v", x) + Debug_.Printf("handleIncomingXMPPStanzas: run time panic: %v", x) ps.Unsub(events, "presence","door","buttons","updateinterval") close(xmpp_presence_events_chan_) } @@ -70,7 +75,7 @@ func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface var present, locked, shut bool = false, true, true var last_buttonpress int64 = 0 var who string - button_msg := "The button has been pressed ! Propably someone is bored and in need of company ! ;-)" + button_msg := "Dooom ! The button has been pressed ! Propably someone is bored and in need of company ! ;-)" present_status := r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowOnline,"Somebody is present"} notpresent_status := r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowNotAvailabe,"Nobody is here"} button_status := r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowFreeForChat, "The button has been pressed :-)"} @@ -78,7 +83,7 @@ func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface xmpp_presence_events_chan_ <- r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowNotAvailabe, "Nobody is here"} for eventinterface := range(events) { - fmt.Println("event2xmpp", eventinterface) + Debug_.Println("event2xmpp", eventinterface) switch event := eventinterface.(type) { case r3events.PresenceUpdate: present = event.Present @@ -101,7 +106,7 @@ func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface case r3events.DoorAjarUpdate: shut = event.Shut xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: composeMessage(present, locked, shut, who, event.Ts), DistributeLevel: r3xmppbot.R3DebugInfo, RememberAsStatus: true} - case r3events.ButtonPressUpdate: + case r3events.BoreDoomButtonPressEvent: xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: button_msg, DistributeLevel: r3xmppbot.R3OnlineOnlyInfo} xmpp_presence_events_chan_ <- button_status last_buttonpress = event.Ts @@ -138,12 +143,12 @@ func main() { } else { fmt.Println(xmpperr) fmt.Println("XMPP Bot disabled") + Syslog_.Printf("XMPP Bot disabled due to error: %s", xmpperr) } // --- 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) }