X-Git-Url: https://git.realraum.at/?p=svn42.git;a=blobdiff_plain;f=listen_to_events.py;fp=listen_to_events.py;h=0000000000000000000000000000000000000000;hp=107a61071d2be3f734d311c5ffdc6e8e7135fdf8;hb=c775b5528f8f96e75c28264b9cea8525c6da9298;hpb=a87c91b7d4544703879b7ef6e472b863765e3949 diff --git a/listen_to_events.py b/listen_to_events.py deleted file mode 100755 index 107a610..0000000 --- a/listen_to_events.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -import os -import os.path -import sys -import signal -import zmq.utils.jsonapi as json -import zmq -######################## - -def decodeR3Message(multipart_msg): - try: - return (multipart_msg[0], json.loads(multipart_msg[1])) - except Exception, e: - logging.debug("decodeR3Message:"+str(e)) - return ("",{}) - -def exitHandler(signum, frame): - try: - zmqsub.close() - zmqctx.destroy() - except: - pass - sys.exit(0) - -signal.signal(signal.SIGINT, exitHandler) -signal.signal(signal.SIGQUIT, exitHandler) - -while True: - try: - #Start zmq connection to publish / forward sensor data - zmqctx = zmq.Context() - zmqctx.linger = 0 - zmqsub = zmqctx.socket(zmq.SUB) - zmqsub.setsockopt(zmq.SUBSCRIBE, "") - zmqsub.connect("tcp://torwaechter.realraum.at:4244") - - while True: - - data = zmqsub.recv_multipart() - (structname, dictdata) = decodeR3Message(data) - print "Got data: " + structname + ":"+ str(dictdata) - - except Exception, ex: - logging.error("main: "+str(ex)) - traceback.print_exc(file=sys.stdout) - try: - zmqsub.close() - zmqctx.destroy() - except: - pass - time.sleep(5)