1 // (c) Bernhard Tittelbach, 2013
6 pubsub "github.com/tuxychandru/pubsub"
13 r3events "svn.spreadspace.org/realraum/go.svn/r3events"
17 type spaceState struct {
19 buttonpress_until int64
23 spaceapidata spaceapi.SpaceInfo = spaceapi.NewSpaceInfo("realraum", "http://realraum.at", "http://realraum.at/logo-red_250x250.png", "http://realraum.at/logo-re_open_100x100.png", "http://realraum.at/logo-re_empty_100x100.png",47.065554, 15.450435).AddSpaceAddress("Brockmanngasse 15, 8010 Graz, Austria")
24 statusstate *spaceState = new(spaceState)
25 re_querystresc_ *regexp.Regexp = regexp.MustCompile("[^\x30-\x39\x41-\x7E]")
30 spaceapidata.AddSpaceFeed("calendar", "http://grical.realraum.at/s/?query=!realraum&view=rss")
31 spaceapidata.AddSpaceFeed("blog", "https://plus.google.com/113737596421797426873")
32 spaceapidata.AddSpaceFeed("wiki", "http://realraum.at/wiki")
33 spaceapidata.AddSpaceContactInfo("+43780700888524", "irc://irc.oftc.net/#realraum", "realraum@realraum.at", "realraum@realraum.at", "realraum@realraum.at", "vorstand@realraum.at")
37 func updateStatusString() {
38 var spacestatus string
39 if statusstate.present {
40 if statusstate.buttonpress_until > time.Now().Unix() {
41 spacestatus = "Panic! Present&Bored"
43 spacestatus = "Leute Anwesend"
46 spacestatus = "Keiner Da"
48 spaceapidata.SetStatus(statusstate.present, spacestatus)
51 func publishStateToWeb() {
53 jsondata_b, err := spaceapidata.MakeJSON()
55 Syslog_.Println("Error:", err)
58 //jsondata_b := re_querystresc_.ReplaceAllFunc(jsondata_b, func(in []byte) []byte {
59 // out := make([]byte, 4)
61 // copy(out[1:], []byte(strconv.FormatInt(int64(in[0]), 16)))
64 jsondata := url.QueryEscape(string(jsondata_b))
65 resp, err := http.Get("http://www.realraum.at/cgi/status.cgi?pass=jako16&set=" + jsondata)
67 Syslog_.Println("Error publishing realraum info", err)
73 func EventToWeb(ps *pubsub.PubSub) {
74 events := ps.Sub("presence","door","sensors","buttons","updateinterval")
76 for eventinterface := range(events) {
77 //Debug_.Printf("EventToWeb: %s" , eventinterface)
78 switch event := eventinterface.(type) {
79 case r3events.TimeTick:
81 case r3events.PresenceUpdate:
82 statusstate.present = event.Present
84 case r3events.BackdoorAjarUpdate:
85 spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("HintertorwaechterAjarSensor", "Hintertürkontakt", event.Shut))
87 case r3events.DoorAjarUpdate:
88 spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterAjarSensor", "Türkontakt", event.Shut))
90 case r3events.DoorLockUpdate:
91 spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterLock", "Türschloß", event.Locked))
93 case r3events.BoreDoomButtonPressEvent:
94 statusstate.buttonpress_until = event.Ts + 3600
95 spaceapidata.AddSpaceEvent("BoreDOOMButton", "check-in", "The button has been pressed")
97 case r3events.TempSensorUpdate:
98 var tempsensorlocation string
99 switch event.Sensorindex {
101 tempsensorlocation = "LoTHR"
103 tempsensorlocation = "CX"
105 tempsensorlocation = "Sonstwo"
107 spaceapidata.MergeInSensor(spaceapi.MakeTempCSensor(fmt.Sprintf("Temp%d",event.Sensorindex),tempsensorlocation, event.Value))
108 case r3events.IlluminationSensorUpdate:
109 spaceapidata.MergeInSensor(spaceapi.MakeIlluminationSensor("Photodiode","LoTHR","1024V/5V", event.Value))