mqtt_test.py
Go to the documentation of this file.
1 import paho.mqtt.client as mqtt
2 import math
3 import json
4 from time import sleep
5 
6 # The callback for when the client receives a CONNACK response from the server.
7 def on_connect(client, userdata, flags, rc):
8  print("Connected with result code "+str(rc))
9 
10 client = mqtt.Client()
11 client.on_connect = on_connect
12 
13 client = mqtt.Client("PlotJuggler-test") #create new instance
14 
15 client.connect("127.0.0.1", 1883, 60)
16 
17 time = 0.0
18 
19 while True:
20  sleep(0.20)
21  time += 0.20
22  data = {
23  "timestamp": time,
24  "test_data": {
25  "cos": math.cos(time),
26  "sin": math.sin(time)
27  }
28  }
29 
30  ret = client.publish("plotjuggler/stuff", json.dumps(data), qos=0 )
31  print( ret.is_published() )
void print(std::FILE *f, const S &format_str, Args &&...args)
Definition: core.h:2101


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:09