15 type SpaceState struct {
17 buttonpress_until int64
21 re_presence_ *regexp.Regexp = regexp.MustCompile("Presence: (yes|no)(?:, (opened|closed), (.+))?")
22 re_button_ *regexp.Regexp = regexp.MustCompile("PanicButton|button\\d?")
23 re_temp_ *regexp.Regexp = regexp.MustCompile("temp0: (\\d+\\.\\d+)")
24 re_photo_ *regexp.Regexp = regexp.MustCompile("photo0: (\\d+)")
25 re_querystresc_ *regexp.Regexp = regexp.MustCompile("[^\x30-\x39\x41-\x7E]")
26 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")
27 statusstate *SpaceState = new(SpaceState)
32 func updateStatusString() {
33 var spacestatus string
34 if statusstate.present {
35 if statusstate.buttonpress_until > time.Now().Unix() {
36 spacestatus = "Panic! Present&Bored"
38 spacestatus = "Leute Anwesend"
41 spacestatus = "Keiner Da"
43 spaceapidata.SetStatus(statusstate.present, spacestatus)
46 func publishStateToWeb() {
48 jsondata_b, err := spaceapidata.MakeJSON()
50 fmt.Println("Error:", err)
53 //jsondata_b := re_querystresc_.ReplaceAllFunc(jsondata_b, func(in []byte) []byte {
54 // out := make([]byte, 4)
56 // copy(out[1:], []byte(strconv.FormatInt(int64(in[0]), 16)))
59 jsondata := url.QueryEscape(string(jsondata_b))
60 resp, err := http.Get("http://www.realraum.at/cgi/status.cgi?pass=jako16&set=" + jsondata)
62 fmt.Println("Error publishing realraum info", err)
65 defer resp.Body.Close()
68 func parseSocketInputLine(line string) {
69 match_presence := re_presence_.FindStringSubmatch(line)
70 match_button := re_button_.FindStringSubmatch(line)
71 match_temp := re_temp_.FindStringSubmatch(line)
72 match_photo := re_photo_.FindStringSubmatch(line)
74 if match_presence != nil {
75 statusstate.present = (match_presence[1] == "yes")
76 spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("Torwaechter", "Front Door", match_presence[2] == "closed"))
78 } else if match_button != nil {
79 statusstate.buttonpress_until = time.Now().Unix() + 3600
80 spaceapidata.AddSpaceEvent("PanicButton", "check-in", "The button has been pressed")
82 } else if match_temp != nil {
83 newtemp, err := strconv.ParseFloat((match_temp[1]), 32)
85 spaceapidata.MergeInSensor(spaceapi.MakeTempCSensor("Temp0","Ceiling",newtemp))
87 } else if match_photo != nil {
88 newphoto, err := strconv.ParseInt(match_photo[1], 10, 32)
90 spaceapidata.MergeInSensor(spaceapi.MakeIlluminationSensor("Photodiode","Ceiling","1024V/5V",newphoto))
95 func readFromUSocket(path string, c chan string) {
98 presence_socket, err := net.Dial("unix", path)
101 time.Sleep(5 * time.Second)
102 continue ReOpenSocket
104 presence_reader := bufio.NewReader(presence_socket)
106 line, err := presence_reader.ReadString('\n')
109 presence_socket.Close()
110 continue ReOpenSocket
118 spaceapidata.AddSpaceFeed("calendar", "application/rss+xml", "http://grical.realraum.at/s/?query=!realraum&view=rss")
119 spaceapidata.AddSpaceFeed("google+", "text/html", "https://plus.google.com/113737596421797426873")
120 spaceapidata.AddSpaceContactInfo("+43780700888524", "irc://irc.oftc.net/#realraum", "realraum@realraum.at", "realraum@realraum.at", "realraum@realraum.at", "vorstand@realraum.at")
121 eventqueue := make(chan string)
122 ticker := time.NewTicker(time.Duration(15) * time.Minute)
123 go readFromUSocket("/var/run/tuer/presence.socket", eventqueue)
126 case e := <-eventqueue:
127 parseSocketInputLine(e)
135 * Read config from an .ini file