From a4cbbee0671ff20560c31a2f3945b6131496ab2b Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 13 Jun 2018 20:41:24 +0200 Subject: wip --- assignments/old/client1/client1.ino | 71 +++++++++++++++++++++ assignments/old/mqtt2/mqtt2.md | 10 +++ assignments/old/mqtt2/mqtt2.pdf | Bin 0 -> 51245 bytes assignments/old/mqtt3/mqtt3.md | 12 ++++ assignments/old/mqtt3/mqtt3.pdf | Bin 0 -> 53509 bytes assignments/old/network/network.md | 7 ++ .../old/read-temperature/read-temperature.md | 13 ++++ .../old/read-temperature/read-temperature.pdf | Bin 0 -> 794796 bytes .../schematic/read-temperature.fzz | Bin 0 -> 23036 bytes .../schematic/read-temperature_bb.pdf | Bin 0 -> 392490 bytes .../schematic/read-temperature_schem.pdf | Bin 0 -> 354997 bytes .../solution/read-temperature/read-temperature.ino | 24 +++++++ 12 files changed, 137 insertions(+) create mode 100644 assignments/old/client1/client1.ino create mode 100644 assignments/old/mqtt2/mqtt2.md create mode 100644 assignments/old/mqtt2/mqtt2.pdf create mode 100644 assignments/old/mqtt3/mqtt3.md create mode 100644 assignments/old/mqtt3/mqtt3.pdf create mode 100644 assignments/old/network/network.md create mode 100644 assignments/old/read-temperature/read-temperature.md create mode 100644 assignments/old/read-temperature/read-temperature.pdf create mode 100644 assignments/old/read-temperature/schematic/read-temperature.fzz create mode 100644 assignments/old/read-temperature/schematic/read-temperature_bb.pdf create mode 100644 assignments/old/read-temperature/schematic/read-temperature_schem.pdf create mode 100644 assignments/old/read-temperature/solution/read-temperature/read-temperature.ino (limited to 'assignments/old') diff --git a/assignments/old/client1/client1.ino b/assignments/old/client1/client1.ino new file mode 100644 index 0000000..39eabfe --- /dev/null +++ b/assignments/old/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/assignments/old/mqtt2/mqtt2.md b/assignments/old/mqtt2/mqtt2.md new file mode 100644 index 0000000..cfc623a --- /dev/null +++ b/assignments/old/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/old/mqtt2/mqtt2.pdf b/assignments/old/mqtt2/mqtt2.pdf new file mode 100644 index 0000000..fdd47f6 Binary files /dev/null and b/assignments/old/mqtt2/mqtt2.pdf differ diff --git a/assignments/old/mqtt3/mqtt3.md b/assignments/old/mqtt3/mqtt3.md new file mode 100644 index 0000000..2994e9a --- /dev/null +++ b/assignments/old/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/old/mqtt3/mqtt3.pdf b/assignments/old/mqtt3/mqtt3.pdf new file mode 100644 index 0000000..179a73e Binary files /dev/null and b/assignments/old/mqtt3/mqtt3.pdf differ diff --git a/assignments/old/network/network.md b/assignments/old/network/network.md new file mode 100644 index 0000000..8e49b24 --- /dev/null +++ b/assignments/old/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/old/read-temperature/read-temperature.md b/assignments/old/read-temperature/read-temperature.md new file mode 100644 index 0000000..31a32a8 --- /dev/null +++ b/assignments/old/read-temperature/read-temperature.md @@ -0,0 +1,13 @@ +# Read the temperature and humidity sensor DHT22 + +## Step 1 + +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/old/read-temperature/read-temperature.pdf b/assignments/old/read-temperature/read-temperature.pdf new file mode 100644 index 0000000..f1ec641 Binary files /dev/null and b/assignments/old/read-temperature/read-temperature.pdf differ diff --git a/assignments/old/read-temperature/schematic/read-temperature.fzz b/assignments/old/read-temperature/schematic/read-temperature.fzz new file mode 100644 index 0000000..52a9fa0 Binary files /dev/null and b/assignments/old/read-temperature/schematic/read-temperature.fzz differ diff --git a/assignments/old/read-temperature/schematic/read-temperature_bb.pdf b/assignments/old/read-temperature/schematic/read-temperature_bb.pdf new file mode 100644 index 0000000..79cc8eb Binary files /dev/null and b/assignments/old/read-temperature/schematic/read-temperature_bb.pdf differ diff --git a/assignments/old/read-temperature/schematic/read-temperature_schem.pdf b/assignments/old/read-temperature/schematic/read-temperature_schem.pdf new file mode 100644 index 0000000..d01ab4b Binary files /dev/null and b/assignments/old/read-temperature/schematic/read-temperature_schem.pdf differ diff --git a/assignments/old/read-temperature/solution/read-temperature/read-temperature.ino b/assignments/old/read-temperature/solution/read-temperature/read-temperature.ino new file mode 100644 index 0000000..b261dc5 --- /dev/null +++ b/assignments/old/read-temperature/solution/read-temperature/read-temperature.ino @@ -0,0 +1,24 @@ +#include +#include + +const auto DHTPIN = D1; +const auto DHTTYPE = DHT22; + +DHT_Unified dht(DHTPIN, DHTTYPE); + +void setup() { + Serial.begin(115200); + pinMode(D2, INPUT); + pinMode(D0, OUTPUT); +} + +void loop() { + if (digitalRead(D2) == HIGH) { + Serial.println("HIGH"); + } else { + Serial.println("LOW"); + } + digitalWrite(D0, digitalRead(D2)); + delay(100); +} + -- cgit v1.2.3