Esempio n. 1
0
    def __init__(self, ip="localhost"):
        self.windowHeight = 600
        self.windowWidth = 800
        pygame.init()
        self.surface = pygame.display.set_mode(
            (self.windowWidth, self.windowHeight))
        col0 = (255, 255, 255)
        col1 = (188, 55, 133)
        col2 = (18, 108, 161)
        col3 = (0, 0, 255)
        col4 = (0, 0, 0)
        colors = (col0, col1, col2, col3, col4)
        self.colors = []
        for col in colors:
            self.colors.append(pygame.Color(col[0], col[1], col[2]))
        self.judgeIp = ip

        self.grid = []
        self.positions = []
        self.fieldWidth = 0
        self.fieldHeight = 0
        self.columns = 0
        self.rows = 0
        self.sub = subscriber.Subscriber(self.data_callback, self.judgeIp)
        self.sub.start_subscription()
Esempio n. 2
0
def start_subscription(ip):

    #sub's callback method is the first argument.
    sub = subscriber.Subscriber(data_received, ip, 50007)
    #To shut down properly
    signal.signal(signal.SIGINT, signal_handler)
    sub.start_subscription()
Esempio n. 3
0
 def subscribe_to_apps(self, apps):
     # code for the first run of then server to fetch and subscribe to all current apps
     for app_id in apps:
         app_to_subscribe = self.db.get_application(app_id)
         if app_to_subscribe:
             # looks like we get random disconnects from other instances if this id  is not unique
             random_chars = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(4))
             client = mqtt.Client(client_id='client'+str(app_id)+random_chars,
                                  clean_session=False,
                                  userdata=app_to_subscribe['app_id'])
             sub = subscriber.Subscriber(app_to_subscribe, client)
             client.loop_start()
             self.mqtt_clients[app_id] = client
Esempio n. 4
0
import subscriber as sub
import time
import zmq

def print_msg(topic, msg):
    print topic, msg

ip = "127.0.0.1"
port = 8690
list_of_topics = ['simulator']
topic_to_callback_map = dict([("simulator", print_msg)])

s = sub.Subscriber(ip, port, list_of_topics, topic_to_callback_map)

for i in range(3):
        s.recv_message("simulator")

all_msg = s.get_messages("simulator")
print all_msg
Esempio n. 5
0

def subCallback(stream_id, data, state, log, crtl):
    #store data locally in some file
    #with all of the timedate stuff and all that already in there
    df = pd.DataFrame([data])
    df.to_csv('test' + str(stream_id).strip() + '.csv',
              mode='a',
              header=False,
              index=False)
    return state


reader = reader.Reader(config, logger)
test_streams = ['Hybrid_Mux', 'Hybrid_Beam_Balances']
sub = subscriber.Subscriber(config, logger)
for stream in test_streams:
    data = {
        stream:
        pd.DataFrame(
            reader.get_stream_raw_data(stream,
                                       start=time.time(),
                                       stop=time.time() - 300))
    }
    sub.subscribe(stream)
    data[stream].to_csv('test' + str(stream).strip() + '.csv', index=False)
reader.close()
time.sleep(10)
sub.close()
for stream in test_streams:
    print(pd.read_csv('test' + str(stream).strip() + '.csv').tail())
Esempio n. 6
0
        print(cursor.execute('''SELECT * FROM pm_reading''').fetchall())


def open_db():
    global db, cursor
    db = sqlite3.connect(SQL_FILE)
    cursor = db.cursor()


def close_db():
    db.close()


def init_db():
    open_db()
    global db, cursor
    cursor.execute(
        '''CREATE TABLE IF NOT EXISTS pm_reading (id INTEGER PRIMARY KEY AUTOINCREMENT, date TIMESTAMP, pm25 INTEGER, pm10 INTEGER)''')
    db.commit()
    db.close()


if __name__ == "__main__":
    init_db()
    sub = subscriber.Subscriber(
        URL, PORT, DEVICE_ID, USERNAME, PW, pushData, TOPIC)
    sub.start()
    while(True):
        time.sleep(10)
        read()