From 42ec7df723ece5c2c4400d8db24e3a2ac6b826d0 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 25 Apr 2018 09:03:31 +0200 Subject: wip --- arduino/01-blink-a-led/Makefile | 4 + arduino/01-blink-a-led/blink-a-led.md | 39 ++++++ arduino/01-blink-a-led/blink-a-led.pdf | Bin 0 -> 703496 bytes arduino/01-blink-a-led/schematic/assignment-1.fzz | Bin 0 -> 21480 bytes .../01-blink-a-led/schematic/assignment-1_bb.pdf | Bin 0 -> 354599 bytes .../schematic/assignment-1_schem.pdf | Bin 0 -> 263607 bytes .../solution/assignment-1/assignment-1.ino | 20 +++ arduino/Makefile | 5 + arduino/Makefile.assignment | 8 ++ arduino/client1/client1.ino | 71 ++++++++++ arduino/client1/config.h | 5 + host/udp-client.py | 31 +++++ host/udp-server.py | 18 +++ slides/README.md | 2 + slides/what-is-iot-reveal.html | 151 ++++++++++++++++++--- slides/what-is-iot-slides.pdf | Bin 221761 -> 571648 bytes slides/what-is-iot-slides.tex | 113 ++++++++++++--- slides/what-is-iot-text.pdf | Bin 87314 -> 689296 bytes slides/what-is-iot.md | 67 ++++++--- 19 files changed, 480 insertions(+), 54 deletions(-) create mode 100644 arduino/01-blink-a-led/Makefile create mode 100644 arduino/01-blink-a-led/blink-a-led.md create mode 100644 arduino/01-blink-a-led/blink-a-led.pdf create mode 100644 arduino/01-blink-a-led/schematic/assignment-1.fzz create mode 100644 arduino/01-blink-a-led/schematic/assignment-1_bb.pdf create mode 100644 arduino/01-blink-a-led/schematic/assignment-1_schem.pdf create mode 100644 arduino/01-blink-a-led/solution/assignment-1/assignment-1.ino create mode 100644 arduino/Makefile create mode 100644 arduino/Makefile.assignment create mode 100644 arduino/client1/client1.ino create mode 100644 arduino/client1/config.h create mode 100755 host/udp-client.py create mode 100755 host/udp-server.py diff --git a/arduino/01-blink-a-led/Makefile b/arduino/01-blink-a-led/Makefile new file mode 100644 index 0000000..b015ec1 --- /dev/null +++ b/arduino/01-blink-a-led/Makefile @@ -0,0 +1,4 @@ +DIR=01-blink-a-led +A=blink-a-led + +include $(BASEDIR)/Makefile.assignment diff --git a/arduino/01-blink-a-led/blink-a-led.md b/arduino/01-blink-a-led/blink-a-led.md new file mode 100644 index 0000000..f4b3fa1 --- /dev/null +++ b/arduino/01-blink-a-led/blink-a-led.md @@ -0,0 +1,39 @@ +# Assignment: Blink a led + + +## Goal + +Check that your local environment is working properly. + +## Step 1 + +Create this schematic: + +![](schematic/assignment-1_schem.pdf) + +![](schematic/assignment-1_bb.pdf) + +The colors on the wires used does not matter. The resistors +orientation is not important, but the LED's orientation is important. + +## Step 2 + +Implement `setup()` and `loop()`. In `setup()` configure the LED pin and blink the LED in `loop()`. + +Use these functions: + +~~~ .c++ + +Serial.begin(115200); +Serial.println(string); + +pinMode(pin, mode); +digitalWrite(pin, state); // HIGH or LOW +delay(); + +~~~ + +## Tips + +* It is useful to print a startup message just to see when the + application has started. diff --git a/arduino/01-blink-a-led/blink-a-led.pdf b/arduino/01-blink-a-led/blink-a-led.pdf new file mode 100644 index 0000000..de719fd Binary files /dev/null and b/arduino/01-blink-a-led/blink-a-led.pdf differ diff --git a/arduino/01-blink-a-led/schematic/assignment-1.fzz b/arduino/01-blink-a-led/schematic/assignment-1.fzz new file mode 100644 index 0000000..da3ad5b Binary files /dev/null and b/arduino/01-blink-a-led/schematic/assignment-1.fzz differ diff --git a/arduino/01-blink-a-led/schematic/assignment-1_bb.pdf b/arduino/01-blink-a-led/schematic/assignment-1_bb.pdf new file mode 100644 index 0000000..0995ece Binary files /dev/null and b/arduino/01-blink-a-led/schematic/assignment-1_bb.pdf differ diff --git a/arduino/01-blink-a-led/schematic/assignment-1_schem.pdf b/arduino/01-blink-a-led/schematic/assignment-1_schem.pdf new file mode 100644 index 0000000..a5241b2 Binary files /dev/null and b/arduino/01-blink-a-led/schematic/assignment-1_schem.pdf differ diff --git a/arduino/01-blink-a-led/solution/assignment-1/assignment-1.ino b/arduino/01-blink-a-led/solution/assignment-1/assignment-1.ino new file mode 100644 index 0000000..5b72892 --- /dev/null +++ b/arduino/01-blink-a-led/solution/assignment-1/assignment-1.ino @@ -0,0 +1,20 @@ +const int LED_PIN = D0; + +void setup() { + Serial.begin(115200); + Serial.println(); + Serial.println(); + Serial.println("Hello world!"); + pinMode(LED_PIN, OUTPUT); +} + +void loop() { + digitalWrite(LED_PIN, HIGH); + Serial.println("HIGH"); + delay(1000); + + digitalWrite(LED_PIN, LOW); + Serial.println("LOW"); + delay(1000); +} + diff --git a/arduino/Makefile b/arduino/Makefile new file mode 100644 index 0000000..c7ae828 --- /dev/null +++ b/arduino/Makefile @@ -0,0 +1,5 @@ +AS=01-blink-a-led + +BASEDIR=$(CURDIR) + +include $(patsubst %,%/Makefile,$(AS)) diff --git a/arduino/Makefile.assignment b/arduino/Makefile.assignment new file mode 100644 index 0000000..d05662f --- /dev/null +++ b/arduino/Makefile.assignment @@ -0,0 +1,8 @@ +all: $(DIR)/$(A).pdf + +$(DIR)/$(A).pdf: $(DIR)/$(A).md + @echo pandoc $(A).md + @cd $(DIR); pandoc $(patsubst $(DIR)/%,%,$<) -o $(patsubst $(DIR)/%,%,$@) + +clean: + @rm -f $(DIR)/$(A).pdf diff --git a/arduino/client1/client1.ino b/arduino/client1/client1.ino new file mode 100644 index 0000000..39eabfe --- /dev/null +++ b/arduino/client1/client1.ino @@ -0,0 +1,71 @@ +#include +#include + +#include "config.h" + +WiFiUDP Udp; +unsigned int localUdpPort = 5006; +IPAddress host_ip(192, 168, 10, 151); +unsigned int host_port = 5005; + +const int out_buf_len_start = 100; +const int out_buf_len_increment = 100; +const int out_buf_len_max = 2200; + +char buf[out_buf_len_max]; +int out_buf_len; + +static const char alphabet[] = "abcdefghijklmnopqrstuvxyz"; + +unsigned long time_start, time_end; + +void setup() { + Serial.begin(115200); + + Serial.printf("Connecting to %s ", wifi_ssid); + WiFi.begin(wifi_ssid, wifi_password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println(" connected"); + + Udp.begin(localUdpPort); + time_start = millis(); + out_buf_len = out_buf_len_start; +} + +void loop() { + + if (millis() > (time_start + 1000)) { + for (int i = 0; i < out_buf_len; i++) { + buf[i] = alphabet[i % sizeof(alphabet) - 1]; + } + out_buf_len += out_buf_len_increment; + if (out_buf_len > out_buf_len_max) { + out_buf_len = out_buf_len_start; + } + Serial.printf("Sending %d bytes to %s:%d\n", out_buf_len, host_ip.toString().c_str(), host_port); + Udp.beginPacket(host_ip, host_port); + Udp.write(buf, out_buf_len); + time_start = millis(); + auto ok = Udp.endPacket(); + + if (!ok) { + Serial.printf("Could not send packet with size %d\n", out_buf_len); + } + } + + int len = Udp.parsePacket(); + if (len) { + time_end = millis(); + Serial.printf("RX %s:%d: size=%d\n", Udp.remoteIP().toString().c_str(), Udp.remotePort(), len); + int len = Udp.read(buf, sizeof(buf)); + Serial.printf("len=%d\n"); + if (len > 0) { + buf[len] = 0; + } + Serial.printf("RTT: %d ms. Payload:%s\n", int(time_end - time_start), buf); + } +} + diff --git a/arduino/client1/config.h b/arduino/client1/config.h new file mode 100644 index 0000000..ea9affe --- /dev/null +++ b/arduino/client1/config.h @@ -0,0 +1,5 @@ +#pragma once + +const char wifi_ssid[] = "***REMOVED***"; +const char wifi_password[] = "***REMOVED***"; + diff --git a/host/udp-client.py b/host/udp-client.py new file mode 100755 index 0000000..5e2b132 --- /dev/null +++ b/host/udp-client.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +import socket, asyncoro + +ip = "127.0.0.1" +ip = "192.168.10.151" +port = 5005 +msg = "Hello, World!" + +print("UDP target IP: {}".format(ip)) +print("UDP target port: {}".format(port)) +print("message: {}".format(msg)) + +sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + +start = None + +def client(coro=None): + buffer_size = 64 * 1024 + print("Waiting for packet") + msg, (ip, port) = yield sock.recvfrom(buffer_size) + end = time.process_time() + print("Received '{}' from {}:{}".format(msg, ip, port)) + print("RTT: {:.3f} ms".format((end - start) * 1000)) + +asyncoro.Coro(client) +import time +time.sleep(0.1) +print("Sending") +start = time.process_time() +sock.sendto(msg.encode("utf-8"), (ip, port)) diff --git a/host/udp-server.py b/host/udp-server.py new file mode 100755 index 0000000..79bbe73 --- /dev/null +++ b/host/udp-server.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +import socket + +UDP_IP = "0.0.0.0" +UDP_PORT = 5005 + +sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +sock.bind((UDP_IP, UDP_PORT)) + +buffser_size = 64 * 1024 + +while True: + data, (remote_ip, remote_port) = sock.recvfrom(buffser_size) + s = data.decode("utf-8", "ignore") + print("=> {}:{}: size={}, packet={}".format(remote_ip, remote_port, len(data), s)) + sock.sendto(data, (remote_ip, remote_port)) + diff --git a/slides/README.md b/slides/README.md index 912b907..9d1d71e 100644 --- a/slides/README.md +++ b/slides/README.md @@ -3,3 +3,5 @@ * Some TikZ diagrams where taken from: https://github.com/tabascoeye/TikZ-diagrams/tree/master/networking (Beerwarae licensed) +* NodeMCU picture from: https://i2.wp.com/electronilab.co/wp-content/uploads/2016/02/NodeMCU-%E2%80%93-Board-de-desarrollo-con-m%C3%B3dulo-ESP8266-WiFi-y-Lua-4.jpg +* Fritzing model of NodeMCU: https://github.com/roman-minyaylov/fritzing-parts/tree/master/esp8266-nodemcu-v3 diff --git a/slides/what-is-iot-reveal.html b/slides/what-is-iot-reveal.html index 1ad9d7b..a2f7d9e 100644 --- a/slides/what-is-iot-reveal.html +++ b/slides/what-is-iot-reveal.html @@ -40,7 +40,16 @@

Trygve Laugstøl <trygvis@trygvis.io>

-

What is IoT

+

What is IoT

+

wat png

+

+
+

wat pdf

+

+
+

wat svg

+

+

What is IoT

  • Not “a computer connected to the internet” @@ -77,22 +86,26 @@
  • Network bandwidth and/or latency
  • Storage
-
  • Connected +
  • Has connectivity
    • Bluetooth
    • Wi-Fi
    • NB-IoT
    • -
    • LTE Cat-M
    • +
    • LTE Cat-M
    • +
    • LoRA
    • +
    • Proprietary radio
    • +
  • + +
    -

    Typical IoT chips - Bluetooth 4/5

    +
    +

    IoT Devices - Bluetooth 4/5 chips

    @@ -114,25 +127,124 @@ - - - - - - + + + + + + + + + + + + + + + + + + + + + +
    $1.88
    High performance,entry-level Bluetooth4/ANT/2.4GHz SoCnRF52832Cortex-M4F32k256k$2.54
    64k512k$2.59
    nRF52840Cortex-M4F256k1024k$3.85
    -

    nRF52832 Cortex-M4F 32k 256k $2.54 64k 512k $2.59 High performance Bluetooth 4/ANT/2.4GHz SoC

    -

    nRF52840 Cortex-M4F 256k 1024k $3.85 Advanced multi-protocol System-on-Chip Supporting: Bluetooth 5, ANT/ANT+, 802.15.4 and 2.4GHz proprietary

    +
      +
    • nRF52810: High performance, entry-level Bluetooth 4/ANT/2.4GHz SoC
    • +
    • nRF52832: High performance Bluetooth 4/ANT/2.4GHz SoC
    • +
    • nRF52840: Advanced multi-protocol System-on-Chip Supporting: Bluetooth 5, ANT/ANT+, 802.15.4 and 2.4GHz proprietary
    • +
    +
    +

    IoT Devices - LoRA

    +

    Modules

    + + + + + + + + + + + + + + + + + + + + + + + + + +
    ModuleData RatePrice
    RN2483A-I/RM104$12.05 @ 250
    CMWX1ZZABZ-078SX1276$10.74 @ 1000
    RF-LORA-868-SOSX1272$16.55 @ 1000
    +

    Chips

    + + + + + + + + + + + + + + + + + + + + + + + + + +
    ChipPrice
    SX1281$3.23
    SX1272$4.25
    SX1276$4.25
    SX1279$4.74
    + -
    -

    Typical IoT chips - Wi-Fi

    +
    +

    IoT Devices - NB-IoT

    + + + + + + + + + + + + + + + + + +
    ModulePrice
    uBlox SARA-N210~$10 @ 100
    Sierra Wireless HL7800_1103933$15.72
    +
    +

    IoT Devices - Wi-Fi

    @@ -290,6 +402,9 @@

    Lecture: ESP8266

    NodeMCU hardware

    +

    +
    +

    NodeMCU hardware

    ESP8266 software layers

    diff --git a/slides/what-is-iot-slides.pdf b/slides/what-is-iot-slides.pdf index 6e89140..9eb29db 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 f6a35b4..e3646f7 100644 --- a/slides/what-is-iot-slides.tex +++ b/slides/what-is-iot-slides.tex @@ -78,7 +78,7 @@ What differentiates a computer from an IoT device?} Storage \end{itemize} \item - Connected + Has connectivity \begin{itemize} \tightlist @@ -89,22 +89,30 @@ What differentiates a computer from an IoT device?} \item NB-IoT \item - LTE Cat-M + LTE Cat-M \item - IR + LoRA \item - UART - \item - CAN + Proprietary radio \end{itemize} \end{itemize} -\note{} +\note{\begin{itemize} +\tightlist +\item + IR +\item + UART +\item + CAN +\end{itemize} + +Sparkfun and Adafruit etc sell modules with all of these technologies.} \end{frame} -\begin{frame}{Typical IoT chips - Bluetooth 4/5} -\protect\hypertarget{typical-iot-chips---bluetooth-45}{} +\begin{frame}{IoT Devices - Bluetooth 4/5 chips} +\protect\hypertarget{iot-devices---bluetooth-45-chips}{} \begin{longtable}[]{@{}llllll@{}} \toprule @@ -112,17 +120,22 @@ Chip & CPU & Freq & RAM & Flash & Price\tabularnewline \midrule \endhead nRF52810 & Cortex-M4 & 64 M & Hz 24k & 192k & \$1.88\tabularnewline -High perf & ormance, & entry & -level Bl & uetooth & 4/ANT/2.4GHz -SoC\tabularnewline +nRF52832 & Cortex-M4 & F & 32k & 256k & \$2.54\tabularnewline +& & & 64k & 512k & \$2.59\tabularnewline +nRF52840 & Cortex-M4 & F & 256k & 1024k & \$3.85\tabularnewline \bottomrule \end{longtable} -nRF52832 Cortex-M4F 32k 256k \$2.54 64k 512k \$2.59 High performance -Bluetooth 4/ANT/2.4GHz SoC - -nRF52840 Cortex-M4F 256k 1024k \$3.85 Advanced multi-protocol -System-on-Chip Supporting: Bluetooth 5, ANT/ANT+, 802.15.4 and 2.4GHz -proprietary +\begin{itemize} +\tightlist +\item + nRF52810: High performance, entry-level Bluetooth 4/ANT/2.4GHz SoC +\item + nRF52832: High performance Bluetooth 4/ANT/2.4GHz SoC +\item + nRF52840: Advanced multi-protocol System-on-Chip Supporting: Bluetooth + 5, ANT/ANT+, 802.15.4 and 2.4GHz proprietary +\end{itemize} \note{All quantities are 1000 pieces @@ -131,12 +144,70 @@ https://www.digikey.no/products/en/rf-if-and-rfid/rf-transceiver-ics/879?k=nrf51 nRF52832: these have different packagings, not only difference price -https://www.digikey.no/products/en/rf-if-and-rfid/rf-transceiver-ics/879?FV=1c0001\%2Cffe0036f\&quantity=3000\&ColumnSort=1000011\&page=1\&k=nrf52832\&pageSize=500\&pkeyword=nrf52810} +https://www.digikey.no/products/en/rf-if-and-rfid/rf-transceiver-ics/879?FV=1c0001\%2Cffe0036f\&quantity=3000\&ColumnSort=1000011\&page=1\&k=nrf52832\&pageSize=500\&pkeyword=nrf52810 + +nRF52810: High performance, entry-level Bluetooth 4/ANT/2.4GHz SoC +nRF52832: High performance Bluetooth 4/ANT/2.4GHz SoC nRF52840: Advanced +multi-protocol System-on-Chip Supporting: Bluetooth 5, ANT/ANT+, +802.15.4 and 2.4GHz proprietary} + +\end{frame} + +\begin{frame}{IoT Devices - LoRA} +\protect\hypertarget{iot-devices---lora}{} + +\begin{block}{Modules} + +\begin{longtable}[]{@{}lll@{}} +\toprule +Module & Data Rate & Price\tabularnewline +\midrule +\endhead +RN2483A-I/RM104 & & \$12.05 @ 250\tabularnewline +CMWX1ZZABZ-078 & SX1276 & \$10.74 @ 1000\tabularnewline +RF-LORA-868-SO & SX1272 & \$16.55 @ 1000\tabularnewline +\bottomrule +\end{longtable} + +\end{block} + +\begin{block}{Chips} + +\begin{longtable}[]{@{}ll@{}} +\toprule +Chip & Price\tabularnewline +\midrule +\endhead +SX1281 & \$3.23\tabularnewline +SX1272 & \$4.25\tabularnewline +SX1276 & \$4.25\tabularnewline +SX1279 & \$4.74\tabularnewline +\bottomrule +\end{longtable} + +\note{These modules require an external MCU, so does the chips.} + +\end{block} \end{frame} -\begin{frame}{Typical IoT chips - Wi-Fi} -\protect\hypertarget{typical-iot-chips---wi-fi}{} +\begin{frame}{IoT Devices - NB-IoT} +\protect\hypertarget{iot-devices---nb-iot}{} + +\begin{longtable}[]{@{}ll@{}} +\toprule +Module & Price\tabularnewline +\midrule +\endhead +uBlox SARA-N210 & \textasciitilde{}\$10 @ 100\tabularnewline +Sierra Wireless HL7800\_1103933 & \$15.72\tabularnewline +\bottomrule +\end{longtable} + +\end{frame} + +\begin{frame}{IoT Devices - Wi-Fi} +\protect\hypertarget{iot-devices---wi-fi}{} \begin{longtable}[]{@{}llllll@{}} \toprule @@ -963,6 +1034,8 @@ releases at the same time.} \begin{frame}{Assignment 1: Blink a led} \protect\hypertarget{assignment-1-blink-a-led}{} +\includegraphics{../arduino/assignment-1/solution/assignment-1_bb.pdf} + \end{frame} \begin{frame}{Assignment 2: Connect to Wi-Fi} diff --git a/slides/what-is-iot-text.pdf b/slides/what-is-iot-text.pdf index 8270d3e..6d02221 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 341e4d4..edc3940 100644 --- a/slides/what-is-iot.md +++ b/slides/what-is-iot.md @@ -53,38 +53,36 @@ What differentiates a computer from an IoT device? * CPU * Network bandwidth and/or latency * Storage -* Connected +* Has connectivity * Bluetooth * Wi-Fi * NB-IoT * LTE Cat-M - - * IR - * UART - * CAN + * LoRA + * Proprietary radio ::: notes +* IR +* UART +* CAN +Sparkfun and Adafruit etc sell modules with all of these technologies. ::: -## Typical IoT chips - Bluetooth 4/5 +## IoT Devices - Bluetooth 4/5 chips -!comment -~~~ -~~~ Chip CPU Freq RAM Flash Price -------- -------- ---- -------- ------ ------ nRF52810 Cortex-M4 64 MHz 24k 192k $1.88 -High performance, entry-level Bluetooth 4/ANT/2.4GHz SoC - nRF52832 Cortex-M4F 32k 256k $2.54 64k 512k $2.59 -High performance Bluetooth 4/ANT/2.4GHz SoC - nRF52840 Cortex-M4F 256k 1024k $3.85 -Advanced multi-protocol System-on-Chip Supporting: Bluetooth 5, ANT/ANT+, 802.15.4 and 2.4GHz proprietary + +* nRF52810: High performance, entry-level Bluetooth 4/ANT/2.4GHz SoC +* nRF52832: High performance Bluetooth 4/ANT/2.4GHz SoC +* nRF52840: Advanced multi-protocol System-on-Chip Supporting: Bluetooth 5, ANT/ANT+, 802.15.4 and 2.4GHz proprietary ::: notes @@ -96,9 +94,45 @@ nRF52832: these have different packagings, not only difference price https://www.digikey.no/products/en/rf-if-and-rfid/rf-transceiver-ics/879?FV=1c0001%2Cffe0036f&quantity=3000&ColumnSort=1000011&page=1&k=nrf52832&pageSize=500&pkeyword=nrf52810 +nRF52810: High performance, entry-level Bluetooth 4/ANT/2.4GHz SoC +nRF52832: High performance Bluetooth 4/ANT/2.4GHz SoC +nRF52840: Advanced multi-protocol System-on-Chip Supporting: Bluetooth 5, ANT/ANT+, 802.15.4 and 2.4GHz proprietary + +::: + +## IoT Devices - LoRA + +### Modules + +Module Data Rate Price +----- --------- ------ +RN2483A-I/RM104 $12.05 @ 250 +CMWX1ZZABZ-078 SX1276 $10.74 @ 1000 +RF-LORA-868-SO SX1272 $16.55 @ 1000 + +### Chips + +Chip Price +---- ------- +SX1281 $3.23 +SX1272 $4.25 +SX1276 $4.25 +SX1279 $4.74 + +::: notes + +These modules require an external MCU, so does the chips. + ::: -## Typical IoT chips - Wi-Fi +## IoT Devices - NB-IoT + +Module Price +------ ----- +uBlox SARA-N210 ~$10 @ 100 +Sierra Wireless HL7800_1103933 $15.72 + +## IoT Devices - Wi-Fi Chip CPU Freq ROM RAM Price ----- ------- ------- ----- ------ ------ @@ -305,7 +339,7 @@ Version 3.1.1 er den som gjelder, V 3.1 er rar, de andre finnes ikke (før stand ## MQTT - The protocol -Agents have one of two roles: +Agents have one of two roles: * *Client* * Publishes *messages* @@ -501,6 +535,7 @@ In between are: ## Assignment 1: Blink a led + ## Assignment 2: Connect to Wi-Fi ## Assignment 3: Connect to MQTT broker -- cgit v1.2.3