Share
Embed
Transcript
32 slides
-
CSC 5100 Modern Software Engineering Lecture 03. Communication Services Dr.
Javier Gonzalez-Sanchez [email protected] www.javiergs.info ffi o ce: 14 -227 -
Why do we need a communication service? Robot Python EEG
SDK / Python Storage Communication Service Analytics Eye Tracker C# / Python Digital Twin Web / Java Dashboard Goal: components agree on messages, not implementation language. 2 -
The scaling problem: point-to-point communication Robot Storage Twin Coupling grows
Endpoints Protocols Retries Security Discovery EEG 3 Analytics Dashboard We need an intermediary. -
Publish / Subscribe through a broker SUBSCRIBE Publisher EEG sensor
PUBLISH Dashboard MQTT Broker Storage Topic: lab/eeg/participant-872/metrics Analytics Payload: { "focus": 0.72, "stress": 0.31, "ts": "…" } Publisher does not need to know who consumes the message. 4 -
The three MQTT concepts to remember 1 2 3 CLIENT
TOPIC BROKER Connects, publishes, subscribes Logical address for messages Routes messages to subscribers Decoupling dimensions A Python sensor and a Java dashboard can cooperate without importing each other’s code. CSC 364 or equivalent 6 -
Topics are part of the architecture project / source /
device / data Exact subscription 5100/robot/ur3e-01/pose 5100 / robot / ur3e-01 / pose 5100 / eeg / insight-01 / metrics 5100 / commands / ur3e-01 / move Single-level wildcard (+) 5100/robot/+/pose Everything below wildcard (#) 5100/robot/# Design for meaning, ownership, and permissions — not for class names. 7 -
Eclipse Paho for Java Wh t is Eclipse P ho?
• A set of MQTT client libr ries developed by the Eclipse Found tion. • It supports multiple l ngu ges, such s J v , Python, J v Script, etc. J v Dependency (M ven) a a a a a a a a a a a a a 9 a <dependency> <groupId>org.eclipse.paho</groupId> <artifactId>org.eclipse.paho.client.mqttv3</artifactId> <version>1.2.5</version> </dependency> -
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. 11 -
Eclipse Paho for Java J v Dependency (M ven) <dependency>
<groupId>software.amazon.awssdk.iotdevicesdk</groupId> <artifactId>aws-iot-device-sdk</artifactId> <version>1.34.0</version> </dependency> What changes? a a 14 a AWS IoT Device SDK AWS IoT endpoint X.509 certificate + private key -
One Communication Contract Host: a40203d8x0q5g-ats.iot.us-west-2.amazonaws.com Port: 8883 Topic: 5100/checkin {
"id": "[email protected]", "name": "Student Name" } TLS/X.509 files device.pem.crt private.pem.key AmazonRootCA1.pem 3 15 -
Python: Same MQTT Operation pip install paho-mqtt import json, time
import paho.mqtt.client as mqtt ENDPOINT = "a40203d8x0q5g-ats.iot.us-west-2.amazonaws.com" TOPIC = "5100/checkin" payload = { "id": "[email protected]", "name": "Student Name" } client = mqtt.Client( mqtt.CallbackAPIVersion.VERSION2, client_id=f"student-{int(time.time())}" ) client.tls_set( ca_certs="AmazonRootCA1.pem", certfile="device.pem.crt", keyfile="private.pem.key" ) client.connect(ENDPOINT, 8883) client.publish(TOPIC, json.dumps(payload), qos=1) client.disconnect() 5 17 -
JavaScript / Node.js: Same MQTT Operation npm install mqtt const
mqtt = require("mqtt"); const fs = require("fs"); const endpoint = "a40203d8x0q5g-ats.iot.us-west-2.amazonaws.com"; const client = mqtt.connect(`mqtts://${endpoint}:8883`, { clientId: `student-${Date.now()}`, ca: fs.readFileSync("AmazonRootCA1.pem"), cert: fs.readFileSync("device.pem.crt"), key: fs.readFileSync("private.pem.key") }); client.on("connect", () => { const payload = { id: "[email protected]", name: "Student Name" }; client.publish( "5100/checkin", JSON.stringify(payload), { qos: 1 }, () => client.end() ); }); 6 18 -
Homework Java Python JavaScript AWS IoT Device SDK Paho MQTT
mqtt Maven pip npm ↓ ↓ ↓ PUBLISH "5100/checkin" PUBLISH "5100/checkin" PUBLISH "5100/checkin" { "id": "[email protected]", "name": "Student Name" } 19 TLS/X.509 files device.pem.crt private.pem.key AmazonRootCA1.pem Success = your name appears at https://javiergs.github.io/csc5100/checkin/ 7 -
Delivery is a design decision QoS 0 “At most once”
Fast telemetry; occasional loss may be acceptable QoS 1 “At least once” Acknowledged delivery; duplicates are possible AWS IoT Core supports QoS 0 and QoS 1 (not QoS 2). Therefore consumers should be prepared for duplicate messages when correctness matters. Example: pose stream → QoS 0 | critical command / event → consider QoS 1 22 -
AWS IoT Core: managed communication infrastructure Lambda Device Gateway DynamoDB
Devices / Apps Message Broker Rules Engine S3 Device Shadows CloudWatch Secure, bi-directional device communication + integration with cloud services 23 -
One message, end to end 1 2 3 4 5
UR3e Adapter AWS IoT Core Twin Service Dashboard Storage Read pose Route by topic Subscribe + update Render state Persist event Topic 5100/robot/ur3e-01/pose { "x":0.42, "y":-0.18, "z":0.31, "rx":…, "ts":… } 24 -
Device Shadow: current state is different from event history Physical
Device reported state update Device Shadow Cloud copy of state set desired desired Application desired state reported Useful when the device is temporarily offline or when apps need the latest known state. Event stream ≠ state store -
Security is built into the communication boundary Who can connect?
What can each client publish or subscribe to? Thing / Client X.509 Certificate Example principle of least privilege Robot adapter: publish 5100/robot/ur3e-01/pose subscribe 5100/commands/ur3e-01/# IoT Policy Topics -
Architecture choices for our semester project Communication AWS IoT Core
/ MQTT Shared asynchronous event bus Message format JSON initially Language-neutral and inspectable Topic namespace 5100/<domain>/<device>/<event> Stable architectural contract Telemetry QoS 0 by default Favor freshness / throughput Important events QoS 1 + message ID Handle duplicates explicitly State Device Shadow when appropriate Latest desired/reported device state Persistence Rules → AWS service Separate transport from storage -
Takeaways Distributed system Components communicate across process / machine /
language boundaries. MQTT Publish/subscribe messaging gives us loose coupling. AWS IoT Core Managed broker + secure connectivity + rules + device state services. Our project Topics and message schemas are architectural interfaces. Next: connect a client → publish → subscribe → observe the message flow. 29 -
References & Homework AWS documentation used for this lecture •
AWS IoT Core — How AWS IoT works • AWS IoT Core — MQTT • AWS IoT Core — MQTT topics • AWS IoT Core — Rules for AWS IoT • AWS IoT Core — Device Shadow service • AWS Whitepaper — Designing MQTT Topics for AWS IoT Core 30 -
CSC 5100 Modern Software Engineering Javier Gonzalez-Sanchez, Ph.D. [email protected] Fall
2026 Copyright. These slides may be used only as study material for CSC 5100 within the California State University system. They may not be distributed or used for any other purpose.