No ACL setup yet! Denying access to everyone.
en:edu:zmitac:s2:iotn:lab1
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:edu:zmitac:s2:iotn:lab1 [2022/03/21 13:36] – [Tracing] pczekalski | en:edu:zmitac:s2:iotn:lab1 [2023/04/21 16:38] (current) – administrator | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== |
| - | Introduction to the IoT programming. | + | Introduction to IoT programming. |
| - | During labs, you will likely use Visual Studio Code with PlatformIO plugin, to author code for the IoT device. | + | You will likely use Visual Studio Code with the PlatformIO plugin |
| - | Devices are connected to the PC via USB cable but they expose a serial port to the operating system. You need to check the COM port number | + | Devices are connected to the PC via a USB cable, but they expose a serial port to the operating system. You need to check the COM port number, which varies from PC to PC, and configure your project accordingly. |
| - | <note tip>You can use default COM port transfer speed but in any case, when using COM port as a trace, you need to configure the transmission speed on the code side. Default | + | <note tip>You can use the default COM port transfer speed, but in any case, when using the COM port as a trace, you need to configure the transmission speed on the code side. The default |
| - | + | ||
| - | <note important> | + | |
| ==== Hardware ==== | ==== Hardware ==== | ||
| Line 15: | Line 13: | ||
| < | < | ||
| </ | </ | ||
| - | 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 33: | 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 48: | Line 46: | ||
| </ | </ | ||
| - | It is also necessary to configure | + | Configuring |
| < | < | ||
| ... | ... | ||
| Line 57: | 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> | ||
| {{: | {{: | ||
| - | < | + | < |
| </ | </ | ||
| === Hardware-software components and libraries === | === Hardware-software components and libraries === | ||
| - | Interfacing hardware requires the use of particular GPIOs. Laboratory nodes and hardware used needs specific | + | Interfacing hardware requires the use of particular GPIOs. Laboratory nodes and hardware used need specific |
| == LCD display == | == LCD display == | ||
| Line 73: | Line 71: | ||
| </ | </ | ||
| - | Your LCD shield is a 2x16 character | + | Your LCD shield is a 2x16 character driven by a Hitachi HD44780 controller. You can use a library to use it easily. The PlatformIO will pull the library automatically if defined in the '' |
| <code c> | <code c> | ||
| lib_deps = Arduino-libraries/ | lib_deps = Arduino-libraries/ | ||
| Line 82: | Line 80: | ||
| </ | </ | ||
| - | To initialise | + | 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 88: | Line 86: | ||
| </ | </ | ||
| - | It is also necessary to tell the library about the display | + | It is also necessary to tell the library about the display |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 96: | Line 94: | ||
| == 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 104: | Line 102: | ||
| - | 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 121: | Line 119: | ||
| == 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 //platformio.ini// file, and obviously | + | 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 '' |
| < | < | ||
| lib_deps = | lib_deps = | ||
| Line 132: | Line 130: | ||
| </ | </ | ||
| - | 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 138: | Line 136: | ||
| 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 146: | Line 144: | ||
| </ | </ | ||
| - | The sensor class returns data (among others) in a float containing temperature (in C) and relative humidity (in per cent): | + | The sensor class returns data (among others) in a float containing temperature (in C) and relative humidity (in percent): |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 154: | Line 152: | ||
| </ | </ | ||
| ==== Software ==== | ==== Software ==== | ||
| - | String formatting may be a challenge. | + | String formatting may be a challenge. |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 161: | Line 159: | ||
| </ | </ | ||
| - | To convert float into the string with formatting use '' | + | To convert float into the string with formatting, use '' |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 169: | Line 167: | ||
| ... | ... | ||
| </ | </ | ||
| - | <note tip>'' | + | <note tip>'' |
| <code c> | <code c> | ||
| delay(time) | delay(time) | ||
| </ | </ | ||
| ==== 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 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 //platformio.ini// file. | + | 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 188: | Line 186: | ||
| ... | ... | ||
| </ | </ | ||
| - | 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 |
| ==== 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 204: | Line 202: | ||
| === 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 212: | Line 210: | ||
| * 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 | ||
| * User: vrel | * User: vrel | ||
| * Password: vrel2018 | * Password: vrel2018 | ||
| + | |||
| + | <figure zmitacnetworkingiot> | ||
| + | {{: | ||
| + | < | ||
| + | </ | ||
| === Node Red and Node Red Dashboard === | === Node Red and Node Red Dashboard === | ||
| - | A Node RED server is working on same Raspberry Pi 2 as MQTT and in private address pool only, available through // | + | A Node RED server is working on the same Raspberry Pi 2 as MQTT and in a private address pool only, available through // |
| * [[http:// | * [[http:// | ||
| * [[http:// | * [[http:// | ||
| - | Login using the following credentials: | + | Log in using the following credentials: |
| * User: //contact supervisor// | * User: //contact supervisor// | ||
| * Password: //contact supervisor// | * Password: //contact supervisor// | ||
| ==== 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 not to overlay one another. |
| - | <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 245: | Line 248: | ||
| </ | </ | ||
| - | The standard serial port speed is 9600 (bps). Connect COM port monitor (a plug icon in the PlatformIO toolbar), once you compile and upload your code, to see the "Hello World" message. | + | The standard serial port speed is 9600 (bps). Connect |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 253: | Line 256: | ||
| 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 260: | Line 263: | ||
| ** Using LCD **\\ | ** Using LCD **\\ | ||
| In this scenario, you will write an application that writes on the LCD Display.\\ | In this scenario, you will write an application that writes on the LCD Display.\\ | ||
| - | Your code shall implement a message '' | + | Your code shall implement a message '' |
| Report: | Report: | ||
| Line 272: | Line 275: | ||
| Report: | Report: | ||
| - | * Describe how did you solve the problem of the asynchronous | + | * Describe how you solved |
| * Include source code. | * Include source code. | ||
| < | < | ||
en/edu/zmitac/s2/iotn/lab1.1647866210.txt.gz · Last modified: by pczekalski
