15 type SpaceState struct {
17 buttonpress_until int64
21 re_presence_ *regexp.Regexp = regexp.MustCompile("Presence: (yes|no)(?:, (opened|closed), (.+))?")
22 re_status_ *regexp.Regexp = regexp.MustCompile("Status: (closed|opened), (opening|waiting|closing|idle), (ajar|shut).*")
23 re_button_ *regexp.Regexp = regexp.MustCompile("PanicButton|button\\d?")
24 re_temp_ *regexp.Regexp = regexp.MustCompile("temp0: (\\d+\\.\\d+)")
25 re_photo_ *regexp.Regexp = regexp.MustCompile("photo0: (\\d+)")
26 re_querystresc_ *regexp.Regexp = regexp.MustCompile("[^\x30-\x39\x41-\x7E]")
27 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")
28 statusstate *SpaceState = new(SpaceState)
33 func updateStatusString() {
34 var spacestatus string
35 if statusstate.present {
36 if statusstate.buttonpress_until > time.Now().Unix() {
37 spacestatus = "Panic! Present&Bored"
39 spacestatus = "Leute Anwesend"
42 spacestatus = "Keiner Da"
44 spaceapidata.SetStatus(statusstate.present, spacestatus)
47 func publishStateToWeb() {
49 jsondata_b, err := spaceapidata.MakeJSON()
51 fmt.Println("Error:", err)
54 //jsondata_b := re_querystresc_.ReplaceAllFunc(jsondata_b, func(in []byte) []byte {
55 // out := make([]byte, 4)
57 // copy(out[1:], []byte(strconv.FormatInt(int64(in[0]), 16)))
60 jsondata := url.QueryEscape(string(jsondata_b))
61 resp, err := http.Get("http://www.realraum.at/cgi/status.cgi?pass=jako16&set=" + jsondata)
63 fmt.Println("Error publishing realraum info", err)
66 defer resp.Body.Close()
69 func parseSocketInputLine(line string) {
70 match_presence := re_presence_.FindStringSubmatch(line)
71 match_status := re_status_.FindStringSubmatch(line)
72 match_button := re_button_.FindStringSubmatch(line)
73 match_temp := re_temp_.FindStringSubmatch(line)
74 match_photo := re_photo_.FindStringSubmatch(line)
76 if match_presence != nil {
77 statusstate.present = (match_presence[1] == "yes")
78 //spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("Torwaechter", "Front Door", match_presence[2] == "closed"))
79 spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterLock", "Türschloß", match_presence[2] == "closed"))
81 } else if match_status != nil {
82 spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterLock", "Türschloß", match_status[1] == "closed"))
83 spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterAjarSensor", "Türkontakt", match_status[3] == "shut"))
84 //spaceapidata.MergeInSensor(spaceapi.MakeDoorAjarSensor("Torwaechter", "Front Door", match_presence[3] == "shut"))
86 } else if match_button != nil {
87 statusstate.buttonpress_until = time.Now().Unix() + 3600
88 spaceapidata.AddSpaceEvent("PanicButton", "check-in", "The button has been pressed")
90 } else if match_temp != nil {
91 newtemp, err := strconv.ParseFloat((match_temp[1]), 32)
93 spaceapidata.MergeInSensor(spaceapi.MakeTempCSensor("Temp0","Decke",newtemp))
95 } else if match_photo != nil {
96 newphoto, err := strconv.ParseInt(match_photo[1], 10, 32)
98 spaceapidata.MergeInSensor(spaceapi.MakeIlluminationSensor("Photodiode","Decke","1024V/5V",newphoto))
103 func readFromUSocket(path string, c chan string) {
106 presence_socket, err := net.Dial("unix", path)
109 time.Sleep(5 * time.Second)
110 continue ReOpenSocket
112 presence_reader := bufio.NewReader(presence_socket)
114 line, err := presence_reader.ReadString('\n')
117 presence_socket.Close()
118 continue ReOpenSocket
126 spaceapidata.AddSpaceFeed("calendar", "http://grical.realraum.at/s/?query=!realraum&view=rss")
127 spaceapidata.AddSpaceFeed("blog", "https://plus.google.com/113737596421797426873")
128 spaceapidata.AddSpaceFeed("wiki", "http://realraum.at/wiki")
129 spaceapidata.AddSpaceContactInfo("+43780700888524", "irc://irc.oftc.net/#realraum", "realraum@realraum.at", "realraum@realraum.at", "realraum@realraum.at", "vorstand@realraum.at")
130 eventqueue := make(chan string)
131 ticker := time.NewTicker(time.Duration(7) * time.Minute)
132 go readFromUSocket("/var/run/tuer/presence.socket", eventqueue)
135 case e := <-eventqueue:
136 parseSocketInputLine(e)
144 * Read config from an .ini file