From 284a60cf65523b3a868a58cf2edc97d190a95608 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 27 Apr 2018 00:39:19 +0200 Subject: wip --- assignments/Makefile | 2 + assignments/blink-a-led/blink-a-led.pdf | Bin 722602 -> 722602 bytes assignments/mqtt/mqtt.md | 5 +- assignments/mqtt/mqtt.pdf | Bin 105234 -> 104784 bytes assignments/mqtt2/mqtt2.md | 10 + assignments/mqtt2/mqtt2.pdf | Bin 0 -> 51245 bytes assignments/mqtt3/mqtt3.md | 12 + assignments/mqtt3/mqtt3.pdf | Bin 0 -> 53509 bytes assignments/network/network.md | 7 + assignments/read-temperature/read-temperature.md | 4 + assignments/read-temperature/read-temperature.pdf | Bin 790129 -> 791810 bytes host/requirements.txt | 2 + slides/Makefile | 2 +- slides/images/ip-packet.pgf | 47 +++ slides/images/mqtt-example-architecture.pgf | 23 ++ slides/images/qtikz-template.pgs | 2 + slides/images/udp-packet.pgf | 32 ++ slides/toc.md | 20 +- slides/what-is-iot-reveal.html | 263 ++++++------ slides/what-is-iot-slides.pdf | Bin 314262 -> 308648 bytes slides/what-is-iot-slides.tex | 465 +++++++++++++--------- slides/what-is-iot-text.pdf | Bin 331142 -> 315666 bytes slides/what-is-iot.md | 230 ++++++----- 23 files changed, 707 insertions(+), 419 deletions(-) create mode 100644 assignments/mqtt2/mqtt2.md create mode 100644 assignments/mqtt2/mqtt2.pdf create mode 100644 assignments/mqtt3/mqtt3.md create mode 100644 assignments/mqtt3/mqtt3.pdf create mode 100644 assignments/network/network.md create mode 100644 host/requirements.txt create mode 100644 slides/images/ip-packet.pgf create mode 100644 slides/images/mqtt-example-architecture.pgf create mode 100644 slides/images/udp-packet.pgf diff --git a/assignments/Makefile b/assignments/Makefile index 2f97a07..6d31568 100644 --- a/assignments/Makefile +++ b/assignments/Makefile @@ -2,6 +2,8 @@ AS = AS += blink-a-led AS += read-temperature AS += mqtt +AS += mqtt2 +AS += mqtt3 PDFS=$(foreach A,$(AS),$(A)/$(A).pdf) diff --git a/assignments/blink-a-led/blink-a-led.pdf b/assignments/blink-a-led/blink-a-led.pdf index 785547f..7efd91f 100644 Binary files a/assignments/blink-a-led/blink-a-led.pdf and b/assignments/blink-a-led/blink-a-led.pdf differ diff --git a/assignments/mqtt/mqtt.md b/assignments/mqtt/mqtt.md index e89e88c..f52eed3 100644 --- a/assignments/mqtt/mqtt.md +++ b/assignments/mqtt/mqtt.md @@ -11,9 +11,6 @@ Get aquainted with MQTT. 1. Connect to MQTT broker 1. Publish temperature -1. Implement last will to indicate online status -1. Implement subscription to reconfigure device - 1. Change temperature report interval ## Tips @@ -32,7 +29,7 @@ char *cStr = myString.c_str(); ## Bonus -**1:** Print the heap at regular intervals. +**1:** Print the heap free size at regular intervals. **2:** Implement min, max and average temperature over configured interval. diff --git a/assignments/mqtt/mqtt.pdf b/assignments/mqtt/mqtt.pdf index 4c578f9..35ecd0b 100644 Binary files a/assignments/mqtt/mqtt.pdf and b/assignments/mqtt/mqtt.pdf differ diff --git a/assignments/mqtt2/mqtt2.md b/assignments/mqtt2/mqtt2.md new file mode 100644 index 0000000..cfc623a --- /dev/null +++ b/assignments/mqtt2/mqtt2.md @@ -0,0 +1,10 @@ +# Assignment: MQTT + +## Goal + +Get to know will messages and retained messages. + +## Steps + +1. Implement last will to indicate online status +1. Retained message diff --git a/assignments/mqtt2/mqtt2.pdf b/assignments/mqtt2/mqtt2.pdf new file mode 100644 index 0000000..b34898e Binary files /dev/null and b/assignments/mqtt2/mqtt2.pdf differ diff --git a/assignments/mqtt3/mqtt3.md b/assignments/mqtt3/mqtt3.md new file mode 100644 index 0000000..2994e9a --- /dev/null +++ b/assignments/mqtt3/mqtt3.md @@ -0,0 +1,12 @@ +# Assignment: MQTT + +## Goal + +Connect two devices with MQTT + +## Steps + +1. Publish an alert +1. Subscribe to alert topic, blink a led when you get a message +1. Implement subscription to reconfigure device + 1. Change temperature report interval diff --git a/assignments/mqtt3/mqtt3.pdf b/assignments/mqtt3/mqtt3.pdf new file mode 100644 index 0000000..e156bcf Binary files /dev/null and b/assignments/mqtt3/mqtt3.pdf differ diff --git a/assignments/network/network.md b/assignments/network/network.md new file mode 100644 index 0000000..8e49b24 --- /dev/null +++ b/assignments/network/network.md @@ -0,0 +1,7 @@ +## Assignment: Network play time + +* Measure round trip time/latency. Measure UDP, TCP. Measure when the + packet size is greater than the MTU + +* Notice variations in RTT + diff --git a/assignments/read-temperature/read-temperature.md b/assignments/read-temperature/read-temperature.md index 2528b4a..1037ba9 100644 --- a/assignments/read-temperature/read-temperature.md +++ b/assignments/read-temperature/read-temperature.md @@ -6,3 +6,7 @@ Wire up this schematic on the bread board: ![](schematic/read-temperature_schem.pdf) ![](schematic/read-temperature_bb.pdf) + +## Step 2 + +* Change sampling frequency diff --git a/assignments/read-temperature/read-temperature.pdf b/assignments/read-temperature/read-temperature.pdf index 5a13441..d3f21d1 100644 Binary files a/assignments/read-temperature/read-temperature.pdf and b/assignments/read-temperature/read-temperature.pdf differ diff --git a/host/requirements.txt b/host/requirements.txt new file mode 100644 index 0000000..a44e34e --- /dev/null +++ b/host/requirements.txt @@ -0,0 +1,2 @@ +asyncore +paho-mqtt diff --git a/slides/Makefile b/slides/Makefile index e0cc2a6..a94dcd6 100644 --- a/slides/Makefile +++ b/slides/Makefile @@ -6,7 +6,7 @@ HTMLS=$(P)-reveal.html ifeq (1,$(QUICK)) PP_DEFS+=QUICK -PDF_ENGINE = pdflatex +PDF_ENGINE = xelatex #PANDOC_ARGS += --no-highlight PANDOC_ARGS += --highlight-style=pygments else diff --git a/slides/images/ip-packet.pgf b/slides/images/ip-packet.pgf new file mode 100644 index 0000000..5a977a2 --- /dev/null +++ b/slides/images/ip-packet.pgf @@ -0,0 +1,47 @@ +\begin{tikzpicture}[scale=0.30] + \sffamily + \foreach \x in {0,7,8,15,16,31} % {0,...,32} + \node at (\x+0.5,20.5) {\scriptsize \x}; +% \foreach \x in {0,...,31} +% \node at (\x+0.5,13.5) {\scriptsize \x}; + \foreach \x in {0,8,16,32} % {0,...,32} + \draw[thick] (\x,20) -- (\x,21); + \foreach \x in {0,...,32} + \draw[thick] (\x,14) -- (\x,20); +% \foreach \x in {0,...,32} +% \draw[thick] (\x,13) -- (\x,14); + \node[thick] (bit1) at (-0.6,20.5) {\scriptsize bit}; +% \node[thick] (bit2) at (-0.6,13.5) {\scriptsize bit}; + +\iffalse + \draw [<->, thick] (-0.6, 19.9) -- (-0.6,15.1); + \draw [thick] (-1, 20) -- (-0.1,20); + \draw [thick] (-1, 15) -- (-0.1,15); + \node[fill=white] at (-1.1,17.5) {\tiny 20 bytes}; +\fi + \foreach \y/\v in {0,4,8,12,16,20} + \node at (-0.6,{19.5-(\v / 4)}) {\scriptsize \v}; + + \filldraw[thick,draw=black, fill=white] (0,20) rectangle (4,19); \node (mode) at (2,19.5) {\scriptsize version}; + \filldraw[thick,draw=black, fill=white] (4,20) rectangle (8,19); \node (mode) at (6,19.5) {\scriptsize len}; +% \draw[thick, draw=black, fill=white] (8,20) rectangle (16,19); \node (stratum) at (11.5,19.5) {\scriptsize type of service (TOS)}; + \draw[thick, draw=black, fill=white] (8,20) rectangle (16,19); \node (stratum) at (11.5,19.5) {\scriptsize TOS}; + \draw[thick, draw=black, fill=white] (16,20) rectangle (32,19); \node (li) at (24,19.5) {\scriptsize full length of packet}; + \filldraw[thick,draw=black, fill=white] (0,19) rectangle (16,18); \node (mode) at (8,18.5) {\scriptsize identification}; +% \draw[thick, draw=black] (16,19) rectangle (19,18); \filldraw[white] (16.5,18.43) rectangle (19,18.88); \node [](li) at (17.5,18.67) {\tiny IP flags}; \node at (16.5,18.25) {\tiny x};\node at (17.5,18.25) {\tiny D};\node at (18.5,18.25) {\tiny M}; + \draw[thick, draw=black] (16,19) rectangle (19,18); \filldraw[white] (16.5,18.43) rectangle (19,18.88); \node at (16.5,18.5) {\scriptsize X};\node at (17.5,18.5) {\scriptsize D};\node at (18.5,18.5) {\scriptsize M}; + \draw[thick, draw=black, fill=white] (19,19) rectangle (32,18); \node (li) at (24,18.5) {\scriptsize fragment Offset}; + \filldraw[thick,draw=black, fill=white] (0,18) rectangle (8,17); \node (mode) at (4,17.5) {\scriptsize time to live (TTL)}; + \draw[thick, draw=black, fill=white] (8,18) rectangle (16,17); \node (stratum) at (11.5,17.5) {\scriptsize protocol}; + \draw[thick, draw=black, fill=white] (16,18) rectangle (32,17); \node (li) at (24,17.5) {\scriptsize header checksum}; + \filldraw[thick,draw=black, fill=white] (0,17) rectangle (32,16); \node (mode) at (16,16.5) {\scriptsize source IP address}; + \filldraw[thick,draw=black, fill=white] (0,16) rectangle (32,15); \node (mode) at (16,15.5) {\scriptsize destination IP address}; + \draw[thick,draw=black, fill=white] (0,15) rectangle (32,14); +% \draw[thick,draw=black, fill=white] (0,15) rectangle (31.5,14); +% \draw[fill=white, draw=white] (31.4,15) rectangle (31.6,16); +% \draw[thick] (31.5,14.97) decorate [decoration=saw] { -- (31.5,14.02)}; + \node (mode) at (16,14.5) {\scriptsize IP options (variable length)}; + + \filldraw[thick,draw=black, fill=white] (0,12) rectangle (32,14); \node (mode) at (16,13) {\scriptsize payload}; + +\end{tikzpicture} diff --git a/slides/images/mqtt-example-architecture.pgf b/slides/images/mqtt-example-architecture.pgf new file mode 100644 index 0000000..b36827c --- /dev/null +++ b/slides/images/mqtt-example-architecture.pgf @@ -0,0 +1,23 @@ +\begin{tikzpicture} + +\path + (-3 cm, 0) node (c1_label) {Device \#1} + ( 0 cm, 0) node (c2_label) {Device \#2} + ( 3 cm, 0) node (c3_label) {Device \#3} + + (0, -3 cm) node (broker_label) {Broker} + (0, -6 cm) node (central_label) {Central} +; + +\node (c1)[draw, circle, fit=(c1_label)] {}; +\node (c2)[draw, circle, fit=(c2_label)] {}; +\node (c3)[draw, circle, fit=(c3_label)] {}; +\node (central)[draw, circle, fit=(central_label)] {}; +\node (broker)[draw, rectangle, thick, inner ysep=5 mm, inner xsep=10 mm, fit=(broker_label)] {}; + +\draw[{Latex[length=4mm, round]}-{Latex[length=4mm, round]}] (c1) to [bend right] (broker); +\draw[{Latex[length=4mm, round]}-{Latex[length=4mm, round]}] (c2) -- (broker); +\draw[{Latex[length=4mm, round]}-{Latex[length=4mm, round]}] (c3) to [bend left] (broker); +\draw[{Latex[length=4mm, round]}-{Latex[length=4mm, round]}] (central) -- (broker); + +\end{tikzpicture} diff --git a/slides/images/qtikz-template.pgs b/slides/images/qtikz-template.pgs index 6d23d1a..edb322b 100644 --- a/slides/images/qtikz-template.pgs +++ b/slides/images/qtikz-template.pgs @@ -6,6 +6,7 @@ \usetikzlibrary{ angles, arrows, + arrows.meta, backgrounds, calc, chains, @@ -14,6 +15,7 @@ decorations.pathreplacing, decorations.text, fit, + matrix, positioning, quotes, shapes.arrows, diff --git a/slides/images/udp-packet.pgf b/slides/images/udp-packet.pgf new file mode 100644 index 0000000..405f805 --- /dev/null +++ b/slides/images/udp-packet.pgf @@ -0,0 +1,32 @@ +\scalebox{0.5}{ + +\begin{tikzpicture}[ +every node/.style={font=\bfseries} +] + +\path +(-6.5em, 2em) node[draw, rectangle, minimum width=5em, minimum height=2em] {Offsets} +(-6.5em, 0em) node[draw, rectangle, minimum width=5em, minimum height=2em] {Octet} +(-2em, 2em) node[draw, rectangle, minimum width=4em, minimum height=2em] {Octet} +(-2em, 0em) node[draw, rectangle, minimum width=4em, minimum height=2em] {Bit} + +(16em, -2em) node[draw, rectangle, minimum width=32em, minimum height=2em] {source port} +(48em, -2em) node[draw, rectangle, minimum width=32em, minimum height=2em] {destination port} +(16em, -4em) node[draw, rectangle, minimum width=32em, minimum height=2em] {length} +(48em, -4em) node[draw, rectangle, minimum width=32em, minimum height=2em] {checksum} +; + +\foreach \x in {0,...,3} + \node[draw, rectangle, minimum width=16em, minimum height=2em] at (\x * 16em + 8em, 2em) {\scriptsize \x}; +\foreach \x in {0,...,31} + \node[draw, rectangle, minimum width=2em, minimum height=2em] at (\x * 2em + 1em, 0em) {\scriptsize \x}; + +\node[draw, rectangle, minimum width=4em, minimum height=2em] at (-2em, -2em) {\scriptsize 0}; +\node[draw, rectangle, minimum width=4em, minimum height=2em] at (-2em, -4em) {\scriptsize 32}; + +\node[draw, rectangle, minimum width=5em, minimum height=2em] at (-6.5em, -2em) {\scriptsize 0}; +\node[draw, rectangle, minimum width=5em, minimum height=2em] at (-6.5em, -4em) {\scriptsize 4}; + +\end{tikzpicture} + +} diff --git a/slides/toc.md b/slides/toc.md index 8c07c8b..76e65a6 100644 --- a/slides/toc.md +++ b/slides/toc.md @@ -22,6 +22,7 @@ * Layer 7: Application Layer * Details: IP * Details: IP + * Details: UDP * Lecture: ESP8266 * NodeMCU hardware * NodeMCU hardware @@ -35,16 +36,21 @@ * ESP Arduino APIs * Lecture: MQTT * MQTT + * MQTT - Implementations + * MQTT Cloud Connectors * MQTT - The protocol - * MQTT - The protocol - MQTT Topic - * MQTT - The protocol - MQTT Topic * MQTT - The protocol - MQTT Packet - * MQTT - The protocol - MQTT Topic - more + * MQTT - The protocol - Keep alive + * MQTT - The protocol - MQTT Topic * MQTT - The protocol - Retained message * MQTT - The protocol - Will message - * MQTT - Patterns - * MQTT - Implementations - * MQTT Cloud Connectors + * MQTT - The protocol - Client id + * Device and application architecture with MQTT + * MQTT Topic * MQTT on Arduino * MQTT on Arduino - * Assignment: Network play time + * Assignment + * MQTT topic architecture + * MQTT - Patterns + * Assignment + * Assignment diff --git a/slides/what-is-iot-reveal.html b/slides/what-is-iot-reveal.html index 0d73619..b63657a 100644 --- a/slides/what-is-iot-reveal.html +++ b/slides/what-is-iot-reveal.html @@ -172,9 +172,9 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni Chip CPU -Freq +Freq RAM -Flash +Flash Price @@ -182,33 +182,33 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni nRF52810 Cortex-M4 -64 M -Hz 24k -192k +64 MHz +24k +192k $1.88 nRF52832 -Cortex-M4 -F +Cortex-M4F + 32k -256k +256k $2.54 - + 64k -512k +512k $2.59 nRF52840 -Cortex-M4 -F +Cortex-M4F + 256k -1024k +1024k $3.85 @@ -451,12 +451,11 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni

Details: IP

- -
-

Details: IP

+
+

Details: UDP

+ +

TODO: add payload to “ip packets”

Lecture: ESP8266

NodeMCU hardware

@@ -530,8 +529,12 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni void restart(); uint32_t getFreeHeap(); uint32_t getChipId(); -} ESP; -

// Usage ESP.restart();

+ + ... +} ESP; + +// Usage +ESP.restart();

ESP Arduino APIs

class {
@@ -544,11 +547,13 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
     IPAddress subnetMask();
     IPAddress gatewayIP();
     IPAddress dnsIP(uint8_t dns_no = 0);
-} WiFi;
-
-// Usage:
+
+    ...
+} WiFi;
 
-Serial.println(WiFi.localIP().toString());
+// Usage: + +Serial.println(WiFi.localIP().toString()); @@ -565,6 +570,40 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni

Has UDP-like semantics with “fire and forget” but on a higher level (the message always have to be delivered and ACKed by the broker, not it’s final recipient.

Version 3.1.1 er den som gjelder, V 3.1 er rar, de andre finnes ikke (før standardisering).

+
+

MQTT - Implementations

+
    +
  • Mosquitto
  • +
  • Eclipse Paho
  • +
  • RabbitMQ
  • +
  • ActiveMQ
  • +
+ +
+

MQTT Cloud Connectors

+
    +
  • Cloud +
      +
    • Amazon IoT
    • +
    • Google Cloud IoT
    • +
    • Microsoft Azure IoT
    • +
    • CloudMQTT (at Heroku)
    • +
  • +
  • DIY +
      +
    • ThingMQ
    • +
    • HiveMQ
    • +
  • +
+

MQTT - The protocol

Agents have one of two roles:

@@ -591,47 +630,7 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni

http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html

Subscriptions are not permanent. The connection is (unlike HTTP) stateful.

Some messages may be persistent, but only one per topic. You will often end up with a “proper” mq on the backend if queuing is needed.

- -
-

MQTT - The protocol - MQTT Topic

-
    -
  • Topic name: foo/bar/baz
  • -
  • Topic filter -
      -
    • foo/bar/?
    • -
    • foo/#
    • -
  • -
-
-

MQTT - The protocol - MQTT Topic

-

The temperature sensor:

-
    -
  • Publishes on: -
      -
    • myapp/$device-id/temperature
    • -
    • myapp/$device-id/humidity
    • -
    • myapp/$device-id/altert
    • -
  • -
  • Subscribes to: -
      -
    • myapp/$device-id/command
    • -
  • -
-

The central application:

-
    -
  • Subscribes to: -
      -
    • myapp/#/temperature
    • -
    • myapp/#/humidity
    • -
  • -
  • Publishes on: -
      -
    • myapp/$device-id/command
    • -
  • -
-

MQTT - The protocol - MQTT Packet

@@ -648,28 +647,19 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni

Only packet type + flags (1 byte) is required, everything else is optional.

The size field is variable length encoded, 0-127 bytes is 1 byte, 128-16383 use 2 bytes etc, up to 4 bytes for 256MB payload.

-
-

MQTT - The protocol - MQTT Topic - more

-

Enten må den holdes rett etter “## MQTT - The protocol - MQTT Topic” ellers kanskje flyttes etter “patterns”.

-

The central application is split:

-
    -
  • An aggregating agent: -
      -
    • myapp/#/temperature
    • -
    • myapp/#/humidity
    • -
  • -
  • Emailing agent +
+

MQTT - The protocol - Keep alive

+

TODO

+
+

MQTT - The protocol - MQTT Topic

    -
  • myapp/$device-id/altert
  • -
-
  • Publishes on: +
  • Topic name: foo/bar/baz
  • +
  • Topic filter
      -
    • myapp/$device-id/command
    • +
    • foo/bar/?
    • +
    • foo/#
  • -

    MQTT - The protocol - Retained message

    Message is kept by the server even after disconnect

    @@ -723,50 +713,42 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
  • 0
  • -
    -

    MQTT - Patterns

    -

    Må utvides

    -

    Explain:

    +
    +

    MQTT - The protocol - Client id

    +

    TODO

    +
    +

    Device and application architecture with MQTT

    + +
    +

    MQTT Topic

    +

    The temperature sensor:

      -
    • Push vs pull, central applications can push to clients
    • -
    • mostly mqtt, some http
    • -
    • Client id - sparker ut gamle koblinger
    • -
    • Keep alive / ping meldinger
    • -
    • Alternative transporter - websockets(!)
    • -
    -
    -

    MQTT - Implementations

    +
  • Publishes on:
      -
    • Mosquitto
    • -
    • Eclipse Paho
    • -
    • RabbitMQ
    • -
    • ActiveMQ
    • +
    • myapp/$device-id/temperature
    • +
    • myapp/$device-id/humidity
    • +
    • myapp/$device-id/altert
    • +
  • +
  • Subscribes to: +
      +
    • myapp/$device-id/command
    • +
  • - -
    -

    MQTT Cloud Connectors

    +

    The central application:

      -
    • Cloud +
    • Subscribes to:
        -
      • Amazon IoT
      • -
      • Google Cloud IoT
      • -
      • Microsoft Azure IoT
      • -
      • CloudMQTT (at Heroku)
      • +
      • myapp/#/temperature
      • +
      • myapp/#/humidity
    • -
    • DIY +
    • Publishes on:
        -
      • ThingMQ
      • -
      • HiveMQ
      • +
      • myapp/$device-id/command

    MQTT on Arduino

    @@ -801,12 +783,51 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni -
    -

    Assignment: Network play time

    +
    +

    Assignment

      -
    • Measure round trip time/latency. Measure UDP, TCP. Measure when the packet size is greater than the MTU

    • -
    • Notice variations in RTT

    • +
    • mqtt
    +
    +

    MQTT topic architecture

    +

    The central application is split:

    +
      +
    • An aggregating agent: +
        +
      • myapp/#/temperature
      • +
      • myapp/#/humidity
      • +
    • +
    • Emailing agent +
        +
      • myapp/$device-id/altert
      • +
    • +
    • Publishes on: +
        +
      • myapp/$device-id/command
      • +
    • +
    + +
    +

    MQTT - Patterns

    +
      +
    • Combining MQTT and HTTP
    • +
    • Using web sockets transport
    • +
    +
    +

    Assignment

    +
      +
    • mqtt2
    • +
    +
    +

    Assignment

    +
      +
    • mqtt3
    • +
    +

    diff --git a/slides/what-is-iot-slides.pdf b/slides/what-is-iot-slides.pdf index cb3b978..efee6d1 100644 Binary files a/slides/what-is-iot-slides.pdf and b/slides/what-is-iot-slides.pdf differ diff --git a/slides/what-is-iot-slides.tex b/slides/what-is-iot-slides.tex index 68f0c06..1e31381 100644 --- a/slides/what-is-iot-slides.tex +++ b/slides/what-is-iot-slides.tex @@ -129,10 +129,10 @@ Sparkfun and Adafruit etc sell modules with all of these technologies.} Chip & CPU & Freq & RAM & Flash & Price\tabularnewline \midrule \endhead -nRF52810 & Cortex-M4 & 64 M & Hz 24k & 192k & \$1.88\tabularnewline -nRF52832 & Cortex-M4 & F & 32k & 256k & \$2.54\tabularnewline +nRF52810 & Cortex-M4 & 64 MHz & 24k & 192k & \$1.88\tabularnewline +nRF52832 & Cortex-M4F & & 32k & 256k & \$2.54\tabularnewline & & & 64k & 512k & \$2.59\tabularnewline -nRF52840 & Cortex-M4 & F & 256k & 1024k & \$3.85\tabularnewline +nRF52840 & Cortex-M4F & & 256k & 1024k & \$3.85\tabularnewline \bottomrule \end{longtable} @@ -447,21 +447,7 @@ The signaling does not specify any max data rate, very high rates \begin{frame}{Details: IP} \protect\hypertarget{details-ip}{} -\includegraphics{images/ip-header.pdf} - -\note{Note that the “total length” field is 16 bits, 2 bytes, it’s -maximum value is 64k, 65536.} - -\end{frame} - -\begin{frame}{Details: IP} -\protect\hypertarget{details-ip-1}{} - \begin{center} -\iffalse -Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. -\fi - \begin{tikzpicture}[scale=0.30] \sffamily \foreach \x in {0,7,8,15,16,31} % {0,...,32} @@ -500,12 +486,57 @@ Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem \draw[thick, draw=black, fill=white] (16,18) rectangle (32,17); \node (li) at (24,17.5) {\scriptsize header checksum}; \filldraw[thick,draw=black, fill=white] (0,17) rectangle (32,16); \node (mode) at (16,16.5) {\scriptsize source IP address}; \filldraw[thick,draw=black, fill=white] (0,16) rectangle (32,15); \node (mode) at (16,15.5) {\scriptsize destination IP address}; - \draw[thick,draw=black, fill=white] (0,15) rectangle (31.5,14); - \draw[fill=white, draw=white] (31.4,14.96) rectangle (31.6,14.05); - \draw[thick] (31.5,14.97) decorate [decoration=saw] { -- (31.5,14.02)}; + \draw[thick,draw=black, fill=white] (0,15) rectangle (32,14); +% \draw[thick,draw=black, fill=white] (0,15) rectangle (31.5,14); +% \draw[fill=white, draw=white] (31.4,15) rectangle (31.6,16); +% \draw[thick] (31.5,14.97) decorate [decoration=saw] { -- (31.5,14.02)}; \node (mode) at (16,14.5) {\scriptsize IP options (variable length)}; + + \filldraw[thick,draw=black, fill=white] (0,12) rectangle (32,14); \node (mode) at (16,13) {\scriptsize payload}; + +\end{tikzpicture} + +\end{center} + +\end{frame} + +\begin{frame}{Details: UDP} +\protect\hypertarget{details-udp}{} + +\begin{center} +\scalebox{0.5}{ + +\begin{tikzpicture}[ +every node/.style={font=\bfseries} +] + +\path +(-6.5em, 2em) node[draw, rectangle, minimum width=5em, minimum height=2em] {Offsets} +(-6.5em, 0em) node[draw, rectangle, minimum width=5em, minimum height=2em] {Octet} +(-2em, 2em) node[draw, rectangle, minimum width=4em, minimum height=2em] {Octet} +(-2em, 0em) node[draw, rectangle, minimum width=4em, minimum height=2em] {Bit} + +(16em, -2em) node[draw, rectangle, minimum width=32em, minimum height=2em] {source port} +(48em, -2em) node[draw, rectangle, minimum width=32em, minimum height=2em] {destination port} +(16em, -4em) node[draw, rectangle, minimum width=32em, minimum height=2em] {length} +(48em, -4em) node[draw, rectangle, minimum width=32em, minimum height=2em] {checksum} +; + +\foreach \x in {0,...,3} + \node[draw, rectangle, minimum width=16em, minimum height=2em] at (\x * 16em + 8em, 2em) {\scriptsize \x}; +\foreach \x in {0,...,31} + \node[draw, rectangle, minimum width=2em, minimum height=2em] at (\x * 2em + 1em, 0em) {\scriptsize \x}; + +\node[draw, rectangle, minimum width=4em, minimum height=2em] at (-2em, -2em) {\scriptsize 0}; +\node[draw, rectangle, minimum width=4em, minimum height=2em] at (-2em, -4em) {\scriptsize 32}; + +\node[draw, rectangle, minimum width=5em, minimum height=2em] at (-6.5em, -2em) {\scriptsize 0}; +\node[draw, rectangle, minimum width=5em, minimum height=2em] at (-6.5em, -4em) {\scriptsize 4}; + \end{tikzpicture} +} + \end{center} \end{frame} @@ -527,13 +558,13 @@ Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem \begin{tikzpicture} \path - (0, 0) node(flash)[draw, rectangle, + (0, 0) node(flash)[draw, rectangle, minimum height=1cm, minimum width=2cm] {Flash} - (0, 1.5) node(esp8266)[draw, rectangle, + (0, 1.5) node(esp8266)[draw, rectangle, minimum height=1cm, minimum width=2cm] {ESP8266} - (3.5, 1.5) node(cp201x)[draw, rectangle, + (3.5, 1.5) node(cp201x)[draw, rectangle, minimum height=0.75cm, minimum width=1cm] {CP201x} @@ -716,12 +747,15 @@ config.h is created by “new tab”.} \DataTypeTok{void}\NormalTok{ restart();} \DataTypeTok{uint32_t}\NormalTok{ getFreeHeap();} \DataTypeTok{uint32_t}\NormalTok{ getChipId();} + +\NormalTok{ ...} \NormalTok{\} ESP;} + +\CommentTok{// Usage} +\NormalTok{ESP.restart();} \end{Highlighting} \end{Shaded} -// Usage ESP.restart(); - \end{frame} \begin{frame}[fragile]{ESP Arduino APIs} @@ -739,6 +773,8 @@ config.h is created by “new tab”.} \NormalTok{ IPAddress subnetMask();} \NormalTok{ IPAddress gatewayIP();} \NormalTok{ IPAddress dnsIP(}\DataTypeTok{uint8_t}\NormalTok{ dns_no = }\DecValTok{0}\NormalTok{);} + +\NormalTok{ ...} \NormalTok{\} WiFi;} \CommentTok{// Usage:} @@ -779,139 +815,123 @@ Version 3.1.1 er den som gjelder, V 3.1 er rar, de andre finnes ikke \end{frame} -\begin{frame}{MQTT - The protocol} -\protect\hypertarget{mqtt---the-protocol}{} +\begin{frame}{MQTT - Implementations} +\protect\hypertarget{mqtt---implementations}{} -Agents have one of two roles: +\begin{itemize} +\tightlist +\item + Mosquitto +\item + Eclipse Paho +\item + RabbitMQ +\item + ActiveMQ +\end{itemize} + +\note{RabbitMQ has a separate connector that must be installed Not sure +about ActiveMQ but it is at least a part of the project so it is +releases at the same time.} + +\end{frame} + +\begin{frame}{MQTT Cloud Connectors} +\protect\hypertarget{mqtt-cloud-connectors}{} \begin{itemize} \tightlist \item - \emph{Client} + Cloud \begin{itemize} \tightlist \item - Publishes \emph{messages} + Amazon IoT \item - Subscribes / unsubscribes to \emph{topics} + Google Cloud IoT + \item + Microsoft Azure IoT + \item + CloudMQTT (at Heroku) \end{itemize} \item - \emph{Broker} (aka Server) + DIY \begin{itemize} \tightlist \item - Handles network connections - \item - Keeps subscriptions - \item - Manages client - - \begin{itemize} - \tightlist - \item - Disconnects - \item - \emph{(last) will} - \end{itemize} + ThingMQ \item - Persistence of retained messages + HiveMQ \end{itemize} \end{itemize} -\note{network connections: this includes removing closed sockets, -client’s that doesn’t respons to timeouts and duplicate clients. - -http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html - -Subscriptions are not permanent. The connection is (unlike HTTP) -stateful. - -Some messages may be persistent, but only one per topic. You will often -end up with a “proper” mq on the backend if queuing is needed.} - -\end{frame} - -\begin{frame}[fragile]{MQTT - The protocol - MQTT Topic} -\protect\hypertarget{mqtt---the-protocol---mqtt-topic}{} +\note{In between are: \begin{itemize} \tightlist \item - Topic name: \texttt{foo/bar/baz} + self hosted \item - Topic filter - - \begin{itemize} - \tightlist - \item - \texttt{foo/bar/?} - \item - \texttt{foo/\#} - \end{itemize} -\end{itemize} + Generic bridges +\end{itemize}} \end{frame} -\begin{frame}[fragile]{MQTT - The protocol - MQTT Topic} -\protect\hypertarget{mqtt---the-protocol---mqtt-topic-1}{} +\begin{frame}{MQTT - The protocol} +\protect\hypertarget{mqtt---the-protocol}{} -The temperature sensor: +Agents have one of two roles: \begin{itemize} \tightlist \item - Publishes on: + \emph{Client} \begin{itemize} \tightlist \item - \texttt{myapp/\$device-id/temperature} - \item - \texttt{myapp/\$device-id/humidity} + Publishes \emph{messages} \item - \texttt{myapp/\$device-id/altert} + Subscribes / unsubscribes to \emph{topics} \end{itemize} \item - Subscribes to: + \emph{Broker} (aka Server) \begin{itemize} \tightlist \item - \texttt{myapp/\$device-id/command} - \end{itemize} -\end{itemize} - -The central application: - -\begin{itemize} -\tightlist -\item - Subscribes to: - - \begin{itemize} - \tightlist + Handles network connections \item - \texttt{myapp/\#/temperature} + Keeps subscriptions \item - \texttt{myapp/\#/humidity} - \end{itemize} -\item - Publishes on: + Manages client - \begin{itemize} - \tightlist + \begin{itemize} + \tightlist + \item + Disconnects + \item + \emph{(last) will} + \end{itemize} \item - \texttt{myapp/\$device-id/command} + Persistence of retained messages \end{itemize} \end{itemize} -\note{Typical first round of implementation. +\note{network connections: this includes removing closed sockets, +client’s that doesn’t respons to timeouts and duplicate clients. -Commands can be: * load new firmware (maybe an URL and firmware -signature). * Set new calibration values * Change reading interval, -altert levels (autonomous operation)} +http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html + +Subscriptions are not permanent. The connection is (unlike HTTP) +stateful. + +Some messages may be persistent, but only one per topic. You will often +end up with a “proper” mq on the backend if queuing is needed. + +Push vs pull, central applications can push to clients} \end{frame} @@ -944,46 +964,32 @@ The size field is variable length encoded, 0-127 bytes is 1 byte, \end{frame} -\begin{frame}[fragile]{MQTT - The protocol - MQTT Topic - more} -\protect\hypertarget{mqtt---the-protocol---mqtt-topic---more}{} +\begin{frame}{MQTT - The protocol - Keep alive} +\protect\hypertarget{mqtt---the-protocol---keep-alive}{} -Enten må den holdes rett etter “\#\# MQTT - The protocol - MQTT Topic” -ellers kanskje flyttes etter “patterns”. +TODO -The central application is split: +\end{frame} + +\begin{frame}[fragile]{MQTT - The protocol - MQTT Topic} +\protect\hypertarget{mqtt---the-protocol---mqtt-topic}{} \begin{itemize} \tightlist \item - An aggregating agent: - - \begin{itemize} - \tightlist - \item - \texttt{myapp/\#/temperature} - \item - \texttt{myapp/\#/humidity} - \end{itemize} + Topic name: \texttt{foo/bar/baz} \item - Emailing agent + Topic filter \begin{itemize} \tightlist \item - \texttt{myapp/\$device-id/altert} - \end{itemize} -\item - Publishes on: - - \begin{itemize} - \tightlist + \texttt{foo/bar/?} \item - \texttt{myapp/\$device-id/command} + \texttt{foo/\#} \end{itemize} \end{itemize} -\note{} - \end{frame} \begin{frame}[fragile]{MQTT - The protocol - Retained message} @@ -1092,90 +1098,103 @@ Broker \end{frame} -\begin{frame}{MQTT - Patterns} -\protect\hypertarget{mqtt---patterns}{} +\begin{frame}{MQTT - The protocol - Client id} +\protect\hypertarget{mqtt---the-protocol---client-id}{} -Må utvides +TODO -Explain: +\end{frame} -\begin{itemize} -\tightlist -\item - Push vs pull, central applications can push to clients -\item - mostly mqtt, some http -\item - Client id - sparker ut gamle koblinger -\item - Keep alive / ping meldinger -\item - Alternative transporter - websockets(!) -\end{itemize} +\begin{frame}{Device and application architecture with MQTT} +\protect\hypertarget{device-and-application-architecture-with-mqtt}{} -\end{frame} +\begin{center} +\begin{tikzpicture} -\begin{frame}{MQTT - Implementations} -\protect\hypertarget{mqtt---implementations}{} +\path + (-3 cm, 0) node (c1_label) {Device \#1} + ( 0 cm, 0) node (c2_label) {Device \#2} + ( 3 cm, 0) node (c3_label) {Device \#3} -\begin{itemize} -\tightlist -\item - Mosquitto -\item - Eclipse Paho -\item - RabbitMQ -\item - ActiveMQ -\end{itemize} + (0, -3 cm) node (broker_label) {Broker} + (0, -6 cm) node (central_label) {Central} +; -\note{RabbitMQ has a separate connector that must be installed Not sure -about ActiveMQ but it is at least a part of the project so it is -releases at the same time.} +\node (c1)[draw, circle, fit=(c1_label)] {}; +\node (c2)[draw, circle, fit=(c2_label)] {}; +\node (c3)[draw, circle, fit=(c3_label)] {}; +\node (central)[draw, circle, fit=(central_label)] {}; +\node (broker)[draw, rectangle, thick, inner ysep=5 mm, inner xsep=10 mm, fit=(broker_label)] {}; + +\draw[{Latex[length=4mm, round]}-{Latex[length=4mm, round]}] (c1) to [bend right] (broker); +\draw[{Latex[length=4mm, round]}-{Latex[length=4mm, round]}] (c2) -- (broker); +\draw[{Latex[length=4mm, round]}-{Latex[length=4mm, round]}] (c3) to [bend left] (broker); +\draw[{Latex[length=4mm, round]}-{Latex[length=4mm, round]}] (central) -- (broker); + +\end{tikzpicture} + +\end{center} \end{frame} -\begin{frame}{MQTT Cloud Connectors} -\protect\hypertarget{mqtt-cloud-connectors}{} +\begin{frame}[fragile]{MQTT Topic} +\protect\hypertarget{mqtt-topic}{} + +The temperature sensor: \begin{itemize} \tightlist \item - Cloud + Publishes on: \begin{itemize} \tightlist \item - Amazon IoT - \item - Google Cloud IoT + \texttt{myapp/\$device-id/temperature} \item - Microsoft Azure IoT + \texttt{myapp/\$device-id/humidity} \item - CloudMQTT (at Heroku) + \texttt{myapp/\$device-id/altert} \end{itemize} \item - DIY + Subscribes to: \begin{itemize} \tightlist \item - ThingMQ - \item - HiveMQ + \texttt{myapp/\$device-id/command} \end{itemize} \end{itemize} -\note{In between are: +The central application: \begin{itemize} \tightlist \item - self hosted + Subscribes to: + + \begin{itemize} + \tightlist + \item + \texttt{myapp/\#/temperature} + \item + \texttt{myapp/\#/humidity} + \end{itemize} \item - Generic bridges -\end{itemize}} + Publishes on: + + \begin{itemize} + \tightlist + \item + \texttt{myapp/\$device-id/command} + \end{itemize} +\end{itemize} + +\note{Typical first round of implementation. + +Commands can be: * load new firmware (maybe an URL and firmware +signature). * Set new calibration values * Change reading interval, +altert levels (autonomous operation)} \end{frame} @@ -1228,15 +1247,89 @@ PubSubClient is our MQTT client implementation. \end{frame} -\begin{frame}{Assignment: Network play time} -\protect\hypertarget{assignment-network-play-time}{} +\begin{frame}[fragile]{Assignment} +\protect\hypertarget{assignment}{} \begin{itemize} +\tightlist +\item + \texttt{mqtt} +\end{itemize} + +\end{frame} + +\begin{frame}[fragile]{MQTT topic architecture} +\protect\hypertarget{mqtt-topic-architecture}{} + +The central application is split: + +\begin{itemize} +\tightlist \item - Measure round trip time/latency. Measure UDP, TCP. Measure when the - packet size is greater than the MTU + An aggregating agent: + + \begin{itemize} + \tightlist + \item + \texttt{myapp/\#/temperature} + \item + \texttt{myapp/\#/humidity} + \end{itemize} \item - Notice variations in RTT + Emailing agent + + \begin{itemize} + \tightlist + \item + \texttt{myapp/\$device-id/altert} + \end{itemize} +\item + Publishes on: + + \begin{itemize} + \tightlist + \item + \texttt{myapp/\$device-id/command} + \end{itemize} \end{itemize} +\note{} + +\end{frame} + +\begin{frame}{MQTT - Patterns} +\protect\hypertarget{mqtt---patterns}{} + +\begin{itemize} +\tightlist +\item + Combining MQTT and HTTP +\item + Using web sockets transport +\end{itemize} + +\end{frame} + +\begin{frame}[fragile]{Assignment} +\protect\hypertarget{assignment-1}{} + +\begin{itemize} +\tightlist +\item + \texttt{mqtt2} +\end{itemize} + +\end{frame} + +\begin{frame}[fragile]{Assignment} +\protect\hypertarget{assignment-2}{} + +\begin{itemize} +\tightlist +\item + \texttt{mqtt3} +\end{itemize} + +\note{discussion: how to connect these two devices?} + \end{frame} diff --git a/slides/what-is-iot-text.pdf b/slides/what-is-iot-text.pdf index 5f9f0e1..2508346 100644 Binary files a/slides/what-is-iot-text.pdf and b/slides/what-is-iot-text.pdf differ diff --git a/slides/what-is-iot.md b/slides/what-is-iot.md index c3a74eb..e3c3591 100644 --- a/slides/what-is-iot.md +++ b/slides/what-is-iot.md @@ -6,7 +6,7 @@ header-includes: allbordercolors={0 0 0}, pdfborderstyle={/S/U/W 1}} - \usepackage{tikz} - \usetikzlibrary{angles,arrows,backgrounds,calc,chains,decorations,decorations.pathmorphing,decorations.pathreplacing,decorations.text,fit,positioning, quotes,shapes.arrows,shapes.geometric,shapes.symbols} + \usetikzlibrary{angles,arrows,arrows.meta,backgrounds,calc,chains,decorations,decorations.pathmorphing,decorations.pathreplacing,decorations.text,fit,matrix,positioning,quotes,shapes.arrows,shapes.geometric,shapes.symbols} !ifndef(QUICK) ~~~~~~ - \usepackage{fontspec} @@ -79,12 +79,12 @@ Sparkfun and Adafruit etc sell modules with all of these technologies. ## IoT Devices - Bluetooth 4/5 chips -Chip CPU Freq RAM Flash Price --------- -------- ---- -------- ------ ------ -nRF52810 Cortex-M4 64 MHz 24k 192k $1.88 -nRF52832 Cortex-M4F 32k 256k $2.54 - 64k 512k $2.59 -nRF52840 Cortex-M4F 256k 1024k $3.85 +Chip CPU Freq RAM Flash Price +-------- ---------- ------ ---- ----- ------ +nRF52810 Cortex-M4 64 MHz 24k 192k $1.88 +nRF52832 Cortex-M4F 32k 256k $2.54 + 64k 512k $2.59 +nRF52840 Cortex-M4F 256k 1024k $3.85 * nRF52810: High performance, entry-level Bluetooth 4/ANT/2.4GHz SoC * nRF52832: High performance Bluetooth 4/ANT/2.4GHz SoC @@ -264,6 +264,8 @@ This layer is not really much used in the IP stack * CoAP * (everything else..) +!comment +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## Details: IP !ifdef(REVEAL) @@ -280,19 +282,23 @@ This layer is not really much used in the IP stack Note that the "total length" field is 16 bits, 2 bytes, it's maximum value is 64k, 65536. ::: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## Details: IP !ifndef(QUICK)( \begin{center} -!include(images/IP-Header_eng.tex) +!include(images/ip-packet.pgf) \end{center} ) -!comment -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -![](images/IP-Header_eng.pdf) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## Details: UDP + +!ifndef(QUICK)( +\begin{center} +!include(images/udp-packet.pgf) +\end{center} +) # Lecture: ESP8266 @@ -396,11 +402,13 @@ class { void restart(); uint32_t getFreeHeap(); uint32_t getChipId(); + + ... } ESP; -~~~ // Usage ESP.restart(); +~~~ ## ESP Arduino APIs @@ -415,6 +423,8 @@ class { IPAddress subnetMask(); IPAddress gatewayIP(); IPAddress dnsIP(uint8_t dns_no = 0); + + ... } WiFi; // Usage: @@ -451,6 +461,41 @@ Version 3.1.1 er den som gjelder, V 3.1 er rar, de andre finnes ikke ::: +## MQTT - Implementations + +* Mosquitto +* Eclipse Paho +* RabbitMQ +* ActiveMQ + +::: notes + +RabbitMQ has a separate connector that must be installed +Not sure about ActiveMQ but it is at least a part of the project so it is releases at the same time. + +::: + +## MQTT Cloud Connectors + +* Cloud + * Amazon IoT + * Google Cloud IoT + * Microsoft Azure IoT + * CloudMQTT (at Heroku) + +* DIY + * ThingMQ + * HiveMQ + +::: notes + +In between are: + +* self hosted +* Generic bridges + +::: + ## MQTT - The protocol Agents have one of two roles: @@ -479,42 +524,7 @@ stateful. Some messages may be persistent, but only one per topic. You will often end up with a "proper" mq on the backend if queuing is needed. -::: - -## MQTT - The protocol - MQTT Topic - -* Topic name: `foo/bar/baz` -* Topic filter - * `foo/bar/?` - * `foo/#` - -## MQTT - The protocol - MQTT Topic - -The temperature sensor: - -* Publishes on: - * `myapp/$device-id/temperature` - * `myapp/$device-id/humidity` - * `myapp/$device-id/altert` -* Subscribes to: - * `myapp/$device-id/command` - -The central application: - -* Subscribes to: - * `myapp/#/temperature` - * `myapp/#/humidity` -* Publishes on: - * `myapp/$device-id/command` - -::: notes - -Typical first round of implementation. - -Commands can be: -* load new firmware (maybe an URL and firmware signature). -* Set new calibration values -* Change reading interval, altert levels (autonomous operation) +Push vs pull, central applications can push to clients ::: @@ -534,24 +544,16 @@ The size field is variable length encoded, 0-127 bytes is 1 byte, 128-16383 use ::: -## MQTT - The protocol - MQTT Topic - more - -Enten må den holdes rett etter "## MQTT - The protocol - MQTT Topic" ellers kanskje flyttes etter "patterns". - -The central application is split: - -* An aggregating agent: - * `myapp/#/temperature` - * `myapp/#/humidity` -* Emailing agent - * `myapp/$device-id/altert` +## MQTT - The protocol - Keep alive -* Publishes on: - * `myapp/$device-id/command` +TODO -::: notes +## MQTT - The protocol - MQTT Topic -::: +* Topic name: `foo/bar/baz` +* Topic filter + * `foo/bar/?` + * `foo/#` ## MQTT - The protocol - Retained message @@ -598,50 +600,45 @@ Broker * `$app/$device/online` * `0` -## MQTT - Patterns - -Må utvides - -Explain: +## MQTT - The protocol - Client id -* Push vs pull, central applications can push to clients -* mostly mqtt, some http -* Client id - sparker ut gamle koblinger -* Keep alive / ping meldinger -* Alternative transporter - websockets(!) +TODO -## MQTT - Implementations - -* Mosquitto -* Eclipse Paho -* RabbitMQ -* ActiveMQ +## Device and application architecture with MQTT -::: notes +!ifndef(QUICK)( +\begin{center} +!include(images/mqtt-example-architecture.pgf) +\end{center} +) -RabbitMQ has a separate connector that must be installed -Not sure about ActiveMQ but it is at least a part of the project so it is releases at the same time. +## MQTT Topic -::: +The temperature sensor: -## MQTT Cloud Connectors +* Publishes on: + * `myapp/$device-id/temperature` + * `myapp/$device-id/humidity` + * `myapp/$device-id/altert` +* Subscribes to: + * `myapp/$device-id/command` -* Cloud - * Amazon IoT - * Google Cloud IoT - * Microsoft Azure IoT - * CloudMQTT (at Heroku) +The central application: -* DIY - * ThingMQ - * HiveMQ +* Subscribes to: + * `myapp/#/temperature` + * `myapp/#/humidity` +* Publishes on: + * `myapp/$device-id/command` ::: notes -In between are: +Typical first round of implementation. -* self hosted -* Generic bridges +Commands can be: +* load new firmware (maybe an URL and firmware signature). +* Set new calibration values +* Change reading interval, altert levels (autonomous operation) ::: @@ -686,9 +683,42 @@ void reconnect() { This is blocking! ::: -## Assignment: Network play time +## Assignment + +* `mqtt` + +## MQTT topic architecture + +The central application is split: + +* An aggregating agent: + * `myapp/#/temperature` + * `myapp/#/humidity` +* Emailing agent + * `myapp/$device-id/altert` + +* Publishes on: + * `myapp/$device-id/command` + +::: notes + +::: + +## MQTT - Patterns + +* Combining MQTT and HTTP +* Using web sockets transport + +## Assignment + +* `mqtt2` -* Measure round trip time/latency. Measure UDP, TCP. Measure when the - packet size is greater than the MTU +## Assignment -* Notice variations in RTT +* `mqtt3` + +::: notes + +discussion: how to connect these two devices? + +::: -- cgit v1.2.3