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() )
print
void print(std::FILE *f, const text_style &ts, const S &format_str, const Args &... args)
Definition: color.h:497
mqtt_test.on_connect
on_connect
Definition: mqtt_test.py:11


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45