update spaceapi code for ajar/shut
authorBernhard Tittelbach <xro@realraum.at>
Tue, 18 Jun 2013 00:33:50 +0000 (00:33 +0000)
committerBernhard Tittelbach <xro@realraum.at>
Tue, 18 Jun 2013 00:33:50 +0000 (00:33 +0000)
r3-webstatus-spaceapi/main.go
raspberry-kiosk/kiosk.js

index 114777e..f4e4e76 100644 (file)
@@ -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 {
index 0c90e4e..da4df77 100644 (file)
@@ -166,41 +166,51 @@ function writeAnwesenheitStatus(data)
   html='<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100"><tr><td style="width:100px;"><img style="float:left;" src="'+iconuri+'" height="100" width="100"/></td><td style="width:4px;"></td><td class="anwesenheitsstatus" style="background-color:'+statuscolor+'; ">'+data.status+'</td></tr></table>';
   document.getElementById('anwesenheit_status').innerHTML=html;
 
-  if (data.sensors)
+if (data.sensors)
   {
     if (data.sensors.temperature)
     {
+      sensorstd+='<td style="background-color:white; height:42px; text-align:center; vertical-align:middle; display:table-cell;"><b>Temperatur</b>';
       $.each( data.sensors.temperature, function(s, sensorobj) {
-        sensorstd+='<td style="background-color:white; height:42px; text-align:center; vertical-align:middle; display:table-cell;"><b>Temperatur</b><br/>'+sensorobj.location+': '+sensorobj.value.toFixed(2)+sensorobj.unit+'</td>';
+        sensorstd+='<br/>'+sensorobj.location+': '+sensorobj.value.toFixed(2)+sensorobj.unit;
       });
+      sensorstd+='</td>';
     }
     if (data.sensors.ext_illumination)
     {
+      sensorstd+='<td style="background-color:white; height:42px; text-align:center; vertical-align:middle; display:table-cell;"><b>Licht</b>';
       $.each( data.sensors.ext_illumination, function(s, sensorobj) {
-        sensorstd+='<td style="background-color:white; height:42px; text-align:center; vertical-align:middle; display:table-cell;"><b>Licht</b><br/>'+sensorobj.location+': '+sensorobj.value+'</td>';
+        sensorstd+='<br/>'+sensorobj.location+': '+sensorobj.value;
       });
+      sensorstd+='</td>';
     }
     if (data.sensors.door_locked)
     {
+      sensorstd+='<td style="background-color:white; height:42px; text-align:center; vertical-align:middle; display:table-cell;"><b>Eingangstür</b>';
       $.each( data.sensors.door_locked, function(s, sensorobj)  {
-        var lockstatus="Unlocked";
-        if (sensorobj.value) { lockstatus = "Locked"; }
-        sensorstd+='<td style="background-color:white; height:42px; text-align:center; vertical-align:middle; display:table-cell;"><b>Türschloß</b><br/>'+sensorobj.location+': '+lockstatus+'</td>';
+        var lockstatus="Auf";
+        if (sensorobj.value) { lockstatus = "Zu"; }
+        sensorstd+='<br/>'+sensorobj.location+': '+lockstatus;
       });
+      sensorstd+='</td>';
     }
     if (data.sensors.ext_door_ajar)
     {
+      sensorstd+='<td style="background-color:white; height:42px; text-align:center; vertical-align:middle; display:table-cell;"><b>Türkontakt</b>';
       $.each( data.sensors.ext_door_ajar, function(s, sensorobj)  {
-        var lockstatus="Shut";
-        if (sensorobj.value) { lockstatus = "Ajar"; }
-        sensorstd+='<td style="background-color:white; height:42px; text-align:center; vertical-align:middle; display:table-cell;"><b>Türkontakt</b><br/>'+sensorobj.location+': '+lockstatus+'</td>';
+        var lockstatus="Auf";
+        if (sensorobj.value) { lockstatus = "Zu"; }
+        sensorstd+='<br/>'+sensorobj.location+': '+lockstatus;
       });
+      sensorstd+='</td>';
     }
     if (data.sensors.ext_dust)
     {
+      sensorstd+='<td style="background-color:white; height:42px; text-align:center; vertical-align:middle; display:table-cell;"><b>Staub</b>';
       $.each( data.sensors.ext_dust, function(s, sensorobj) {
-        sensorstd+='<td style="background-color:white; height:42px; text-align:center; vertical-align:middle; display:table-cell;"><b>Staub</b><br/>'+sensorobj.location+': '+sensorobj.value+sensorobj.unit+'</td>';
+        sensorstd+='<br/>'+sensorobj.location+': '+sensorobj.value+sensorobj.unit+'</td>';
       });
+      sensorstd+='</td>';
 
     }    
     if (sensorstd != "")
@@ -208,7 +218,7 @@ function writeAnwesenheitStatus(data)
       sensorshtml='<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>'+sensorstd+'</tr></table>';
       document.getElementById('sensor_status').innerHTML=sensorshtml;
     }
-  }  
+  }
 }
 
 function updateAnwesenheitStatus()