--bug
[svn42.git] / sensorvalues-to-json-zmq.py
index 6608086..e2ed5d6 100755 (executable)
@@ -48,7 +48,7 @@ class UWSConfig:
     self.config_parser.set('zmq','remote_uri',"tcp://wuzzler.realraum.at:4244")
     self.config_parser.set('zmq','sshtunnel',"realraum@wuzzler.realraum.at:22000")
     self.config_parser.set('zmq','sshkeyfile',"/home/guests/realraum.wirdorange.org/id_rsa")
-    self.config_parser.set('zmq','subscribe',"TempSensorUpdate IlluminationSensorUpdate DustSensorUpdate RelativeHumiditySensorUpdate MovementSensorUpdate PresenceUpdate")
+    self.config_parser.set('zmq','subscribe',"TempSensorUpdate IlluminationSensorUpdate DustSensorUpdate RelativeHumiditySensorUpdate MovementSensorUpdate")
     self.config_parser.add_section('debug')
     self.config_parser.set('debug','enabled',"False")
     self.config_mtime=0
@@ -246,15 +246,26 @@ if __name__ == "__main__":
 
     try:
         with open(uwscfg.json_moveto_path,"rb") as fh:
-            sensor_store = json.loads(fh.read())
+            sensor_store_ = json.loads(fh.read())
     except Exception, e:
         logging.debug(e)
         try:
             with open(uwscfg.json_backup_path,"rb") as fh:
-                sensor_store = json.loads(fh.read())
+                sensor_store_ = json.loads(fh.read())
         except Exception, e:
             logging.debug(e)
 
+
+    for k in set(sensor_store_.keys()).difference(set(uwscfg.zmq_subscribe.split(" "))):
+      del sensor_store_[k]  # del old sensordata of sensor we do not subscribe to
+
+    for k in sensor_store_.keys():
+      try:
+       if len(sensor_store_[k][0]) > 1:
+          sensor_cols_num_[k] = len(sensor_store_[k][0]) -1
+      except:
+        pass
+
     while True:
       try:
         #Start zmq connection to publish / forward sensor data
@@ -291,7 +302,7 @@ if __name__ == "__main__":
             cleanTempLastValueOfMovementValues()
 
             backup_counter += 1
-            # save sensor_store to json for apache
+            # save sensor_store_ to json for apache
             with open(uwscfg.json_write_path,"wb") as fh:
                 fh.truncate()
                 fh.write(json.dumps(sensor_store_))