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/16 10:49] – 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 28: | Line 28: | ||
| {{: | {{: | ||
| < | < | ||
| - | </ | ||
| - | * A selected number of teams will also experiment with a Plantower air quality sensors: [[http:// | ||
| - | <figure pms> | ||
| - | {{: | ||
| - | < | ||
| </ | </ | ||
| - | ==== Software | + | |
| - | You will be writing an application for end nodes (ESP8266) in C++. Additionally, some skills on NodeJS/ | + | ==== VSCode, PlatformIO, and project configuration |
| - | Development IDEs are a choice of: | + | |
| - | * Arduino IDE with Espressif ESP8266 development toolchain, | + | In any case, creating |
| - | * Visual Studio Code with the PlatformIO extension: | + | <figure platformionewproject> |
| - | Sample | + | {{: |
| + | < | ||
| + | </ | ||
| + | This configuration brings the following project configuration file '' | ||
| < | < | ||
| [env: | [env: | ||
| Line 47: | Line 45: | ||
| framework = arduino | framework = arduino | ||
| </ | </ | ||
| - | Additionally, | + | |
| - | <note important> | + | It is also necessary to configure the serial port name used for uploading your firmware and monitoring (if you use it). In the case of this microcontroller, |
| + | < | ||
| + | ... | ||
| + | upload_port = COM3 | ||
| + | monitor_port = COM3 | ||
| + | ... | ||
| + | </ | ||
| + | |||
| + | === Running your code === | ||
| + | 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> | ||
| + | <figure pioribbon> | ||
| + | {{: | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | ==== Software ==== | ||
| + | You will be writing an application for end nodes (ESP8266) in C++ using VS Code.\\ | ||
| + | Additionally, | ||
| + | <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 63: | 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 71: | 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 77: | Line 94: | ||
| * Password: vrel2018 | * Password: vrel2018 | ||
| - | === Node Red and Node Red Dashboard | + | <figure zmitacnetworkingiot> |
| - | A Node RED server | + | {{: |
| - | | + | < |
| - | * [[http://192.168.90.5:1880/ui]] - Node RED dashboard | + | </ |
| - | Login using the following credentials: | + | ==== Tracing |
| - | * User: //contact supervisor// | + | There is no direct debugging capability |
| - | * Password: //contact supervisor// | + | To open serial communication, |
| + | <code c> | ||
| + | Serial.begin(9600); | ||
| + | </ | ||
| + | 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 | ||
| + | <code c> | ||
| + | ... | ||
| + | Serial.print(...); | ||
| + | //or | ||
| + | Serial.println(...); | ||
| + | ... | ||
| + | </code> | ||
| + | Both functions accept a wide range of argument types without needing to convert to string explicitly. | ||
| + | <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.</ |
| < | < | ||
| + | |||
| + | |||
| === Scenario Lab1 === | === Scenario Lab1 === | ||
| **Getting ready with your development environment**\\ | **Getting ready with your development environment**\\ | ||
| Line 96: | 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 main board, 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 '' | ||
| + | < | ||
| + | ... | ||
| + | monitor_port = COM3 | ||
| + | ... | ||
| + | </ | ||
| + | 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 | ||
| < | < | ||
| + | |||
| + | |||
| === Scenario Lab2 === | === Scenario Lab2 === | ||
| ** Using LCD **\\ | ** Using LCD **\\ | ||
| - | In this scenario, you will write an application that writes on the LCD Display.\\ | ||
| - | Your code shall implement a message '' | ||
| - | Additionally, | ||
| - | To control LCD it is easiest to use a software library (add to the '' | + | In this scenario, you will write an application that reports on the LCD Display.\\ |
| + | Your code shall implement a message '' | ||
| + | Additionally, | ||
| + | |||
| + | == The LCD Display == | ||
| + | To control LCD, it is easiest to use a software library (add to the '' | ||
| < | < | ||
| ... | ... | ||
| Line 119: | Line 166: | ||
| </ | </ | ||
| - | + | Your LCD shield is 2x16 characters. To initialize | |
| - | Your LCD shield is a 2x16 characters | + | |
| <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; | ||
| LiquidCrystal lcd(rs, en, d4, d5, d6, d7); | LiquidCrystal lcd(rs, en, d4, d5, d6, d7); | ||
| </ | </ | ||
| + | |||
| + | Remember to initialize it in your code; you need to tell the library the physical organization of the display: | ||
| + | <code c> | ||
| + | ... | ||
| + | lcd.begin(16, | ||
| + | ... | ||
| + | </ | ||
| + | |||
| + | == Keypad == | ||
| + | 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> | ||
| + | {{: | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | |||
| + | 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> | ||
| + | |||
| + | Reading an AD0 is as simple as: | ||
| + | <code c> | ||
| + | #define ADCPIN 0 | ||
| + | ... | ||
| + | int nAdcReading = 0; | ||
| + | ... | ||
| + | nAD0 = analogRead(ADCPIN); | ||
| + | ... | ||
| + | </ | ||
| + | |||
| 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 / DHT 22 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 |
| - | <note tip>The DHT sensor is connected to the GPIO 5 pin. The blue sensor is DHT 11 while the white one is DHT 22. Mind to define appropriate constant definition | + | == Temperature and humidity |
| + | There is a DHT11 (blue) sensor | ||
| + | There are two libraries needed to handle reading from the sensor: a common sensor communication library and a specific | ||
| + | <code> | ||
| + | lib_deps = | ||
| + | adafruit/Adafruit Unified Sensor@^1.1.4 | ||
| + | adafruit/ | ||
| + | </code> | ||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | </ | ||
| + | |||
| + | 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 | ||
| + | #define DHTPIN 5 | ||
| + | DHT dht(DHTPIN, DHTTYPE, | ||
| </ | </ | ||
| + | It is also necessary to initialize the sensor class and give it some time to set up: | ||
| <code c> | <code c> | ||
| - | #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 | + | ... |
| + | dht.begin(); | ||
| + | delay(1000); | ||
| + | ... | ||
| + | </code> | ||
| + | |||
| + | The sensor class returns data (among others) in a float containing temperature (in C) and relative humidity (in per cent): | ||
| + | <code c> | ||
| + | ... | ||
| + | float hum = dht.readHumidity(); | ||
| + | float temp = dht.readTemperature(); | ||
| + | ... | ||
| </ | </ | ||
| 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 151: | Line 255: | ||
| === Scenario Lab4 === | === Scenario Lab4 === | ||
| ** Connecting to the network **\\ | ** Connecting to the network **\\ | ||
| - | In this scenario, you will use ESP 8266 networking. There are three, independent tasks to be completed today: | + | Connect your ESP8266 (as a client, STA mode) to the PRIVATE // |
| - | * List all WiFi networks over the serial port to the serial monitor. | + | |
| - | * Implement a simple web server: using your ESP8266 prepare an Access Point (AP mode) you can connect to directly, using your mobile phone. Implement simple built-in LED control via a web browser, directly from your mobile phone. Present information on the LCD when the client connects to your ESP. | + | |
| - | <note important> | + | |
| - | * Connect your ESP8266 (as a client, STA mode) to the PRIVATE // | + | |
| Report: | Report: | ||
| - | | + | * When using ESP in STA mode, observe |
| - | | + | |
| * Include source code. | * Include source code. | ||
| < | < | ||
| + | |||
| === 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 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 190: | Line 290: | ||
| Mind, '' | Mind, '' | ||
| - | To use 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 199: | 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 219: | 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 228: | Line 344: | ||
| ... | ... | ||
| </ | </ | ||
| - | And once connected you may notify the dashboard (if any) that you're back, on-line: | + | Once connected, you may notify the dashboard (if any) that you're back online: |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 236: | 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' | ||
| - | < | ||
| - | **Evaluation** | ||
| - | |||
| - | As labs 3 through 5 constitute somehow a solid solution, every team is asked to prepare a presentation of their achievements to share it with other groups. The presentation should be some 10min in the form of the PDF presentation on-screen, using DLP projector in the laboratory room. | ||
| < | < | ||
en/edu/zmitac/macro/iot/lab.1647424185.txt.gz · Last modified: by pczekalski
