This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:iot-open:remotelab:ume:smartme:m2 [2019/09/27 17:28] – created salvatdi | en:iot-open:remotelab:ume:smartme:m2 [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== M2: MQTT to subscribe to a topic to receive messages | + | ==== IM2: MQTT to subscribe to a topic to receive messages ==== |
| MQTT is one of the most commonly used protocols in IoT projects. It stands for Message Queuing Telemetry Transport. In addition, it is designed as a lightweight messaging protocol that provides publish/ | MQTT is one of the most commonly used protocols in IoT projects. It stands for Message Queuing Telemetry Transport. In addition, it is designed as a lightweight messaging protocol that provides publish/ | ||
| - | ===== Target group ===== | + | === Target group === |
| This hands-on lab guide is intended for master students. Other target groups may benefit from it only if they follow it after having dealt with all the exercises proposed which belong to lower levels of difficulty. | This hands-on lab guide is intended for master students. Other target groups may benefit from it only if they follow it after having dealt with all the exercises proposed which belong to lower levels of difficulty. | ||
| - | ===== Prerequisites | + | === Prerequisites === |
| - | ==== Liquid Crystal | + | == Liquid Crystal == |
| For this library, you may refer to the [[en: | For this library, you may refer to the [[en: | ||
| - | ==== DHT ==== | + | == DHT == |
| For this library, you may refer to the [[en: | For this library, you may refer to the [[en: | ||
| - | ==== Understand what Arduino Ethernet Shield is and how it works ==== | + | == Understand what Arduino Ethernet Shield is and how it works == |
| The Arduino Ethernet Shield V1 allows an Arduino board to connect to the internet. It is based on the Wiznet W5100 [1] ethernet chip (datasheet [2]). The Wiznet W5100 provides a network (IP) stack capable of both TCP and UDP-based communication. It supports up to four simultaneous socket connections. Use the Ethernet library [3] to write sketches that connect to the Internet using the shield. The ethernet shield connects to an Arduino board using long wire-wrap headers which extend through the shield. This keeps the pin layout intact and allows another shield to be stacked on top. | The Arduino Ethernet Shield V1 allows an Arduino board to connect to the internet. It is based on the Wiznet W5100 [1] ethernet chip (datasheet [2]). The Wiznet W5100 provides a network (IP) stack capable of both TCP and UDP-based communication. It supports up to four simultaneous socket connections. Use the Ethernet library [3] to write sketches that connect to the Internet using the shield. The ethernet shield connects to an Arduino board using long wire-wrap headers which extend through the shield. This keeps the pin layout intact and allows another shield to be stacked on top. | ||
| Line 22: | Line 22: | ||
| [3] https:// | [3] https:// | ||
| - | ==== Understand what MQTT is and how it works. | + | == Understand what MQTT is and how it works. == |
| MQTT (Message Queue Telemetry Transport) is a standard (SO/IEC PRF 20922) machine-to-machine (M2M) communication protocol for the Internet of Things smart objects and devices. MQTT is a simple messaging protocol, designed for constrained devices with low-bandwidth. So, it’s the perfect solution for Internet of Things applications. | MQTT (Message Queue Telemetry Transport) is a standard (SO/IEC PRF 20922) machine-to-machine (M2M) communication protocol for the Internet of Things smart objects and devices. MQTT is a simple messaging protocol, designed for constrained devices with low-bandwidth. So, it’s the perfect solution for Internet of Things applications. | ||
| This publish/ | This publish/ | ||
| Line 36: | Line 36: | ||
| - | ===== Scenario | + | === Scenario === |
| This node, which acts as a subscriber, shows the value of temperature received by the other node that was initialized with the exercise M1. | This node, which acts as a subscriber, shows the value of temperature received by the other node that was initialized with the exercise M1. | ||
| - | ===== Result | + | === Result === |
| It will be possible to display the value of the temperature, | It will be possible to display the value of the temperature, | ||
| Start | Start | ||
| - | This exercise is to be considered as closely related to the M1 exercise. This means that if you want to reproduce a complete experiment, you have to book at least two nodes of the lab, and then you have to run both M1 and M2 sketches, one per node. | + | This exercise is to be considered as closely related to the M1 exercise. This means that if you want to reproduce a complete experiment, you have to book at least two nodes of the lab, and then you have to run both IM1 and IM2 sketches, one per node. |
| - | ===== Steps ===== | + | === Steps === |
| - | ==== Step 1 ==== | + | == Step 1 == |
| Include the following libraries: LCD driver, MQTT, and Ethernet. | Include the following libraries: LCD driver, MQTT, and Ethernet. | ||
| Line 55: | Line 55: | ||
| </ | </ | ||
| - | ==== Step 2 ==== | + | == Step 2 == |
| - | Instantiate the software controller component for the LCD display. Then assign to the ethernet interface a MAC and IP address, the latter valid for the internal laboratory network (192.168.0.0/ | + | Instantiate the software controller component for the LCD display. Then assign to the ethernet interface a MAC and IP address, the latter valid for the internal laboratory network (192.168.0.0/ |
| <code c> | <code c> | ||
| Line 84: | Line 84: | ||
| </ | </ | ||
| - | ==== Step 3 ==== | + | == Step 3 == |
| - | Initialize the display and the Ethernet connection with IP and MAC address. Then launch the connection() function and initialize the MQTT client with the shift.io broker. You can visualize your device stream, after a successful connection, here: https:// | + | Initialize the display and the Ethernet connection with IP and MAC address. Then launch the '' |
| - | We suggest doing all of the above in the setup() function, as follows: | + | We suggest doing all of the above in the '' |
| <code c> | <code c> | ||
| Line 103: | Line 103: | ||
| </ | </ | ||
| - | ==== Step 4 ==== | + | == Step 4 == |
| - | Implement loop() to try connecting until success, as follows: | + | Implement |
| <code c> | <code c> | ||
| Line 115: | Line 115: | ||
| </ | </ | ||
| - | ===== Result validation | + | === Result validation === |
| Observe on your LCD display, its hosting node acting as a subscriber, the value sampled by the temperature sensor attached to the publisher, as soon as you start the M1 sketch on the latter. | Observe on your LCD display, its hosting node acting as a subscriber, the value sampled by the temperature sensor attached to the publisher, as soon as you start the M1 sketch on the latter. | ||
| - | ===== Platformio.ini | + | === Platformio.ini === |
| < | < | ||
| [env:uno] | [env:uno] | ||
| Line 138: | Line 138: | ||
| </ | </ | ||
| - | + | === IM2_sub.cpp === | |
| - | + | ||
| - | + | ||
| - | ===== M1_sub.cpp ===== | + | |
| <code c> | <code c> | ||
| #include < | #include < | ||