2017-08-24 16:02:28 +02:00
|
|
|
#!/usr/bin/env python3.5
|
|
|
|
|
|
|
|
import time
|
|
|
|
import zmq
|
|
|
|
import redis
|
|
|
|
import random
|
2017-09-11 14:53:06 +02:00
|
|
|
import configparser
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import json
|
2017-08-24 16:02:28 +02:00
|
|
|
|
2017-09-11 14:53:06 +02:00
|
|
|
configfile = os.path.join(os.environ['VIRTUAL_ENV'], '../config.cfg')
|
|
|
|
cfg = configparser.ConfigParser()
|
|
|
|
cfg.read(configfile)
|
|
|
|
|
|
|
|
zmq_url = cfg.get('Redis', 'zmq_url')
|
2017-08-24 16:02:28 +02:00
|
|
|
zmq_url = "tcp://crf.circl.lu:5556"
|
2017-09-11 14:53:06 +02:00
|
|
|
channel = cfg.get('Redis', 'channel')
|
2017-08-24 16:02:28 +02:00
|
|
|
context = zmq.Context()
|
|
|
|
socket = context.socket(zmq.SUB)
|
|
|
|
socket.connect(zmq_url)
|
|
|
|
socket.setsockopt_string(zmq.SUBSCRIBE, channel)
|
|
|
|
|
|
|
|
redis_server = redis.StrictRedis(
|
2017-09-11 14:53:06 +02:00
|
|
|
host=cfg.get('Redis', 'host'),
|
|
|
|
port=cfg.getint('Redis', 'port'),
|
|
|
|
db=cfg.getint('Redis', 'db'))
|
2017-08-24 16:02:28 +02:00
|
|
|
|
|
|
|
# server side
|
|
|
|
pubsub = redis_server.pubsub(ignore_subscribe_messages=True)
|
|
|
|
|
|
|
|
while True:
|
2017-09-11 14:53:06 +02:00
|
|
|
rdm = random.randint(1,3)
|
2017-09-12 16:32:00 +02:00
|
|
|
time.sleep(float(rdm / 3))
|
|
|
|
lat = random.randint(-90,90)
|
|
|
|
lon = random.randint(-90,90)
|
2017-09-12 12:27:35 +02:00
|
|
|
content = ["rdm "+str(rdm)]
|
2017-09-12 16:32:00 +02:00
|
|
|
content = [lat,lon]
|
2017-09-12 12:27:35 +02:00
|
|
|
jsonContent = json.dumps(content)
|
|
|
|
to_send = { 'name': 'feeder'+str(rdm), 'log': jsonContent }
|
2017-09-11 14:53:06 +02:00
|
|
|
redis_server.publish(channel, json.dumps(to_send))
|
|
|
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
#FIXME check if sock.recv is blocking
|
2017-08-24 16:02:28 +02:00
|
|
|
time.sleep(0.1)
|
|
|
|
content = socket.recv()
|
2017-10-09 15:56:24 +02:00
|
|
|
print('sending', (content))
|
2017-08-24 16:02:28 +02:00
|
|
|
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)
|