aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--assignments/mqtt-with-button/mqtt-with-button.md14
-rw-r--r--assignments/mqtt-with-button/mqtt-with-button.pdfbin841020 -> 841066 bytes
-rw-r--r--assignments/mqtt-with-button/schematic/mqtt-with-button.fzzbin24221 -> 24142 bytes
-rw-r--r--assignments/mqtt-with-button/schematic/mqtt-with-button_bb.pdfbin449304 -> 449659 bytes
-rw-r--r--assignments/mqtt-with-button/schematic/mqtt-with-button_schem.pdfbin305478 -> 308141 bytes
-rw-r--r--slides/TODO.md16
-rw-r--r--slides/connected-arduino-slides.pdfbin293025 -> 293791 bytes
-rw-r--r--slides/connected-arduino-text.pdfbin64793 -> 298798 bytes
-rw-r--r--slides/connected-arduino.md37
-rw-r--r--slides/toc.md7
11 files changed, 67 insertions, 9 deletions
diff --git a/README.md b/README.md
index 3726b61..8ae53f3 100644
--- a/README.md
+++ b/README.md
@@ -25,6 +25,8 @@ This is the materials for a 1 hour workshop on IoT.
* Install Arduino IDE
* Install the "ESP8266 core" for Arduino, follow the guide on
https://github.com/esp8266/Arduino#installing-with-boards-manager.
+* Install PubSubClient library with Library manager from within the
+ Arduino IDE.
**Assignments**
diff --git a/assignments/mqtt-with-button/mqtt-with-button.md b/assignments/mqtt-with-button/mqtt-with-button.md
index 77f0b22..c825615 100644
--- a/assignments/mqtt-with-button/mqtt-with-button.md
+++ b/assignments/mqtt-with-button/mqtt-with-button.md
@@ -16,13 +16,17 @@ Wire up this schematic on the bread board:
# Step 2
-* Read button, print message on terminal
+* Tip: change upload speed to max.
+
+* Read button in `loop()`. If the button's state changes, print a
+ message.
+
+*Note:* reading the button in a busy loop is not really a best
+practice as it uses lots of energy. Instead use the `attachInterrupt`.
# Step 3
* Connect to the Wi-Fi network
- * Use `WiFi.localIP()`
-
* Connect to MQTT broker
# Step 4
@@ -32,6 +36,10 @@ Wire up this schematic on the bread board:
# Step 5 (Bonus)
+Subscripe to a topic and do something with the led.
+
+* Subscribe to the topic you're publishing to.
+
* Subscribe to the topic `ndc/$device-id/led`.
* Use the value to for example turn the LED on/off, or change the
diff --git a/assignments/mqtt-with-button/mqtt-with-button.pdf b/assignments/mqtt-with-button/mqtt-with-button.pdf
index 93079d7..8fcccf7 100644
--- a/assignments/mqtt-with-button/mqtt-with-button.pdf
+++ b/assignments/mqtt-with-button/mqtt-with-button.pdf
Binary files differ
diff --git a/assignments/mqtt-with-button/schematic/mqtt-with-button.fzz b/assignments/mqtt-with-button/schematic/mqtt-with-button.fzz
index 57e5e5d..1f56f4e 100644
--- a/assignments/mqtt-with-button/schematic/mqtt-with-button.fzz
+++ b/assignments/mqtt-with-button/schematic/mqtt-with-button.fzz
Binary files differ
diff --git a/assignments/mqtt-with-button/schematic/mqtt-with-button_bb.pdf b/assignments/mqtt-with-button/schematic/mqtt-with-button_bb.pdf
index aa0d283..8ba636a 100644
--- a/assignments/mqtt-with-button/schematic/mqtt-with-button_bb.pdf
+++ b/assignments/mqtt-with-button/schematic/mqtt-with-button_bb.pdf
Binary files differ
diff --git a/assignments/mqtt-with-button/schematic/mqtt-with-button_schem.pdf b/assignments/mqtt-with-button/schematic/mqtt-with-button_schem.pdf
index 3ce5de3..5d97abf 100644
--- a/assignments/mqtt-with-button/schematic/mqtt-with-button_schem.pdf
+++ b/assignments/mqtt-with-button/schematic/mqtt-with-button_schem.pdf
Binary files differ
diff --git a/slides/TODO.md b/slides/TODO.md
index 7d053b9..5b84672 100644
--- a/slides/TODO.md
+++ b/slides/TODO.md
@@ -4,4 +4,20 @@ Slide: *Device and application architecture with MQTT*
Illustrates that everyone connects to the broker, but messages can
be pushed. Contrast to HTTP.
+Slide: *MQTT on Arduino*
+* flytt callback til egen slide.
+* legg til Serial.println("connecting"); og Serial.println("connected");
+* sett mqtt_server = "trygvis.io";
+ditto på neste slide
+
+* vis client_id
+
* Assignments: D0 is the pin to use.
+
+
+MQTT
+* fix switch orientation
+* husk å gjøre preparations
+* screen shot av library manager og installering av PubSubClient
+
+* vis hvordan man formaterer stringer., clientId og subscription patterns.
diff --git a/slides/connected-arduino-slides.pdf b/slides/connected-arduino-slides.pdf
index 83e8750..cc258eb 100644
--- a/slides/connected-arduino-slides.pdf
+++ b/slides/connected-arduino-slides.pdf
Binary files differ
diff --git a/slides/connected-arduino-text.pdf b/slides/connected-arduino-text.pdf
index e5088b9..6882209 100644
--- a/slides/connected-arduino-text.pdf
+++ b/slides/connected-arduino-text.pdf
Binary files differ
diff --git a/slides/connected-arduino.md b/slides/connected-arduino.md
index 79ba123..16f93d4 100644
--- a/slides/connected-arduino.md
+++ b/slides/connected-arduino.md
@@ -126,6 +126,27 @@ class {
ESP.restart();
~~~
+## ESP
+
+~~~c++
+// Top of file
+#include <ESP8266WiFi.h>
+
+// In setup()
+WiFi.mode(WIFI_STA);
+WiFi.begin(ssid, password);
+
+while (WiFi.status() != WL_CONNECTED) {
+ delay(500);
+ Serial.print(".");
+}
+
+Serial.println("");
+Serial.println("WiFi connected");
+Serial.println("IP address: ");
+Serial.println(WiFi.localIP());
+~~~
+
## ESP Arduino APIs
~~~c++
@@ -447,6 +468,8 @@ Broker
PubSubClient is our MQTT client implementation.
~~~c++
+#include <PubSubClient.h>
+
WiFiClient wifiClient;
PubSubClient mqtt(wifiClient);
@@ -465,16 +488,24 @@ void setup() {
~~~c++
void loop() {
- if (!mqtt.connected())
+ if (!mqtt.connected()) {
reconnect();
- else
+ }
+ else {
mqtt.loop();
+ }
+
// Do work
}
void reconnect() {
- while (!mqtt.connect(client_id));
+ do {
+ Serial.println("Connecting to MQTT");
+ delay(1000);
+ } while (!mqtt.connect(client_id));
+ Serial.println("Connected to MQTT server");
+ // Subscribe to any topics you need
mqtt.subscribe(topic_pattern);
}
~~~
diff --git a/slides/toc.md b/slides/toc.md
index 6e54e03..227f00a 100644
--- a/slides/toc.md
+++ b/slides/toc.md
@@ -8,6 +8,8 @@
* Arduino file structure
* Generic Arduino APIs
* ESP Arduino APIs
+ * ESP
+#include <ESP8266WiFi.h>
* ESP Arduino APIs
* What is IoT
* What is IoT
@@ -19,16 +21,15 @@
* Lecture: MQTT
* MQTT
* Device and application architecture with MQTT
+ * MQTT Topic
* MQTT - Implementations
* MQTT Cloud Connectors
* MQTT - The protocol
- * MQTT - The protocol - MQTT Packet
- * MQTT Connect
* MQTT - The protocol - MQTT Topic
* MQTT - The protocol - Retained message
* MQTT - The protocol - Will message
- * MQTT Topic
* MQTT on Arduino
+#include <PubSubClient.h>
* MQTT on Arduino
* Assignment
* MQTT topic architecture