import serial import time from common_utils.message import Message import common_utils.config as config __CONFIG__ = config.config_section_map('Uart') __SERIAL__ = None __PORT__ = str(__CONFIG__['port']) __BAUD__ = int(__CONFIG__['baud']) __DIVIDER__ = str(__CONFIG__['divider']) __RESPONSE_TIMEOUT__ = int(__CONFIG__['response_timeout']) def set_timeout(value): global __RESPONSE_TIMEOUT__ __RESPONSE_TIMEOUT__ = int(value) def get_timeout(): global __RESPONSE_TIMEOUT__ return __RESPONSE_TIMEOUT__ def start_serial(): global __SERIAL__, __PORT__, __BAUD__ try: if __SERIAL__ is None: __SERIAL__ = serial.Serial(__PORT__, __BAUD__, timeout=1)
import pika import gzip import common_utils.config as config queueConfig = config.config_section_map('QueueConnection') __url = queueConfig['server_url'] __port = int(queueConfig['port']) connection = pika.BlockingConnection(pika.ConnectionParameters( __url, port=__port)) channel = connection.channel() channel.queue_declare(queue='101') def callback(ch, method, properties, body): # only after python 3.2 :( # file_content = gzip.GzipFile(fileobj=body, mode='rb').read() with open("message.gz", "wb") as write_message: write_message.write(body) with gzip.open('message.gz', 'rb') as f: file_content = f.read() print(" [x] Received %r" % file_content) channel.basic_consume(callback, queue='101', no_ack=True) print(' [*] Waiting for messages. To exit press CTRL+C') channel.start_consuming()