No ACL setup yet! Denying access to everyone.
en:edu:zmitac:macro:iot:lab
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:edu:zmitac:macro:iot:lab [2022/03/26 19:43] – [Laboratory scenarios] pczekalski | en:edu:zmitac:macro:iot:lab [2024/04/21 16:17] (current) – [Laboratory scenarios] pczekalski | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ===== Laboratory on the Internet of Things ===== | ===== Laboratory on the Internet of Things ===== | ||
| Welcome to the laboratory of the Internet of Things. | Welcome to the laboratory of the Internet of Things. | ||
| - | Students are about to perform a number of laboratory tasks. Each task is to be finished with a report summarizing on what and how it was done. The report should be prepared in PDF form and eventually ZIPped | + | Students are about to perform a number of laboratory tasks. Each task is to be finished with a report summarizing on what and how it was done. The report should be prepared in PDF form and eventually ZIPped with extra files like source code, resources, etc. |
| | | ||
| < | < | ||
| Line 12: | Line 12: | ||
| < | < | ||
| </ | </ | ||
| - | Note, this microcontroller even if its board reminds Arduino Uno has different logic voltage (here 0..3.3V while Arduino Uno uses classical 0..5V logic) and has different pinout numbering. Detail on the following figure: | + | Note, this microcontroller, even if its board reminds Arduino Uno has a different logic voltage (here 0..3.3V while Arduino Uno uses classical 0..5V logic) and has different pinout numbering. Detail on the following figure: |
| <figure wemosd1r2pinout> | <figure wemosd1r2pinout> | ||
| {{: | {{: | ||
| Line 31: | Line 31: | ||
| - | ==== VSCode, PlatformIO and project configuration ==== | + | ==== VSCode, PlatformIO, and project configuration ==== |
| - | In any case, creating a new project under PlatformIO should follow this general | + | In any case, creating a new project under PlatformIO should follow this general |
| <figure platformionewproject> | <figure platformionewproject> | ||
| {{: | {{: | ||
| Line 46: | Line 46: | ||
| </ | </ | ||
| - | It is also necessary to configure the serial port name that is used for uploading your firmware and to monitor | + | It is also necessary to configure the serial port name used for uploading your firmware and monitoring |
| < | < | ||
| ... | ... | ||
| Line 55: | Line 55: | ||
| === Running your code === | === Running your code === | ||
| - | To execute your code you need to compile it and upload it to the microcontroller.\\ | + | To execute your code, you need to compile it and upload it to the microcontroller.\\ |
| The easiest way to interact with PlatformIO is to use its blue ribbon bar, located at the bottom of the VSCode (image {{ref> | The easiest way to interact with PlatformIO is to use its blue ribbon bar, located at the bottom of the VSCode (image {{ref> | ||
| <figure pioribbon> | <figure pioribbon> | ||
| {{: | {{: | ||
| - | < | + | < |
| </ | </ | ||
| ==== Software ==== | ==== Software ==== | ||
| You will be writing an application for end nodes (ESP8266) in C++ using VS Code.\\ | You will be writing an application for end nodes (ESP8266) in C++ using VS Code.\\ | ||
| - | Additionally, | + | Additionally, |
| - | <note important> | + | <note important> |
| ==== Networking ==== | ==== Networking ==== | ||
| - | There is a WiFi 2.4GHz, IPv4 network available to the students. This is a PRIVATE network. This network is separated from the Internet but all connected devices | + | There is a WiFi 2.4GHz IPv4 network available to the students. This is a PRIVATE network. This network is separated from the Internet, but all connected devices can talk to one another. There is a DHCP server with networking addressing scope 192.168.90.10-192.168.90.254. |
| - | <note warning> | + | <note warning> |
| To connect to the wireless network, use the following credentials: | To connect to the wireless network, use the following credentials: | ||
| Line 80: | Line 80: | ||
| === MQTT === | === MQTT === | ||
| - | There is an MQTT Broker, binding WiFi PRIVATE network and the PUBLIC | + | There is an MQTT Broker, |
| - | You can access | + | You can access |
| * Address: 157.158.56.54 | * Address: 157.158.56.54 | ||
| * Port: 1883 for plain text, 8883 for secure communication | * Port: 1883 for plain text, 8883 for secure communication | ||
| Line 88: | Line 88: | ||
| * Password: vrel2018 | * Password: vrel2018 | ||
| - | You can also access | + | You can also access |
| * Address: 192.168.90.5 | * Address: 192.168.90.5 | ||
| * Port: 1883 for plain text, 8883 for secure communication | * Port: 1883 for plain text, 8883 for secure communication | ||
| Line 94: | Line 94: | ||
| * Password: vrel2018 | * Password: vrel2018 | ||
| + | <figure zmitacnetworkingiot> | ||
| + | {{: | ||
| + | < | ||
| + | </ | ||
| ==== Tracing ==== | ==== Tracing ==== | ||
| - | There is no direct debugging capability in this environment | + | There is no direct debugging capability in this environment. Yet, it is possible to send log/trace messages to the PC console over a serial (serial over USB) port, which is used for flashing. |
| - | To open serial communication, | + | To open serial communication, |
| <code c> | <code c> | ||
| Serial.begin(9600); | Serial.begin(9600); | ||
| </ | </ | ||
| - | 9600 is the default speed but you can change it in the '' | + | 9600 is the default speed, but you can change it in the '' |
| It is possible to send virtually any message to the console (keep in mind, you need explicitly open Serial | It is possible to send virtually any message to the console (keep in mind, you need explicitly open Serial | ||
| <code c> | <code c> | ||
| Line 109: | Line 113: | ||
| ... | ... | ||
| </ | </ | ||
| - | Both functions accept a wide range of argument types with no need to explicitly | + | Both functions accept a wide range of argument types without needing |
| - | <note tip>Note, there is a limit on the character set that is ASCII only. We suggest avoiding " | + | <note tip>Note: there is a limit on the character set that is ASCII only. We suggest avoiding " |
| ==== Laboratory scenarios ==== | ==== Laboratory scenarios ==== | ||
| - | All teams share the same scenario yet please note that in particular, | + | All teams share the same scenario yet; please note that MQTT messages exchanged between devices shall be coordinated among team members |
| - | <note tip>Mind keeping your code between meetings. It is regular that every next laboratory meeting you will extend your code by something extra.</ | + | <note tip>Mind keeping your code between meetings. It is regular that at every next laboratory meeting, you will extend your code by something extra.</ |
| < | < | ||
| Line 125: | Line 129: | ||
| - Sends a message via serial port to the serial port monitor: '' | - Sends a message via serial port to the serial port monitor: '' | ||
| - | <note tip>The GPIO the built-in LED is connected to is number 14. Physically it is located almost in the middle of the mainboard, under the display and its colour is blue.</ | + | <note tip>The GPIO the built-in LED is connected to is number 14. Physically, it is located almost in the middle of the mainboard, under the display, and its colour is blue.</ |
| <code c> | <code c> | ||
| #define LED_BUILTIN 14 | #define LED_BUILTIN 14 | ||
| </ | </ | ||
| - | Note, to use tracing with the '' | + | Note, to use tracing with the '' |
| < | < | ||
| ... | ... | ||
| Line 136: | Line 140: | ||
| ... | ... | ||
| </ | </ | ||
| + | Obligatory: | ||
| + | * Provide a solution using '' | ||
| Advanced: | Advanced: | ||
| - | * Use timer/ | + | * Use a timer/ |
| + | * | ||
| Report: | Report: | ||
| * Describe your approach and include source code in the report | * Describe your approach and include source code in the report | ||
| Line 147: | Line 154: | ||
| ** Using LCD **\\ | ** Using LCD **\\ | ||
| - | In this scenario, you will write an application that writes | + | In this scenario, you will write an application that reports |
| - | Your code shall implement a message '' | + | Your code shall implement a message '' |
| - | Additionally, | + | Additionally, |
| == The LCD Display == | == The LCD Display == | ||
| - | To control LCD it is easiest to use a software library (add to the '' | + | To control LCD, it is easiest to use a software library (add to the '' |
| < | < | ||
| ... | ... | ||
| Line 159: | Line 166: | ||
| </ | </ | ||
| - | Your LCD shield is a 2x16 characters | + | Your LCD shield is 2x16 characters. To initialize |
| <code c> | <code c> | ||
| const int rs = 12, en = 13, d4 = 4, d5 = 0, d6 = 2, d7 = 14; | const int rs = 12, en = 13, d4 = 4, d5 = 0, d6 = 2, d7 = 14; | ||
| Line 165: | Line 172: | ||
| </ | </ | ||
| - | Remember to initialize it in your code, you need to tell the library the physical | + | Remember to initialize it in your code; you need to tell the library the physical |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 173: | Line 180: | ||
| == Keypad == | == Keypad == | ||
| - | The LCD shield has 6 buttons. One of them is hard-wired to the reset function, but other buttons (marked SELECT, UP, DOWN, RIGHT, LEFT) can be read through voltage analysis delivered into the AD0 (Analogue to Digital Converter, Channel 0) existing in the ESP8266 chip. Buttons are connected the way that they short the connection and every button creates a separate voltage divider between pull-up and respectable resistance, different for each button (see figure {{ref> | + | The LCD shield has 6 buttons. One is hard-wired to the reset function, but other buttons (marked SELECT, UP, DOWN, RIGHT, LEFT) can be read through voltage analysis delivered into the AD0 (Analogue to Digital Converter, Channel 0) existing in the ESP8266 chip. Buttons are connected the way that they short the connection, and every button creates a separate voltage divider between pull-up and respectable resistance, different for each button (see figure {{ref> |
| <figure LCD1602buttons> | <figure LCD1602buttons> | ||
| Line 181: | Line 188: | ||
| - | Note, there is an assumption that you press only one button at a time. If no button is pressed, Vcc goes to the AD0 and you get maximum reading (see schematics on figure {{ref> | + | Note there is an assumption that you press only one button at a time. If no button is pressed, Vcc goes to the AD0, and you get maximum reading (see schematics on figure {{ref> |
| - | <note warning> | + | <note warning> |
| Reading an AD0 is as simple as: | Reading an AD0 is as simple as: | ||
| Line 197: | Line 204: | ||
| Report: | Report: | ||
| - | * Describe how did you solve the problem of the asynchronous | + | * Describe how you solved |
| * Include source code. | * Include source code. | ||
| < | < | ||
| === Scenario Lab3 === | === Scenario Lab3 === | ||
| - | ** Presenting temperature and humidity on the local, LCD screen **\\ | + | ** Presenting temperature and humidity on the local LCD screen **\\ |
| In this scenario, you will measure temperature and relative humidity using the attached DHT 11 and present it on the screen. | In this scenario, you will measure temperature and relative humidity using the attached DHT 11 and present it on the screen. | ||
| - | In the first row, there should appear | + | In the first row, a label should appear |
| == Temperature and humidity sensor == | == Temperature and humidity sensor == | ||
| There is a DHT11 (blue) sensor connected to the __GPIO 5__.\\ | There is a DHT11 (blue) sensor connected to the __GPIO 5__.\\ | ||
| - | There are two libraries needed to handle reading from the sensor: a common sensor communication library and a specific for DHT sensors, both by Adafruit, so two more entries are needed in the '' | + | There are two libraries needed to handle reading from the sensor: a common sensor communication library and a specific |
| < | < | ||
| lib_deps = | lib_deps = | ||
| Line 219: | Line 226: | ||
| </ | </ | ||
| - | To access sensor readings it is necessary to instantiate a communication class that binds the hardware to the code: | + | To access sensor readings, it is necessary to instantiate a communication class that binds the hardware to the code: |
| <code c> | <code c> | ||
| #define DHTTYPE DHT11 // DHT 11 | #define DHTTYPE DHT11 // DHT 11 | ||
| Line 225: | Line 232: | ||
| DHT dht(DHTPIN, DHTTYPE, | DHT dht(DHTPIN, DHTTYPE, | ||
| </ | </ | ||
| - | It is also necessary to initialise | + | It is also necessary to initialize |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 242: | Line 249: | ||
| Report: | Report: | ||
| - | * Present a circuit with connections (LCD, keypad and sensor). | + | * Present a circuit with connections (LCD, keypad, and sensor). |
| * Present an algorithm for both overall program flow and for obtaining measurements. | * Present an algorithm for both overall program flow and for obtaining measurements. | ||
| * Include your code with appropriate comments. | * Include your code with appropriate comments. | ||
| Line 248: | Line 255: | ||
| === Scenario Lab4 === | === Scenario Lab4 === | ||
| ** Connecting to the network **\\ | ** Connecting to the network **\\ | ||
| - | Connect your ESP8266 (as a client, STA mode) to the PRIVATE // | + | Connect your ESP8266 (as a client, STA mode) to the PRIVATE // |
| Report: | Report: | ||
| - | * When using ESP in STA mode, observe | + | * When using ESP in STA mode, observe |
| * Include source code. | * Include source code. | ||
| < | < | ||
| Line 257: | Line 264: | ||
| === Scenario Lab5 === | === Scenario Lab5 === | ||
| **Sending data to the network**\\ | **Sending data to the network**\\ | ||
| - | In this scenario you're going to implement a fully functional IoT end-node, sending | + | In this scenario, you will implement a fully functional IoT end-node |
| - | Use your solution from the last step of Lab4 and also Lab3. Measure temperature and humidity, present them on the screen as in the case of the Lab3 scenario and parallel, publish them as MQTT messages to the Broker. | + | Use your solution from the last step of Lab4 and also Lab3. Measure temperature and humidity, present them on the screen as in the case of the Lab3 scenario, and parallel, publish them as MQTT messages to the Broker. |
| - | <note important> | + | <note important> |
| - | Using any software-based MQTT client, subscribe to the messages using a PRIVATE or PUBLIC network and observe results. You can use a PC computer you're developing your solution for this task. | + | Using any software-based MQTT client, subscribe to the messages using a PRIVATE or PUBLIC network and observe results. You can use a PC to develop a solution for this task. |
| - | The simplest starting point is to use pub-sub MQTT client library: | + | The simplest starting point is to use the pub-sub MQTT client library: |
| <code c> | <code c> | ||
| #include < | #include < | ||
| #include < | #include < | ||
| </ | </ | ||
| - | You may also want to define MQTT topic(s) and constant payloads (i.e. those related to the last-will flag) using ''# | + | You may also want to define MQTT topic(s) and constant payloads (i.e., those related to the last-will flag) using ''# |
| <code c> | <code c> | ||
| //WiFi and MQTT server credentials | //WiFi and MQTT server credentials | ||
| Line 283: | Line 290: | ||
| Mind, '' | Mind, '' | ||
| - | To use the pub-sub client you must instantiate a global object, using a network client, i.e. '' | + | To use the pub-sub client, you must instantiate a global object using a network client, i.e., '' |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 292: | Line 299: | ||
| </ | </ | ||
| - | Then connect your MQTT pub-sub client to the server. You can define a separate function in case you need to repeat this process when connection is down (for any reason), to simplify reconnect procedure: | + | Somewhere in the '' |
| + | <code c> | ||
| + | ... | ||
| + | client.setServer(< | ||
| + | ... | ||
| + | </ | ||
| + | |||
| + | Then, connect your MQTT pub-sub client to the server. You can define a separate function in case you need to repeat this process when the connection is down (for any reason) to simplify reconnect procedure: | ||
| <code c> | <code c> | ||
| Line 312: | Line 326: | ||
| </ | </ | ||
| - | Advanced: | + | To publish a single message, use: |
| - | * Implement a "last will" informing that device has lost connection (suddenly, not a via disconnect). Present | + | <code c> |
| + | ... | ||
| + | client.publish(< | ||
| + | ... | ||
| + | </ | ||
| + | |||
| + | Note that receiving messages requires periodical execution of the '' | ||
| + | |||
| + | **Advanced**: | ||
| + | * Implement a "last will" informing that the device has lost connection (suddenly, not via disconnect)—present the last available measurements as persistent. Present | ||
| - | To publish last-will message, you may use an extended version of the P'' | + | To publish |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 321: | Line 344: | ||
| ... | ... | ||
| </ | </ | ||
| - | And once connected you may notify the dashboard (if any) that you're back, online: | + | Once connected, you may notify the dashboard (if any) that you're back online: |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 329: | Line 352: | ||
| - | Report: | + | **Report**: |
| * Provide your MQTT message Topics and Payload formats (semantics). | * Provide your MQTT message Topics and Payload formats (semantics). | ||
| * Include source code. | * Include source code. | ||
| < | < | ||
| - | === Scenario Lab6 === | ||
| - | ** Visualising your data **\\ | ||
| - | In this scenario, use the public cloud tools or local ones, to visualise your data over time (Temperature, | ||
| - | |||
| - | Advanced: | ||
| - | * Prepare device state visualisation ('' | ||
| - | * Use local dashboard' | ||
| - | < | ||
| - | |||
en/edu/zmitac/macro/iot/lab.1648320187.txt.gz · Last modified: by pczekalski
