X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=go%2Fr3-netstatus%2Fmain.go;h=0af7ef85823c5c122bf1bfdb0065adcc38d4de58;hb=0ae7860ca033f98cfb98721ebb0d4b2b42700d40;hp=a2917a579921ad850224cdb9fc357793f1e1502f;hpb=a8e0651d52192d208758ae9a59e21af313685da4;p=svn42.git diff --git a/go/r3-netstatus/main.go b/go/r3-netstatus/main.go index a2917a5..0af7ef8 100644 --- a/go/r3-netstatus/main.go +++ b/go/r3-netstatus/main.go @@ -9,7 +9,7 @@ import ( "time" "fmt" //~ "./brain" - r3events "svn.spreadspace.org/realraum/go.svn/r3-eventbroker_zmq/r3events" + r3events "svn.spreadspace.org/realraum/go.svn/r3events" ) type SpaceState struct { @@ -27,6 +27,7 @@ var ( r3eventssub_port_ string button_press_timeout_ int64 = 3600 brain_connect_addr_ string + enable_syslog_, enable_debug_ bool ) //------- @@ -38,6 +39,8 @@ 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() } @@ -61,7 +64,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_) } @@ -78,7 +81,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 @@ -114,7 +117,17 @@ func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface } } +func ParseZMQr3Event(lines [][]byte, ps *pubsub.PubSub) { + evnt, pubsubcat, err := r3events.UnmarshalByteByte2Event(lines) + if err != nil { return } + ps.Pub(evnt, pubsubcat) +} + func main() { + if enable_syslog_ { LogEnableSyslog(); r3xmppbot.LogEnableSyslog() } + if enable_debug_ { LogEnableDebuglog(); r3xmppbot.LogEnableDebuglog() } + Syslog_.Print("started") + defer Syslog_.Print("exiting") zmqctx, zmqsub := ZmqsInit(r3eventssub_port_) defer zmqctx.Close() if zmqsub != nil {defer zmqsub.Close()} @@ -138,12 +151,12 @@ func main() { } else { fmt.Println(xmpperr) fmt.Println("XMPP Bot disabled") + Syslog_.Printf("XMPP Bot disabled due to error: %s", xmpperr.Error()) } // --- 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) }