def on_message(mosq, obj, msg):
    data = json.loads(msg.payload.decode("utf-8")) # deserialization
    sent = int2dt(data['now']) # unix timestamp to datetime.datetime
    data['now'] = sent
    received = datetime.datetime.utcnow()
    lag = received - sent
    print("%-20s %d %s lag=%s" % (msg.topic, msg.qos, data, lag))
    #mosq.publish('pong', "Thanks", 0)

    data_x.append(sent)
    data_y.append(data['data']['y'])
    
    line.set_xdata(data_x.all[::-1])
    xmin, xmax = data_x.min(), data_x.max()
    if xmax > xmin:
        ax.set_xlim([xmin, xmax])
    line.set_ydata(data_y.all[::-1])
    ymin, ymax = data_y.min(), data_y.max()
    if ymax > ymin:
        ax.set_ylim([ymin, ymax])
    plt.pause(0.001)
Exemplo n.º 2
0
 def tickStrings(self, values, scale, spacing):
     # PySide's QTime() initialiser fails miserably and dismisses args/kwargs
     #return [QTime().addMSecs(value).toString('mm:ss') for value in values]
     return [int2dt(value).strftime("%H:%M:%S.%f") for value in values]