From a1035c3f39c0952e09571be076bf6a4cb2fb966c Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 20 Apr 2018 09:44:25 +0200 Subject: wip --- images/pp-template | 18 ++- images/qtikz-template.pgs | 32 ++--- toc.md | 16 ++- what-is-iot-reveal.html | 150 +++++++++++++++++++++-- what-is-iot-slides.pdf | Bin 57390 -> 67939 bytes what-is-iot-slides.tex | 305 +++++++++++++++++++++++++++++++++++++++++++++- what-is-iot-text.pdf | Bin 71346 -> 80980 bytes what-is-iot.md | 174 +++++++++++++++++++++++--- 8 files changed, 650 insertions(+), 45 deletions(-) diff --git a/images/pp-template b/images/pp-template index 33fa981..8021025 100755 --- a/images/pp-template +++ b/images/pp-template @@ -3,7 +3,23 @@ echo '\documentclass[preview]{standalone} \usepackage{blindtext} \usepackage[utf8]{inputenc} \usepackage{tikz} -\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,fit,positioning,shapes.symbols,chains,shapes.geometric,shapes.arrows,calc} +\usetikzlibrary{ + angles, + arrows, + backgrounds, + calc, + chains, + decorations, + decorations.pathmorphing, + decorations.pathreplacing, + decorations.text, + fit, + positioning, + quotes, + shapes.arrows, + shapes.geometric, + shapes.symbols, +} \usepackage{fontspec} \setsansfont{Verdana} diff --git a/images/qtikz-template.pgs b/images/qtikz-template.pgs index 34582f2..b05f8ef 100644 --- a/images/qtikz-template.pgs +++ b/images/qtikz-template.pgs @@ -7,21 +7,23 @@ \usepackage{tikz} -\usetikzlibrary{arrows, -decorations, -decorations.pathmorphing, -decorations.pathreplacing, -decorations.text, -backgrounds, -fit, -positioning, -shapes.symbols, -chains, -shapes.geometric, -shapes.arrows, -angles, -quotes, -calc} +\usetikzlibrary{ + angles, + arrows, + backgrounds, + calc, + chains, + decorations, + decorations.pathmorphing, + decorations.pathreplacing, + decorations.text, + fit, + positioning, + quotes, + shapes.arrows, + shapes.geometric, + shapes.symbols, +} \begin{document} diff --git a/toc.md b/toc.md index 785be3f..dd6db1d 100644 --- a/toc.md +++ b/toc.md @@ -20,9 +20,21 @@ * Details: IP * Details: IP * Lecture: ESP8266 aka NodeMCU aka ESP-12 + * ESP8266 software layers * Lecture: MQTT * MQTT - * MQTT Implementations + * 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 + * MQTT - Patterns + * MQTT - Implementations * MQTT Cloud Connectors * Notes - * Assignments +* Assignments + * Assignment 1: Blink a led + * Assignment 2: Connect to Wi-Fi + * Assignment 3: Connect to MQTT broker + * Assignment 4: Network play time diff --git a/what-is-iot-reveal.html b/what-is-iot-reveal.html index cf0d641..3a5698e 100644 --- a/what-is-iot-reveal.html +++ b/what-is-iot-reveal.html @@ -277,20 +277,149 @@

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.

-

Lecture: ESP8266 aka NodeMCU aka ESP-12

+

Lecture: ESP8266 aka NodeMCU aka ESP-12

+

ESP8266 software layers

+ +

Lecture: MQTT

MQTT

-
-

MQTT Implementations

+ +
+

MQTT - The protocol

+

Agents have one of two roles:

+
    +
  • Client +
      +
    • Publishes messages
    • +
    • Subscribes / unsubscribes to topics
    • +
  • +
  • Broker (aka Server) +
      +
    • Handles network connections
    • +
    • Keeps subscription state
    • +
    • Manages client +
        +
      • Disconnects
      • +
      • (last) will
      • +
    • +
    • Persistence
    • +
  • +
+ +
+

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

+
    +
  • Size oriented
  • +
  • Flags indicate type of remaining bytes +
      +
    • Packet type
    • +
    • Topic name
    • +
    • 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 +
      +
    • myapp/$device-id/altert
    • +
  • +
  • Publishes on: +
      +
    • myapp/$device-id/command
    • +
  • +
+ +
+

MQTT - The protocol

+
+

MQTT - Patterns

+

Må utvides

+

Explain:

+
    +
  • Message sizes with MQTT
  • +
  • “will” messages
  • +
  • Push vs pull, central applications can push to clients
  • +
  • mostly mqtt, some http
  • +
+
+

MQTT - Implementations

  • Mosquitto
  • Eclipse Paho
  • -
  • Redis with MQTT connector
  • +
  • RabbitMQ
  • +
  • ActiveMQ
+

MQTT Cloud Connectors

    @@ -315,11 +444,18 @@
-

Notes

-

Assignments

+

Notes

+

Assignments

+

Assignment 2: Connect to Wi-Fi

+
+

Assignment 3: Connect to MQTT broker

+
+

Assignment 4: Network play time

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

  • -
  • Measure ISR timing

  • +
  • Notice variations in RTT

diff --git a/what-is-iot-slides.pdf b/what-is-iot-slides.pdf index 7f99fd3..59b1f24 100644 Binary files a/what-is-iot-slides.pdf and b/what-is-iot-slides.pdf differ diff --git a/what-is-iot-slides.tex b/what-is-iot-slides.tex index ea08852..bf541c1 100644 --- a/what-is-iot-slides.tex +++ b/what-is-iot-slides.tex @@ -178,6 +178,13 @@ TX\strut \end{frame} +\begin{frame}{ESP8266 details - Arduino} +\protect\hypertarget{esp8266-details---arduino}{} + +https://github.com/esp8266/Arduino + +\end{frame} + \hypertarget{going-back-to-basics}{% \section{Going back to basics}\label{going-back-to-basics}} @@ -354,6 +361,15 @@ maximum value is 64k, 65536.} \end{frame} +\hypertarget{lecture-esp8266-aka-nodemcu-aka-esp-12}{% +\section{Lecture: ESP8266 aka NodeMCU aka +ESP-12}\label{lecture-esp8266-aka-nodemcu-aka-esp-12}} + +\begin{frame}{ESP8266 software layers} +\protect\hypertarget{esp8266-software-layers}{} + +\end{frame} + \hypertarget{lecture-mqtt}{% \section{Lecture: MQTT}\label{lecture-mqtt}} @@ -368,10 +384,253 @@ maximum value is 64k, 65536.} \href{https://en.wikipedia.org/wiki/MQTT}{Wikipedia: MQTT} \end{itemize} +\note{MQTT is \emph{the} standard for IoT applications (and lots of +other useful stuff to). Using HTTP is just silly. + +Supports SSL, and requires TCP. + +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).} + +\end{frame} + +\begin{frame}{MQTT - The protocol} +\protect\hypertarget{mqtt---the-protocol}{} + +Agents have one of two roles: + +\begin{itemize} +\tightlist +\item + \emph{Client} + + \begin{itemize} + \tightlist + \item + Publishes \emph{messages} + \item + Subscribes / unsubscribes to \emph{topics} + \end{itemize} +\item + \emph{Broker} (aka Server) + + \begin{itemize} + \tightlist + \item + Handles network connections + \item + Keeps subscription state + \item + Manages client + + \begin{itemize} + \tightlist + \item + Disconnects + \item + \emph{(last) will} + \end{itemize} + \item + Persistence + \end{itemize} +\end{itemize} + +\note{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}{} + +\begin{itemize} +\tightlist +\item + Topic name: \texttt{foo/bar/baz} +\item + Topic filter + + \begin{itemize} + \tightlist + \item + \texttt{foo/bar/?} + \item + \texttt{foo/\#} + \end{itemize} +\end{itemize} + +\end{frame} + +\begin{frame}[fragile]{MQTT - The protocol - MQTT Topic} +\protect\hypertarget{mqtt---the-protocol---mqtt-topic-1}{} + +The temperature sensor: + +\begin{itemize} +\tightlist +\item + Publishes on: + + \begin{itemize} + \tightlist + \item + \texttt{myapp/\$device-id/temperature} + \item + \texttt{myapp/\$device-id/humidity} + \item + \texttt{myapp/\$device-id/altert} + \end{itemize} +\item + Subscribes to: + + \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 + \item + \texttt{myapp/\#/temperature} + \item + \texttt{myapp/\#/humidity} + \end{itemize} +\item + 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} -\begin{frame}{MQTT Implementations} -\protect\hypertarget{mqtt-implementations}{} +\begin{frame}{MQTT - The protocol - MQTT Packet} +\protect\hypertarget{mqtt---the-protocol---mqtt-packet}{} + +\begin{itemize} +\tightlist +\item + Very small +\end{itemize} + +\begin{itemize} +\tightlist +\item + Packet type + flags +\item + Packet identifier +\item + Payload + + \begin{itemize} + \tightlist + \item + Size + \item + Payload + \end{itemize} +\end{itemize} + +\note{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.} + +\end{frame} + +\begin{frame}[fragile]{MQTT - The protocol - MQTT Topic - more} +\protect\hypertarget{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: + +\begin{itemize} +\tightlist +\item + An aggregating agent: + + \begin{itemize} + \tightlist + \item + \texttt{myapp/\#/temperature} + \item + \texttt{myapp/\#/humidity} + \end{itemize} +\item + 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}{} + +Må utvides + +Explain: + +\begin{itemize} +\tightlist +\item + Message sizes with MQTT +\item + “will” messages +\item + Push vs pull, central applications can push to clients +\item + mostly mqtt, some http +\end{itemize} + +\end{frame} + +\begin{frame}{MQTT - Implementations} +\protect\hypertarget{mqtt---implementations}{} \begin{itemize} \tightlist @@ -379,8 +638,16 @@ maximum value is 64k, 65536.} 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} @@ -414,20 +681,48 @@ maximum value is 64k, 65536.} \end{itemize} \end{itemize} +\note{In between are: + +\begin{itemize} +\tightlist +\item + self hosted +\item + Generic bridges +\end{itemize}} + \end{frame} \hypertarget{notes}{% \section{Notes}\label{notes}} -\begin{frame}{Assignments} -\protect\hypertarget{assignments}{} +\hypertarget{assignments}{% +\section{Assignments}\label{assignments}} + +\begin{frame}{Assignment 1: Blink a led} +\protect\hypertarget{assignment-1-blink-a-led}{} + +\end{frame} + +\begin{frame}{Assignment 2: Connect to Wi-Fi} +\protect\hypertarget{assignment-2-connect-to-wi-fi}{} + +\end{frame} + +\begin{frame}{Assignment 3: Connect to MQTT broker} +\protect\hypertarget{assignment-3-connect-to-mqtt-broker}{} + +\end{frame} + +\begin{frame}{Assignment 4: Network play time} +\protect\hypertarget{assignment-4-network-play-time}{} \begin{itemize} \item Measure round trip time/latency. Measure UDP, TCP. Measure when the packet size is greater than the MTU \item - Measure ISR timing + Notice variations in RTT \end{itemize} \end{frame} diff --git a/what-is-iot-text.pdf b/what-is-iot-text.pdf index b3f6aa4..8609058 100644 Binary files a/what-is-iot-text.pdf and b/what-is-iot-text.pdf differ diff --git a/what-is-iot.md b/what-is-iot.md index c4a1a63..3b1b570 100644 --- a/what-is-iot.md +++ b/what-is-iot.md @@ -6,11 +6,11 @@ header-includes: allbordercolors={0 0 0}, pdfborderstyle={/S/U/W 1}} - \usepackage{tikz} - \usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,fit,positioning,shapes.symbols,chains,shapes.geometric,shapes.arrows,calc} + \usetikzlibrary{angles,arrows,backgrounds,calc,chains,decorations,decorations.pathmorphing,decorations.pathreplacing,decorations.text,fit,positioning, quotes,shapes.arrows,shapes.geometric,shapes.symbols} !ifndef(QUICK) ~~~~~~ - \usepackage{fontspec} - \setsansfont{Verdana} + \setsansfont{Verdana} ~~~~~~ --- @@ -103,15 +103,15 @@ The ESP8266's RAM depends on which firmware stack is used. Physical is probably +--------------------------+----------------+ | State | Current usage | +==========================+===============:+ -| Off | 0.5 µA | +| Off | 0.5 µA | +--------------------------+----------------+ -| Deep sleep with RTC | 20 µA | +| Deep sleep with RTC | 20 µA | +--------------------------+----------------+ | Light sleep (with Wi-Fi) | 1 mA | +--------------------------+----------------+ | Sleep with peripherials | 15 mA | +--------------------------+----------------+ -| TX | 170 mA | +| TX | 170 mA | +--------------------------+----------------+ ::: notes @@ -241,6 +241,10 @@ Note that the "total length" field is 16 bits, 2 bytes, it's maximum value is 64 # Lecture: ESP8266 aka NodeMCU aka ESP-12 +## ESP8266 software layers + +!ifndef(QUICK)(!include(images/esp+arduino-sdks.pgf)) + # Lecture: MQTT ## MQTT @@ -248,23 +252,154 @@ Note that the "total length" field is 16 bits, 2 bytes, it's maximum value is 64 * *Message Queuing Telemetry Transport* * [Wikipedia: MQTT](https://en.wikipedia.org/wiki/MQTT) -## MQTT Implementations +::: notes + +MQTT is *the* standard for IoT applications (and lots of other useful stuff to). Using HTTP is just silly. + +Supports SSL, and requires TCP. + +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 - The protocol + +Agents have one of two roles: + +* *Client* + * Publishes *messages* + * Subscribes / unsubscribes to *topics* + +* *Broker* (aka Server) + * Handles network connections + * Keeps subscription state + * Manages client + * Disconnects + * *(last) will* + * Persistence + +::: notes + +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` + +::: 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) + +::: + +## MQTT - The protocol - MQTT Packet + +* Size oriented +* Flags indicate type of remaining bytes + * Packet type + * Topic name + * Payload + +::: notes + +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 + * `myapp/$device-id/altert` + +* Publishes on: + * `myapp/$device-id/command` + +::: notes + +::: + +## MQTT - Patterns + +Må utvides + +Explain: + +* Message sizes with MQTT +* "will" messages +* Push vs pull, central applications can push to clients +* mostly mqtt, some http + +## MQTT - Implementations * Mosquitto * Eclipse Paho -* Redis with MQTT connector +* 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 + * Amazon IoT + * Google Cloud IoT + * Microsoft Azure IoT + * CloudMQTT * DIY - * ThingMQ - * HiveMQ + * ThingMQ + * HiveMQ ::: notes @@ -275,11 +410,20 @@ In between are: ::: + # Notes -## Assignments +# Assignments + +## Assignment 1: Blink a led + +## Assignment 2: Connect to Wi-Fi + +## Assignment 3: Connect to MQTT broker + +## Assignment 4: Network play time * Measure round trip time/latency. Measure UDP, TCP. Measure when the packet size is greater than the MTU -* Measure ISR timing +* Notice variations in RTT -- cgit v1.2.3