4 pubsub "github.com/tuxychandru/pubsub"
14 type spaceState struct {
16 buttonpress_until int64
20 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")
21 statusstate *spaceState = new(spaceState)
22 re_querystresc_ *regexp.Regexp = regexp.MustCompile("[^\x30-\x39\x41-\x7E]")
27 spaceapidata.AddSpaceFeed("calendar", "http://grical.realraum.at/s/?query=!realraum&view=rss")
28 spaceapidata.AddSpaceFeed("blog", "https://plus.google.com/113737596421797426873")
29 spaceapidata.AddSpaceFeed("wiki", "http://realraum.at/wiki")
30 spaceapidata.AddSpaceContactInfo("+43780700888524", "irc://irc.oftc.net/#realraum", "realraum@realraum.at", "realraum@realraum.at", "realraum@realraum.at", "vorstand@realraum.at")
34 func updateStatusString() {
35 var spacestatus string
36 if statusstate.present {
37 if statusstate.buttonpress_until > time.Now().Unix() {
38 spacestatus = "Panic! Present&Bored"
40 spacestatus = "Leute Anwesend"
43 spacestatus = "Keiner Da"
45 spaceapidata.SetStatus(statusstate.present, spacestatus)
48 func publishStateToWeb() {
50 jsondata_b, err := spaceapidata.MakeJSON()
52 log.Println("Error:", err)
55 //jsondata_b := re_querystresc_.ReplaceAllFunc(jsondata_b, func(in []byte) []byte {
56 // out := make([]byte, 4)
58 // copy(out[1:], []byte(strconv.FormatInt(int64(in[0]), 16)))
61 jsondata := url.QueryEscape(string(jsondata_b))
62 resp, err := http.Get("http://www.realraum.at/cgi/status.cgi?pass=jako16&set=" + jsondata)
64 log.Println("Error publishing realraum info", err)
70 func EventToWeb(ps *pubsub.PubSub) {
71 events := ps.Sub("presence","door","sensors","buttons","updateinterval")
73 for eventinterface := range(events) {
74 switch event := eventinterface.(type) {
78 statusstate.present = event.Present
80 case DoorStatusUpdate:
81 spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterLock", "Türschloß", event.Locked))
82 spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterAjarSensor", "Türkontakt", event.Shut))
84 case ButtonPressUpdate:
85 statusstate.buttonpress_until = event.Ts + 3600
86 spaceapidata.AddSpaceEvent("PanicButton", "check-in", "The button has been pressed")
88 case TempSensorUpdate:
89 spaceapidata.MergeInSensor(spaceapi.MakeTempCSensor("Temp0","Decke", event.Value))
90 case IlluminationSensorUpdate:
91 spaceapidata.MergeInSensor(spaceapi.MakeIlluminationSensor("Photodiode","Decke","1024V/5V", event.Value))