16 type SpaceState struct {
18 buttonpress_until int64
24 re_presence_ *regexp.Regexp = regexp.MustCompile("Presence: (yes|no)(?:, (opened|closed), (.+))?")
25 re_status_ *regexp.Regexp = regexp.MustCompile("Status: (closed|opened), (opening|waiting|closing|idle), (ajar|shut).*")
26 re_button_ *regexp.Regexp = regexp.MustCompile("PanicButton|button\\d?")
27 re_temp_ *regexp.Regexp = regexp.MustCompile("temp0: (\\d+\\.\\d+)")
28 re_photo_ *regexp.Regexp = regexp.MustCompile("photo0: (\\d+)")
29 re_querystresc_ *regexp.Regexp = regexp.MustCompile("[^\x30-\x39\x41-\x7E]")
30 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.065779129, 15.442322614).AddSpaceAddress("Jakoministr. 16 ground level left, 8010 Graz, Austria")
31 statusstate *SpaceState = new(SpaceState)
32 xmpp_presence_events_chan_ chan interface{}
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 fmt.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 fmt.Println("Error publishing realraum info", err)
70 defer resp.Body.Close()
73 func parseSocketInputLine(line string) {
74 match_presence := re_presence_.FindStringSubmatch(line)
75 match_status := re_status_.FindStringSubmatch(line)
76 match_button := re_button_.FindStringSubmatch(line)
77 match_temp := re_temp_.FindStringSubmatch(line)
78 match_photo := re_photo_.FindStringSubmatch(line)
80 if match_presence != nil {
81 statusstate.present = (match_presence[1] == "yes")
82 statusstate.door_locked = (match_presence[2] == "closed")
83 //spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("Torwaechter", "Front Door", match_presence[2] == "closed"))
84 spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterLock", "Türschloß", statusstate.door_locked))
86 xmpp_presence_events_chan_ <- r3xmppbot.PresenceEvent{statusstate.present, statusstate.door_locked, statusstate.door_shut}
87 } else if match_status != nil {
88 statusstate.door_locked = (match_status[1] == "closed")
89 statusstate.door_shut = (match_status[3] == "shut")
90 spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterLock", "Türschloß", statusstate.door_locked))
91 spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterAjarSensor", "Türkontakt", statusstate.door_shut))
92 //spaceapidata.MergeInSensor(spaceapi.MakeDoorAjarSensor("Torwaechter", "Front Door", match_presence[3] == "shut"))
94 xmpp_presence_events_chan_ <- r3xmppbot.PresenceEvent{statusstate.present, statusstate.door_locked, statusstate.door_shut}
95 } else if match_button != nil {
96 statusstate.buttonpress_until = time.Now().Unix() + 3600
97 spaceapidata.AddSpaceEvent("PanicButton", "check-in", "The button has been pressed")
99 xmpp_presence_events_chan_ <- "The button has been pressed ! Propably someone is bored and need company ! ;-)"
100 } else if match_temp != nil {
101 newtemp, err := strconv.ParseFloat((match_temp[1]), 32)
103 spaceapidata.MergeInSensor(spaceapi.MakeTempCSensor("Temp0","Decke",newtemp))
105 } else if match_photo != nil {
106 newphoto, err := strconv.ParseInt(match_photo[1], 10, 32)
108 spaceapidata.MergeInSensor(spaceapi.MakeIlluminationSensor("Photodiode","Decke","1024V/5V",newphoto))
113 func readFromUSocket(path string, c chan string) {
116 presence_socket, err := net.Dial("unix", path)
119 time.Sleep(5 * time.Second)
120 continue ReOpenSocket
122 presence_reader := bufio.NewReader(presence_socket)
124 line, err := presence_reader.ReadString('\n')
127 presence_socket.Close()
128 continue ReOpenSocket
136 spaceapidata.AddSpaceFeed("calendar", "http://grical.realraum.at/s/?query=!realraum&view=rss")
137 spaceapidata.AddSpaceFeed("blog", "https://plus.google.com/113737596421797426873")
138 spaceapidata.AddSpaceFeed("wiki", "http://realraum.at/wiki")
139 spaceapidata.AddSpaceContactInfo("+43780700888524", "irc://irc.oftc.net/#realraum", "realraum@realraum.at", "realraum@realraum.at", "realraum@realraum.at", "vorstand@realraum.at")
142 var bot *r3xmppbot.XmppBot
143 bot, xmpp_presence_events_chan_, err = r3xmppbot.NewStartedBot("realrauminfo@realraum.at/Tuer", "d7ynC6Dg", "r3alraumOLGAXMPPInfos", true)
150 //~ presence_events <- PresenceEvent{true, true, true}
151 //~ presence_events <- PresenceEvent{true, true, false}
152 //~ presence_events <- PresenceEvent{true, false, false}
155 eventqueue := make(chan string)
156 defer close(eventqueue)
158 ticker := time.NewTicker(time.Duration(7) * time.Minute)
159 go readFromUSocket("/var/run/tuer/presence.socket", eventqueue)
162 case e := <-eventqueue:
163 parseSocketInputLine(e)
171 * Read config from an .ini file