From a5a4ac7a8733c31c14065230127c7836ac0de4f6 Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Tue, 18 Jun 2013 00:33:50 +0000 Subject: [PATCH] update spaceapi code for ajar/shut --- r3-webstatus-spaceapi/main.go | 15 +++++++++++---- raspberry-kiosk/kiosk.js | 32 +++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/r3-webstatus-spaceapi/main.go b/r3-webstatus-spaceapi/main.go index 114777e..f4e4e76 100644 --- a/r3-webstatus-spaceapi/main.go +++ b/r3-webstatus-spaceapi/main.go @@ -19,6 +19,7 @@ type SpaceState struct { var ( re_presence_ *regexp.Regexp = regexp.MustCompile("Presence: (yes|no)(?:, (opened|closed), (.+))?") + re_status_ *regexp.Regexp = regexp.MustCompile("Status: (closed|opened), (opening|waiting|closing|idle), (ajar|shut).*") re_button_ *regexp.Regexp = regexp.MustCompile("PanicButton|button\\d?") re_temp_ *regexp.Regexp = regexp.MustCompile("temp0: (\\d+\\.\\d+)") re_photo_ *regexp.Regexp = regexp.MustCompile("photo0: (\\d+)") @@ -67,14 +68,20 @@ func publishStateToWeb() { func parseSocketInputLine(line string) { match_presence := re_presence_.FindStringSubmatch(line) + match_status := re_status_.FindStringSubmatch(line) match_button := re_button_.FindStringSubmatch(line) match_temp := re_temp_.FindStringSubmatch(line) match_photo := re_photo_.FindStringSubmatch(line) if match_presence != nil { statusstate.present = (match_presence[1] == "yes") - spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("Torwaechter", "Front Door", match_presence[2] == "closed")) + //spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("Torwaechter", "Front Door", match_presence[2] == "closed")) + spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterLock", "Türschloß", match_presence[2] == "closed")) publishStateToWeb() + } else if match_status != nil { + spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterLock", "Türschloß", match_status[1] == "closed")) + spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterAjarSensor", "Türkontakt", match_status[3] == "shut")) + //spaceapidata.MergeInSensor(spaceapi.MakeDoorAjarSensor("Torwaechter", "Front Door", match_presence[3] == "shut")) } else if match_button != nil { statusstate.buttonpress_until = time.Now().Unix() + 3600 spaceapidata.AddSpaceEvent("PanicButton", "check-in", "The button has been pressed") @@ -82,12 +89,12 @@ func parseSocketInputLine(line string) { } else if match_temp != nil { newtemp, err := strconv.ParseFloat((match_temp[1]), 32) if err == nil { - spaceapidata.MergeInSensor(spaceapi.MakeTempCSensor("Temp0","Ceiling",newtemp)) + spaceapidata.MergeInSensor(spaceapi.MakeTempCSensor("Temp0","Decke",newtemp)) } } else if match_photo != nil { newphoto, err := strconv.ParseInt(match_photo[1], 10, 32) if err == nil { - spaceapidata.MergeInSensor(spaceapi.MakeIlluminationSensor("Photodiode","Ceiling","1024V/5V",newphoto)) + spaceapidata.MergeInSensor(spaceapi.MakeIlluminationSensor("Photodiode","Decke","1024V/5V",newphoto)) } } } @@ -119,7 +126,7 @@ func main() { spaceapidata.AddSpaceFeed("google+", "text/html", "https://plus.google.com/113737596421797426873") spaceapidata.AddSpaceContactInfo("+43780700888524", "irc://irc.oftc.net/#realraum", "realraum@realraum.at", "realraum@realraum.at", "realraum@realraum.at", "vorstand@realraum.at") eventqueue := make(chan string) - ticker := time.NewTicker(time.Duration(15) * time.Minute) + ticker := time.NewTicker(time.Duration(7) * time.Minute) go readFromUSocket("/var/run/tuer/presence.socket", eventqueue) for { select { diff --git a/raspberry-kiosk/kiosk.js b/raspberry-kiosk/kiosk.js index 0c90e4e..da4df77 100644 --- a/raspberry-kiosk/kiosk.js +++ b/raspberry-kiosk/kiosk.js @@ -166,41 +166,51 @@ function writeAnwesenheitStatus(data) html='
'+data.status+'
'; document.getElementById('anwesenheit_status').innerHTML=html; - if (data.sensors) +if (data.sensors) { if (data.sensors.temperature) { + sensorstd+='Temperatur'; $.each( data.sensors.temperature, function(s, sensorobj) { - sensorstd+='Temperatur
'+sensorobj.location+': '+sensorobj.value.toFixed(2)+sensorobj.unit+''; + sensorstd+='
'+sensorobj.location+': '+sensorobj.value.toFixed(2)+sensorobj.unit; }); + sensorstd+=''; } if (data.sensors.ext_illumination) { + sensorstd+='Licht'; $.each( data.sensors.ext_illumination, function(s, sensorobj) { - sensorstd+='Licht
'+sensorobj.location+': '+sensorobj.value+''; + sensorstd+='
'+sensorobj.location+': '+sensorobj.value; }); + sensorstd+=''; } if (data.sensors.door_locked) { + sensorstd+='Eingangstür'; $.each( data.sensors.door_locked, function(s, sensorobj) { - var lockstatus="Unlocked"; - if (sensorobj.value) { lockstatus = "Locked"; } - sensorstd+='Türschloß
'+sensorobj.location+': '+lockstatus+''; + var lockstatus="Auf"; + if (sensorobj.value) { lockstatus = "Zu"; } + sensorstd+='
'+sensorobj.location+': '+lockstatus; }); + sensorstd+=''; } if (data.sensors.ext_door_ajar) { + sensorstd+='Türkontakt'; $.each( data.sensors.ext_door_ajar, function(s, sensorobj) { - var lockstatus="Shut"; - if (sensorobj.value) { lockstatus = "Ajar"; } - sensorstd+='Türkontakt
'+sensorobj.location+': '+lockstatus+''; + var lockstatus="Auf"; + if (sensorobj.value) { lockstatus = "Zu"; } + sensorstd+='
'+sensorobj.location+': '+lockstatus; }); + sensorstd+=''; } if (data.sensors.ext_dust) { + sensorstd+='Staub'; $.each( data.sensors.ext_dust, function(s, sensorobj) { - sensorstd+='Staub
'+sensorobj.location+': '+sensorobj.value+sensorobj.unit+''; + sensorstd+='
'+sensorobj.location+': '+sensorobj.value+sensorobj.unit+''; }); + sensorstd+=''; } if (sensorstd != "") @@ -208,7 +218,7 @@ function writeAnwesenheitStatus(data) sensorshtml=''+sensorstd+'
'; document.getElementById('sensor_status').innerHTML=sensorshtml; } - } + } } function updateAnwesenheitStatus() -- 1.7.10.4