Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSC486 Lecture 05

CSC486 Lecture 05

Human-Computer Interaction
MQTT
(202501)

Javier Gonzalez-Sanchez

January 22, 2025
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. Cobot • Univers a l Robotics e-Series https://www.universal-robots.com/media/1802432/e-series-brochure.pdf • Comm

    a nds th a t c a n be used https://s3-eu-west-1.amazonaws.com/ur-support-site/29983/Script command Examples.pdf 5
  2. Brain-Computer Interfaces • Emotiv He a dsets https://www.emotiv.com/ • D

    a t a S a mples https://emotiv.gitbook.io/cortex-api/data-subscription/data-sample-object 6
  3. Eye Tracking • Tobii Sp a rk https://www.tobii.com/products/eye-trackers/screen-based/tobii-pro-spark • Tobii

    SDK https://www.tobii.com/products/softw a re/ a pplic a tions- a nd-developer-kits/tobii-pro-sdk 8
  4. Eye Tracking • Petoi https://www.petoi.com/pages/software-apps • Arduino IoT (with MQTT)

    https://docs.arduino.cc/tutorials/uno-wifi-rev2/uno-wifi-r2-mqtt-device-to-device/ 9
  5. Communication Protocols Sockets • - Wh a t: Low-level communic

    a tion mech a nism for exch a nging d a t a between two systems. • - How: Utilizes TCP/UDP protocols for reli a ble/unreli a ble d a t a tr a nsfer. • - Use C a se: Direct communic a tion between client-server a pplic a tions (e.g., f ile tr a nsfer a nd ch a t). WebSockets • - Wh a t: Full-duplex communic a tion protocol over a single TCP connection. • - How: En a bles persistent, bidirection a l communic a tion between client a nd server in re a l- time. • - Use C a se: Re a l-time a pplic a tions like live ch a ts, g a ming, a nd stock tr a ding pl a tforms. MQTT (Mess a ge Queuing Telemetry Tr a nsport) • Wh a t: Lightweight mess a ging protocol designed for low-b a ndwidth, high-l a tency networks. • How: Uses a publish-subscribe p a ttern for e ff icient communic a tion between devices. • Use C a se: Ide a l for IoT a pplic a tions, sm a rt home devices, a nd sensor networks. 12
  6. MQTT Wh a t is MQTT? • MQTT (Mess a

    ge Queuing Telemetry Tr a nsport) is a lightweight, publish-subscribe network protocol. • Designed for constr a ined devices a nd low-b a ndwidth, high-l a tency, or unreli a ble networks. Key Fe a tures • Simple a nd e a sy to implement. • Low b a ndwidth consumption. • Reli a ble mess a ge delivery. • Sc a l a ble to millions of devices. 17
  7. MQTT Architecture Broker • The centr a l server th

    a t h a ndles mess a ge distribution. • Ex a mples: Mosquitto, HiveMQ, EMQX, AWS MQ. Clients • Devices or a pplic a tions th a t publish (send) a nd subscribe (receive) mess a ges. • Ex a mples: Sensors, mobile a pps, a nd IoT devices. Topics • Hier a rchic a l n a mesp a ces for org a nizing mess a ges. • Ex a mple: home/livingRoom/temper a ture. 18
  8. MQTT Work f low Connect • Clients connect to the

    broker. Subscribe • Clients subscribe to topics of interest. Publish • Clients publish mess a ges to topics. Receive • Clients receive mess a ges from topics they a re subscribed to. Disconnect • Clients disconnect from the broker. 19
  9. Eclipse Paho for Java Wh a t is Eclipse P

    a ho? • A set of MQTT client libr a ries developed by the Eclipse Found a tion. • It supports multiple l a ngu a ges, such a s J a v a , Python, J a v a Script, etc. J a v a Dependency (M a ven) <dependency> <groupId>org.eclipse.paho</groupId> <artifactId>org.eclipse.paho.client.mqttv3</artifactId> <version>1.2.5</version> </dependency> 27
  10. Quality-of-service options • 0 – "at most once": A.K.A. "fire-and-forget."

    This option is suitable when message loss is acceptable, as it doesn't require acknowledgment or persistence. • 1 – "at least once": This option should be chosen when message loss is unacceptable, and your subscribers can handle duplicate messages. • 2 – "Exactly once": This option is ideal when message loss is unacceptable, and your subscribers cannot handle duplicate messages. 29
  11. Summary • MQTT: Lightweight, e ff i cient protocol for

    IoT and other use cases. • Mosquitto: A popular open-source MQTT broker. • Eclipse Paho: A versatile MQTT client library. • Java Example: https://github.com/CSC3100/MQTT 31
  12. Lab

  13. Part 1. Publisher (only testing purposes) 33 1. Create a

    program in Java that read your data_file
  14. Part 1. Publisher (only testing purposes) 34 2. Follow the

    Publisher example and make this program to “Publish” a line every 10 seconds. Customize your topic and clientID
  15. Part 2. Subscriber (this will be part of your app)

    35 1. Create a program in Java that subscribes to your published data.
  16. Part 2. Subscriber (this will be part of your app)

    36 2. Follow the example of the Subscriber code.
  17. Part 2. Subscriber (this will be part of your app)

    37 3. Every item received, store it in a data structure. When the data structure reaches 1000 values clean it (delete them all).
  18. CSC 509 Software Engineering Javier Gonzalez-Sanchez, Ph.D. [email protected] Fall 2024

    Copyright. These slides can only be used as study material for the class CSC509 at Cal Poly. They cannot be distributed or used for another purpose.