misp-dashboard/zmq_subscriber.py

71 lines
1.8 KiB
Python
Raw Normal View History

#!/usr/bin/env python3.5
import time
import zmq
import redis
import random
import configparser
import os
import sys
import json
configfile = os.path.join(os.environ['VIRTUAL_ENV'], '../config.cfg')
cfg = configparser.ConfigParser()
cfg.read(configfile)
2017-10-11 10:47:11 +02:00
zmq_url = cfg.get('RedisLog', 'zmq_url')
zmq_url = "tcp://crf.circl.lu:5556"
2017-10-11 10:47:11 +02:00
channel = cfg.get('RedisLog', 'channel')
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect(zmq_url)
socket.setsockopt_string(zmq.SUBSCRIBE, channel)
redis_server = redis.StrictRedis(
2017-10-11 10:47:11 +02:00
host=cfg.get('RedisLog', 'host'),
port=cfg.getint('RedisLog', 'port'),
db=cfg.getint('RedisLog', 'db'))
serv_coord = redis.StrictRedis(
host='localhost',
port=6250,
db=1)
channel_proc = "CoordToProcess"
channel_disp = "PicToDisplay"
# server side
pubsub = redis_server.pubsub(ignore_subscribe_messages=True)
while True:
2017-10-11 10:47:11 +02:00
rdm = random.randint(1,10)
time.sleep(float(rdm))
#lux
lon = random.uniform(5.7373, 6.4823)
lat = random.uniform(49.4061,49.7449)
#central eur
lon = random.uniform(3.936, 9.890)
lat = random.uniform(47.957, 50.999)
2017-09-12 12:27:35 +02:00
content = ["rdm "+str(rdm)]
content = [lat,lon]
2017-09-12 12:27:35 +02:00
jsonContent = json.dumps(content)
to_send = { 'name': 'feeder'+str(rdm), 'log': jsonContent }
redis_server.publish(channel, json.dumps(to_send))
2017-10-11 10:47:11 +02:00
serv_coord.publish(channel_proc, json.dumps({'lat': float(lat), 'lon': float(lon)}))
while True:
#FIXME check if sock.recv is blocking
time.sleep(0.1)
content = socket.recv()
2017-10-09 15:56:24 +02:00
print('sending', (content))
redis_server.publish(channel, content)
if random.randint(1,10)<5:
time.sleep(0.5)
redis_server.publish(channel, content)
if random.randint(1,10)<5:
time.sleep(0.5)
redis_server.publish(channel, content)