Ejemplo n.º 1
0
def publish_measurement(data, redis_pub_channel='rtweb'):
    filename = 'template'
    signature = "{0:s}:{1:s}".format(get_host_ip(), filename)
    r = Redis()
    try:
        Msg = Message(signature)
        final_data = dict()
        timestamp = datetime.now().strftime('%Y-%m-%d-%H:%M:%S')
        final_data['timestamp'] = timestamp
        final_data['raw']       = ''
        final_data['data']      = data
        Msg.msg = final_data
        r.publish(redis_pub_channel, Msg.as_jsno())

    except Exception as E:
        error_msg = {'source' : 'ComPort', 'function' : 'def run() - outter', 'error' : E.message}
Ejemplo n.º 2
0
    def __init__(self,
                 port = '/dev/ttyUSB0',
                 packet_timeout=1,
                 baudrate=115200,       
                 bytesize=8,    
                 parity='N',    
                 stopbits=1, 
                 xonxoff=0,             
                 rtscts=0,              
                 writeTimeout=None,     
                 dsrdtr=None,
                 host='127.0.0.1',
                 run=True):
        
        self.buffer  = ''
        self.last_read_line = ''
        self.serial    = serial.Serial(port, baudrate, bytesize, parity, stopbits, packet_timeout, xonxoff, rtscts, writeTimeout, dsrdtr)
        self.signature = "{0:s}:{1:s}".format(get_host_ip(), self.serial.port)
        
        self.redis_send_key = self.signature+'-send'
        self.redis_read_key = self.signature+'-read'
        self.redis = redis.Redis(host=host)
        
        logger_name = 'sermon.py:{}'.format(self.signature)
        if sys.stdout.isatty():        
            self.log   = Logger(logger_name)
        else:            
            self.log   = logger.RedisLogger(logger_name)
            self.log.addHandler(handlers.RedisHandler.to("log", host='localhost', port=6379))

        self.log.level = 1
        self.alive = False
        self._reader_alive = False

        # TODO add checking for redis presence and connection
        if self.redis.ping():
            # Register the new instance with the redis exchange
            if not self.redis.sismember(EXCHANGE,self.signature):
                self.redis.sadd(EXCHANGE,self.signature)
        else:
            pass
        
        if run:
            self.run()
Ejemplo n.º 3
0
Archivo: daq.py Proyecto: borand/ablib
        except Exception as E:
            self.log.error("process_message(): " + E.message)
            self.log.error(item)

def StartIqrSubmit(channel, host, submit_to):
    print"StartIqrSubmit(%s, %s, %s)" % (channel, host, submit_to)
    try:
        I = SubmitData(channel=channel, host=host, submit_to=submit_to);
        print("===============================================")
        while True:
            time.sleep(1)
            pass
    except KeyboardInterrupt:
        pass
    I.stop()

    print "Exiting " + __name__

##########################################################################################
if __name__ == "__main__":
    arguments = docopt(__doc__, version='Naval Fate 2.0')
    print("===============================================")
    print(arguments)

    if arguments['run']:
        channel   = 'data'
        host      = arguments.get('--redishost', get_host_ip())
        submit_to = arguments.get('--submit_to', get_host_ip())
        StartIqrSubmit(channel, host, submit_to)
Ejemplo n.º 4
0
import tornadoredis
import os
import logbook

from docopt import docopt
from ablib.util.common import get_host_ip

from redis import Redis

#define("port", default=8888, help="run on the given port", type=int)

##########################################################################################
#
#
log = logbook.Logger('rtweb.py')
redis_host_ip = get_host_ip()
host_ip       = get_host_ip()
host_port     = 8888;
redis_pubsub_channel = ('data', 'error')

#c = tornadoredis.Client(host=redis_host_ip)
#c.connect()
R = Redis()

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        interfaces = list(R.smembers('ComPort'))
        dynamic_content = { "title" : "RT WEB", "host_ip" : host_ip, "page_title" : 'Test', "interfaces" : interfaces}
        self.render("rtweb.html", title="RT WEB", host_ip=host_ip, page_title='Test', interfaces=interfaces)
        #self.render("rtweb.html", dynamic_content)
Ejemplo n.º 5
0
import tornadoredis
import os
import logbook

from docopt import docopt
from ablib.util.common import get_host_ip

from redis import Redis

#define("port", default=8888, help="run on the given port", type=int)

##########################################################################################
#
#
log = logbook.Logger('rtweb.py')
redis_host_ip = get_host_ip()
host_ip = get_host_ip()
host_port = 8888
redis_pubsub_channel = ('data', 'error')

#c = tornadoredis.Client(host=redis_host_ip)
#c.connect()
R = Redis()


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        interfaces = list(R.smembers('ComPort'))
        dynamic_content = {
            "title": "RT WEB",
            "host_ip": host_ip,
Ejemplo n.º 6
0
    try:
        not_done = True
        while not_done:
            timestamp = datetime.datetime.now()
            data_set     = D.GetData()
            print data_set
            M = Message()
            M.msg = {'data' : data_set}
            R.publish(channel, M.as_jsno())

            last_enqueue = Q.enqueue(submit, data_set,\
                                    timestamp=timestamp,\
                                    submit_to=submit_to,\
                                    threshold=threshold)
            #not_done = False

    except KeyboardInterrupt:
        pass
    print "Exiting " + __name__

##########################################################################################
if __name__ == "__main__":
    arguments = docopt(__doc__, version='Naval Fate 2.0')
    print("===============================================")
    print(arguments)

    if arguments['run']:
        channel   = arguments.get('--channel', 'digitemp')
        host      = get_host_ip()
        submit_to = arguments.get('--submit_to', get_host_ip())
        StarDigitempSubmit(channel, host, submit_to)
Ejemplo n.º 7
0
        mainlog   = Logger('sermon.py:main')
    else:
        mainlog   = logger.RedisLogger('sermon.py:main')
        mainlog.addHandler(handlers.RedisHandler.to("log", host='localhost', port=6379))
        

    mainlog.info("========= __main__ ============")
    mainlog.info(arguments)

    dev = arguments['--dev']
    mainlog.info(dev)

    test_json  = arguments['test']
    run_main   = arguments['run']
    one_wire   = arguments['1wire']
    redis_host = arguments.get('--redishost',get_host_ip())
    run_local  = arguments.get('--local',False)

    if run_local:
        redis_host = 'localhost'
    
    if test_json:
        cmd_vector = ['idn', 'adc', 'dio', 'getwh', 'resetwh', 'peek 22', 'owrom', 'owsave 1','owload', \
                  'owsp','owdata','owwp 3 1', 'owrp 3', 'adsf']
        for cmd in cmd_vector:
            try:
                out = C.query(cmd)
                mainlog.info(out)
            except Exception as E:
                mainlog.info(E)