User Tools

Site Tools


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.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:edu:zmitac:macro:iot:lab [2023/04/21 16:32] – [Network services] administratoren:edu:zmitac:macro:iot:lab [2024/04/21 16:17] (current) – [Laboratory scenarios] pczekalski
Line 33: Line 33:
 ==== VSCode, PlatformIO, and project configuration ==== ==== VSCode, PlatformIO, and project configuration ====
  
-In any case, creating a new project under PlatformIO should follow this general setting, regarding Board and Framework (see figure {{ref>platformionewproject}}):+In any case, creating a new project under PlatformIO should follow this general setting regarding Board and Framework (see figure {{ref>platformionewproject}}):
 <figure platformionewproject> <figure platformionewproject>
 {{:en:edu:zmitac:macro:embedeed:lab:screenshot_from_2021-10-13_12-43-38.png?800|:img}} {{:en:edu:zmitac:macro:embedeed:lab:screenshot_from_2021-10-13_12-43-38.png?800|:img}}
Line 68: Line 68:
  
 ==== 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 can talk to one another. There is a DHCP server with networking addressing scope 192.168.90.10-192.168.90.254. +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>Do not use static IP! Some services in the network have fixed IP addresses; overlapping causes the unavailability of your solution and this service to other teams! Use only DHCP for obtaining a network address.</note>+<note warning>Do not use static IP! Some services in the network have fixed IP addresses; overlapping causes the unavailability of your solution and this service to other teams! Use only DHCP to obtain a network address.</note>
  
 To connect to the wireless network, use the following credentials: To connect to the wireless network, use the following credentials:
Line 114: Line 114:
 </code> </code>
 Both functions accept a wide range of argument types without needing to convert to string explicitly.  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 "special" characters, language-specific.</note>+<note tip>Note: there is a limit on the character set that is ASCII only. We suggest avoiding "special" characters, which are language-specific.</note>
  
 ==== Laboratory scenarios ==== ==== Laboratory scenarios ====
-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.+All teams share the same scenario yet; please note that MQTT messages exchanged between devices shall be coordinated among team members so as not to overlay one another.
 <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.</note> <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.</note>
 <pagebreak> <pagebreak>
Line 129: Line 129:
   - Sends a message via serial port to the serial port monitor: ''Hello World''   - Sends a message via serial port to the serial port monitor: ''Hello World''
  
-<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 color is blue.</note>+<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>
 <code c> <code c>
 #define LED_BUILTIN 14 #define LED_BUILTIN 14
 </code> </code>
  
-Note, to use tracing with the ''Serial.print(...)'' singleton object, you need to tell VS Code which port to use to receive tracing messages you send from your code. Mind including in the ''platformio.ini'' file the appropriate configuration (here COM3 is a sample, check yours in PC configuration):+Note, to use tracing with the ''Serial.print(...)'' singleton object, you need to tell VS Code which port to use to receive tracing messages you send from your code. Mind including in the ''platformio.ini'' file the appropriate configuration (here COM3 is a sample; check yours in PC configuration):
 <code> <code>
 ... ...
Line 140: Line 140:
 ... ...
 </code> </code>
 +Obligatory:
 +  * Provide a solution using ''millis()'' instead of ''delay()''
  
 Advanced: Advanced:
   * Use a timer/interrupt to flash the LED instead of an infinite loop.   * Use a timer/interrupt to flash the LED instead of an infinite loop.
 +  * 
 Report: Report:
   * Describe your approach and include source code in the report   * Describe your approach and include source code in the report
Line 153: Line 156:
 In this scenario, you will write an application that reports on the LCD Display.\\ In this scenario, you will write an application that reports on the LCD Display.\\
 Your code shall implement a message ''Hello IoT'' in the upper line and a counter ticking every second in the lower one.\\ Your code shall implement a message ''Hello IoT'' in the upper line and a counter ticking every second in the lower one.\\
-Additionally, present a label ''LEFT/RIGHT/UP/DOWN'' when a key is pressed on the 6 keys keypad, located down to the LCD display module. The label should appear in a lower line of the LCD, along with a ticking counter that is still working. The label should disappear when the key is released.+Additionally, present a label ''LEFT/RIGHT/UP/DOWN'' when a key is pressed on the 6-key keypad located below the LCD display module. The label should appear in a lower line of the LCD, along with a ticking counter that is still working. The label should disappear when the key is released.
  
 == The LCD Display == == The LCD Display ==
Line 187: Line 190:
 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>LCD1602buttons}} above and warning note below, on readings AD0). 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>LCD1602buttons}} above and warning note below, on readings AD0).
  
-<note warning>Because of the LCD shield construction and the fact that ESP8266 can accept out of the box on their AD0 input voltage range of 0..3.3V only (actually 0..1V but there is a voltage divider in the middle), you're unable to grab button SELECT pressed, because shorting it causes input voltage to on the AD0 to be ~3.7V, while when no button is pressed, the input voltage on AD0 is 5V. Both are far beyond the measurable range, so you will always get maximum reading (1024) in both cases, and there is no way to distinguish them without electrical modification.</note>+<note warning>Because of the LCD shield construction and the fact that ESP8266 can accept out of the box on their AD0 input voltage range of 0..3.3V only (actually 0..1V but there is a voltage divider in the middle), you're unable to grab button SELECT pressed, because shorting it causes input voltage to on the AD0 to be ~3.7V, while when no button is pressed, the input voltage on AD0 is 5V. Both are far beyond the measurable range, so you will always get a maximum reading (1024) in both cases, and there is no way to distinguish them without electrical modification.</note>
  
 Reading an AD0 is as simple as: Reading an AD0 is as simple as:
Line 208: Line 211:
 ** 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 a label ''Temperature:'' or ''Humidity:'' while in the lower, measured value, right-aligned along with the measurement unit. Switching between presenting temperature and humidity should be possible using the Up/Down keys from the keypad and changing the temperature between Celsius and Fahrenheit using the Left/Right keys. Measurements should include a unit: ''C/F'' (for temperature) and ''%Rh'' for humidity. The temperature should be present with one decimal point, while humidity as an integer.+In the first row, a label should appear ''Temperature:'' or ''Humidity:'' while in the lower, measured value, right-aligned along with the measurement unit. Switching between presenting temperature and humidity should be possible using the Up/Down keys from the keypad and changing the temperature between Celsius and Fahrenheit using the Left/Right keys. Measurements should include a unit: ''C/F'' (for temperature) and ''%Rh'' for humidity. The temperature should be present with one decimal point, while humidity should be an integer.
  
 == Temperature and humidity sensor == == Temperature and humidity sensor ==
Line 237: Line 240:
 </code> </code>
  
-The sensor class returns data (among others) in a float containing temperature (in C) and relative humidity (in percent):+The sensor class returns data (among others) in a float containing temperature (in C) and relative humidity (in per cent):
 <code c> <code c>
 ... ...
Line 255: Line 258:
  
 Report: Report:
-  * When using ESP in STA mode, observe if the consequent running of the solution brings new or the same IP address attached via the DHCP server.+  * When using ESP in STA mode, observe whether the subsequent running of the solution attaches a new or the same IP address via the DHCP server.
   * Include source code.   * Include source code.
 <pagebreak> <pagebreak>
Line 261: Line 264:
 === Scenario Lab5 === === Scenario Lab5 ===
 **Sending data to the network**\\ **Sending data to the network**\\
-In this scenario, you will implement a fully functional IoT end-node, sending measurements to the MQTT Broker.+In this scenario, you will implement a fully functional IoT end-node and send measurements to the MQTT 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. 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>Mind agreeing with other sections to let you do not overlap with MQTT Message Topics. They should be unique for all teams!</note> <note important>Mind agreeing with other sections to let you do not overlap with MQTT Message Topics. They should be unique for all teams!</note>
-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 the pub-sub MQTT client library: The simplest starting point is to use the pub-sub MQTT client library:
Line 296: Line 299:
 </code> </code>
  
-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:+Somewhere in the ''setup()'' function, once your wifi is already connected, bind server data to the MQTT client object: 
 +<code c> 
 +... 
 +client.setServer(<server>,1883); //standard port is 1883, change accordingly if needed 
 +... 
 +</code> 
 + 
 +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 316: Line 326:
 </code> </code>
  
-Advanced: +To publish a single message, use: 
-  * Implement a "last will" informing that device has lost connection (suddenly, not via disconnect)—present the last available measurements as persistent. Present the device state by changing a persistent message on connect/disconnect to let the subscribers know the state of your device. To implement controlled disconnect, use //select// key from the keypad (you can assume that you may need to restart the device to get it back on the network, but you also may implement a bistable logic: the first click of the //select// triggers MQTT disconnect, the second click connects it back to the Broker).+<code c> 
 +... 
 +client.publish(<topic>,<payload>); 
 +... 
 +</code> 
 + 
 +Note that receiving messages requires periodical execution of the ''client.loop();'' function. Add it to your code's ''void loop()...'' function. If you send messages only (publish but do not subscribe), using ''client.loop();'' is not obligatory. 
 + 
 +**Advanced**: 
 +  * Implement a "last will" informing that the device has lost connection (suddenly, not via disconnect)—present the last available measurements as persistent. Present the device state by changing a persistent message on connect/disconnect to let the subscribers know the state of your device. To implement controlled disconnect, use //select// key from the keypad (you can assume that you may need to restart the device to get it back on the network, but you also may implement a bistable logic: the first click of the //select// triggers MQTT disconnect, the second click connects it back to the Broker).
  
 To publish a last-will message, you may use an extended version of the P''ubSubClient.connect()'' function (i.e., in your ''reconnect()'' function: To publish a last-will message, you may use an extended version of the P''ubSubClient.connect()'' function (i.e., in your ''reconnect()'' function:
Line 325: Line 344:
 ... ...
 </code> </code>
-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 333: 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.
 <pagebreak> <pagebreak>
  
en/edu/zmitac/macro/iot/lab.1682087552.txt.gz · Last modified: by administrator