Reader small image

You're reading from  Hands-On MQTT Programming with Python

Product typeBook
Published inMay 2018
Reading LevelExpert
PublisherPackt
ISBN-139781789138542
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Gaston C. Hillar
Gaston C. Hillar
author image
Gaston C. Hillar

Gaston C. Hillar is Italian and has been working with computers since he was 8 years old. Gaston has a Bachelor's degree in computer science (graduated with honors) and an MBA. Currently, Gaston is an independent IT consultant and a freelance author who is always looking for new adventures anywhere in the world. He was a senior contributing editor at Dr. Dobb's, and has written more than a hundred articles on software development topics. He has received the prestigious Intel Black Belt Software Developer award eight times. He has written many articles about Java for Oracle Java Magazine. Gaston was also a former Microsoft MVP in technical computing. He lives with his wife, Vanesa, and his two sons, Kevin and Brandon.
Read more about Gaston C. Hillar

Right arrow

Using the threaded client interface

Now, we will write a new version of the vehicle remote control application to use the threaded interface, also known as the threaded loop. Open the existing vehicle_mqtt_remote_control.py Python file and replace the lines that define the publish_command function with the following lines. The code file for the sample is included in the mqtt_python_gaston_hillar_05_04 folder, in the vehicle_mqtt_remote_control.py file:

def publish_command(client, command_name, key="", value=""): 
    command_message = build_command_message( 
        command_name, key, value) 
    result = client.publish(topic=commands_topic, 
    payload=command_message, qos=2) 
    time.sleep(1) 
    return result 

We removed the following line before the call to time.sleep(1):

    client.loop() 

The threaded loop will automatically call client.loop in another...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Hands-On MQTT Programming with Python
Published in: May 2018Publisher: PacktISBN-13: 9781789138542

Author (1)

author image
Gaston C. Hillar

Gaston C. Hillar is Italian and has been working with computers since he was 8 years old. Gaston has a Bachelor's degree in computer science (graduated with honors) and an MBA. Currently, Gaston is an independent IT consultant and a freelance author who is always looking for new adventures anywhere in the world. He was a senior contributing editor at Dr. Dobb's, and has written more than a hundred articles on software development topics. He has received the prestigious Intel Black Belt Software Developer award eight times. He has written many articles about Java for Oracle Java Magazine. Gaston was also a former Microsoft MVP in technical computing. He lives with his wife, Vanesa, and his two sons, Kevin and Brandon.
Read more about Gaston C. Hillar