Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9fa4714

Browse files
committed
change publish message example
1 parent e3d3b63 commit 9fa4714

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

README.md

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -372,25 +372,18 @@ adam = mySystem.User("[email protected]", "a13st0rm")
372372
# Use Adam to access a messaging client
373373
mqtt = mySystem.Messaging(adam)
374374

375+
# Connect
376+
mqtt.connect()
375377

376-
# Set up callback function
377-
def on_connect(client, userdata, flags, rc):
378-
# When we connect to the broker, start publishing our data to the keelhauled topic
379-
for i in range(20):
380-
if i%2==0:
381-
payload = "yo"
382-
else:
383-
payload = "ho"
384-
client.publish("keelhauled", payload)
385-
time.sleep(1)
386-
387-
388-
# Connect callback to client
389-
mqtt.on_connect = on_connect
378+
# When we connect to the broker, start publishing our data to the keelhauled topic
379+
for i in range(20):
380+
if i%2==0:
381+
payload = "yo"
382+
else:
383+
payload = "ho"
384+
client.publish("keelhauled", payload)
385+
time.sleep(1)
390386

391-
# Connect and spin for 30 seconds before disconnecting
392-
mqtt.connect()
393-
time.sleep(30)
394387
mqtt.disconnect()
395388
```
396389
---

0 commit comments

Comments
 (0)