Slide 1

Slide 1 text

Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.info o ffi ce: 14 -227 CSC 486 Human-Computer Interaction Lecture 05. MQTT

Slide 2

Slide 2 text

Project Proposal

Slide 3

Slide 3 text

Homework 3 Brain View Controller Client Blackboard PostOffice Model Server Publisher Subscriber

Slide 4

Slide 4 text

Environment

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

• Unity Development for HoloLens https://learn.microsoft.com/en-us/windows/mixed-reality/develop/unity/unity-development-overview • Met a Quest (3 a nd Pro) https://developers.meta.com/horizon/resources/compare-devices/ AR/VR 7

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Distributed System Architecture

Slide 11

Slide 11 text

Architecture 11

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Pong 13 https://github.com/CSC3100/Pong-Game

Slide 14

Slide 14 text

Publisher-Subscriber MQTT

Slide 15

Slide 15 text

Message Queuing 15

Slide 16

Slide 16 text

Message Queuing (Topics) 16

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

Maven

Slide 21

Slide 21 text

Create a project with Maven support 21

Slide 22

Slide 22 text

POM.xml 22

Slide 23

Slide 23 text

Maven Repository 23

Slide 24

Slide 24 text

Adding a New Dependency 24

Slide 25

Slide 25 text

Right-Click POM.xml 25

Slide 26

Slide 26 text

Publisher-Subscriber MQTT

Slide 27

Slide 27 text

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) org.eclipse.paho org.eclipse.paho.client.mqttv3 1.2.5 27

Slide 28

Slide 28 text

https://github.com/CSC3100/MQTT

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

https://github.com/CSC3100/MQTT

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

Lab

Slide 33

Slide 33 text

Part 1. Publisher (only testing purposes) 33 1. Create a program in Java that read your data_file

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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).

Slide 38

Slide 38 text

Questions 38

Slide 39

Slide 39 text

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.