I have this code in Python. (Add i'm not a great python-expert ;) )
With this I can output the content of the ZeroMQ-stream to a file. Only writing to a file every 10 seconds does not seem to be really useful and costs a lot of performance.
Now I would like to show the content in a web-page. I am not an extreme python expert, but I have learned that I can set up a web server with PyBottle.
How can I integrate
But do not I ( unnecessarily ) create a new web-server instance?
How can I handle this?
Or does anyone else have a good idea how to export the content of recent data from the stream to a browser?
Sample of
With this I can output the content of the ZeroMQ-stream to a file. Only writing to a file every 10 seconds does not seem to be really useful and costs a lot of performance.
Now I would like to show the content in a web-page. I am not an extreme python expert, but I have learned that I can set up a web server with PyBottle.
How can I integrate
PyBottle in my code, so it can output the latest message of the stream? I thought about the code of PyBottle in the **while**-loop.But do not I ( unnecessarily ) create a new web-server instance?
How can I handle this?
Or does anyone else have a good idea how to export the content of recent data from the stream to a browser?
Sample of
PyBottle: from bottle import route, run, template
@route( '/hello/<name>' )
def index( name ):
return template( '<b>Hello {{name}}</b>!', name = name )
run( host = 'localhost', port = 8080 )And my Python script, so far: #!/usr/bin/env python2
from gzip import GzipFile
from cStringIO import StringIO
from subprocess import call
pass; import zmq
context = zmq.Context()
subscriber = context.socket( zmq.XSUB )
subscriber.connect( "tcp://pubsub.*******.nl:7664" )
subscriber.send( chr( 0x01 ) # { 0x01: ZMQ_XSUB.subscribe,
+ "/RIG/VehiclePositions" # 0x00: ZMQ_XSUB.unsubscribe
) # }
while True:
multipart = subscriber.recv_multipart()
address = multipart[0]
contents = ''.join(multipart[1:])
contents = GzipFile( '', 'r', 0, StringIO( contents ) ).read()
filename = "tmp/treinpos.txt"
file = open( filename, "w" )
file.write( contents )
file.close()
subscriber.close()
context.term()




thanks for the post snippsat. I used your example (with data changes) to use flask on my Raspberry Pi 2 with a Sense Hat to have a dynamic webpage which automatically updates Humidity, Temp, Barometric Pressure, and other data. It worked marvelously!!