Revize 9ff60381
Přidáno uživatelem Martin Forejt před asi 4 roky(ů)
- ID 9ff603810cfc4ccbabcaffd20e23c7767af14744
- Rodič b894d929
aswi2021vochomurka/main.py | ||
---|---|---|
1 |
import paho.mqtt.client as mqtt |
|
2 |
|
|
3 |
|
|
4 |
# The callback for when the client receives a CONNACK response from the server. |
|
5 |
def on_connect(client, userdata, flags, rc, properties=None): |
|
6 |
print("Connected with result code " + str(rc)) |
|
7 |
# Subscribing in on_connect() means that if we lose the connection and |
|
8 |
# reconnect then subscriptions will be renewed. |
|
9 |
client.subscribe("$SYS/#") |
|
10 |
|
|
11 |
|
|
12 |
# The callback for when a PUBLISH message is received from the server. |
|
13 |
def on_message(client, userdata, message): |
|
14 |
print(message.topic + " " + str(message.payload)) |
|
15 |
|
|
16 |
|
|
1 | 17 |
def start(): |
2 |
print("hello world Vochomurka") |
|
18 |
client = mqtt.Client() |
|
19 |
client.on_connect = on_connect |
|
20 |
client.on_message = on_message |
|
21 |
|
|
22 |
client.connect("localhost", 1883, 60) |
|
23 |
|
|
24 |
# Blocking call that processes network traffic, dispatches callbacks and |
|
25 |
# handles reconnecting. |
|
26 |
# Other loop*() functions are available that give a threaded interface and a |
|
27 |
# manual interface. |
|
28 |
client.loop_forever() |
src/main.py | ||
---|---|---|
1 |
import paho.mqtt.client as mqtt |
|
2 |
|
|
3 |
|
|
4 |
# The callback for when the client receives a CONNACK response from the server. |
|
5 |
def on_connect(client, userdata, flags, rc, properties=None): |
|
6 |
print("Connected with result code " + str(rc)) |
|
7 |
# Subscribing in on_connect() means that if we lose the connection and |
|
8 |
# reconnect then subscriptions will be renewed. |
|
9 |
client.subscribe("$SYS/#") |
|
10 |
|
|
11 |
|
|
12 |
# The callback for when a PUBLISH message is received from the server. |
|
13 |
def on_message(client, userdata, message): |
|
14 |
print(message.topic + " " + str(message.payload)) |
|
15 |
|
|
16 |
|
|
17 |
client = mqtt.Client() |
|
18 |
client.on_connect = on_connect |
|
19 |
client.on_message = on_message |
|
20 |
|
|
21 |
client.connect("localhost", 1883, 60) |
|
22 |
|
|
23 |
# Blocking call that processes network traffic, dispatches callbacks and |
|
24 |
# handles reconnecting. |
|
25 |
# Other loop*() functions are available that give a threaded interface and a |
|
26 |
# manual interface. |
|
27 |
client.loop_forever() |
Také k dispozici: Unified diff
Merge branch 'master' into feature/paho_demo