aboutsummaryrefslogtreecommitdiff
path: root/slides/what-is-iot.md
diff options
context:
space:
mode:
Diffstat (limited to 'slides/what-is-iot.md')
-rw-r--r--slides/what-is-iot.md100
1 files changed, 89 insertions, 11 deletions
diff --git a/slides/what-is-iot.md b/slides/what-is-iot.md
index ef11ca3..c3a74eb 100644
--- a/slides/what-is-iot.md
+++ b/slides/what-is-iot.md
@@ -376,17 +376,58 @@ config.h is created by "new tab".
## Generic Arduino APIs
+~~~c++
// Pin: D0, D1, etc.
// Mode: OUTPUT, INPUT, INPUT_PULLUP
+void pinMode(uint8_t pin, uint8_t mode);
+
+// State: HIGH, LOW, true/false, 1/0
+void digitalWrite(uint8_t pin, uint8_t state);
+int digitalRead(uint8_t pin);
+
+unsigned long now millis();
+unsigned long now micros();
+~~~
+
+## ESP Arduino APIs
~~~c++
-pinMode(pin, mode);
+class {
+ void restart();
+ uint32_t getFreeHeap();
+ uint32_t getChipId();
+} ESP;
+~~~
+
+// Usage
+ESP.restart();
-digitalWrite(pin, state);
+## ESP Arduino APIs
+
+~~~c++
+class {
+ String macAddress();
-state = digitalRead(pin);
+ wl_status_t status();
+ int32_t RSSI();
+
+ IPAddress localIP();
+ IPAddress subnetMask();
+ IPAddress gatewayIP();
+ IPAddress dnsIP(uint8_t dns_no = 0);
+} WiFi;
+
+// Usage:
+
+Serial.println(WiFi.localIP().toString());
~~~
+::: notes
+
+http://arduino-esp8266.readthedocs.io/en/latest/libraries.html
+
+:::
+
# Lecture: MQTT
## MQTT
@@ -396,13 +437,17 @@ state = digitalRead(pin);
::: notes
-MQTT is *the* standard for IoT applications (and lots of other useful stuff to). Using HTTP is just silly.
+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.
+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).
+Version 3.1.1 er den som gjelder, V 3.1 er rar, de andre finnes ikke
+(før standardisering).
:::
@@ -600,15 +645,48 @@ In between are:
:::
-# Assignments
+## MQTT on Arduino
-## Assignment 1: Blink a led
+PubSubClient is our MQTT client implementation.
-## Assignment 2: Connect to Wi-Fi
+~~~c++
+WiFiClient wifiClient;
+PubSubClient mqtt(wifiClient);
+
+void callback(char* topic,
+ byte* payload,
+ unsigned int length);
-## Assignment 3: Connect to MQTT broker
+void setup() {
+ // Configure WiFi
+ mqtt.setServer(mqtt_server, 1883);
+ mqtt.setCallback(callback);
+}
+~~~
+
+## MQTT on Arduino
+
+~~~c++
+void loop() {
+ if (!mqtt.connected())
+ reconnect();
+ else
+ mqtt.loop();
+ // Do work
+}
+
+void reconnect() {
+ while (!mqtt.connect(client_id));
+
+ mqtt.subscribe(topic_pattern);
+}
+~~~
+
+::: notes
+This is blocking!
+:::
-## Assignment 4: Network play time
+## Assignment: Network play time
* Measure round trip time/latency. Measure UDP, TCP. Measure when the
packet size is greater than the MTU