Created
May 3, 2021 14:33
-
-
Save fisherds/a18bc4528c1a8c6ecf1e9eaea55c7b96 to your computer and use it in GitHub Desktop.
Example of receiving the MATLAB MQTT messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mqtt_helper | |
import time | |
class TankReceiver: | |
def __init__(self): | |
self.mqtt_client = mqtt_helper.MqttClient() | |
self.mqtt_client.callback = self.mqtt_callback | |
self.mqtt_client.connect( | |
mqtt_broker_ip_address="broker.hivemq.com", | |
subscription_topic_name="fisherds", | |
publish_topic_name="fisherds") | |
def mqtt_callback(self, message_type, payload): | |
print("MQTT message_type", message_type) | |
print("MQTT payload", payload) | |
if message_type == "motor/go": | |
left_wheel_speed = payload[0] | |
right_wheel_speed = payload[1] | |
print("motor/go", left_wheel_speed, right_wheel_speed) | |
if message_type == "motor/stop": | |
print("motor/stop") | |
if __name__ == '__main__': | |
TankReceiver() | |
while True: | |
time.sleep(0.01) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment