Welcome to the first video in the “IoT in Practice” workshop. This is a mini-series introducing you to the world of the Internet of Things, during which we will be completing a project for a full IoT system. But what exactly is the Internet of Things?
What is IoTLet me give you an example: at home, you have a temperature sensor that sends data to a server. The server analyzes this data and determines that the temperature is too low, so it sends a command to the thermostat to increase the temperature. In turn, you see in your phone app that the temperature is 17*C, and the thermostat has been set to 25*C.
In summary, the Internet of Things (IoT) is a network of interconnected devices that collect data and exchange it with each other over the internet.
ApplicationsExamples of IoT applications include:
- Smart Homes: Controlling lighting, heating, and household appliances.
- Health Monitoring: Tracking steps, heart rate, and blood pressure.
- Industry 4.0: Machines reporting production status and predictive maintenance (failure prediction).
- Agriculture: Humidity sensors and irrigation assistance devices.
- Smart Cities: Street lighting controlled by human presence, and parking systems.
An IoT system consists of four basic elements: the end device, the network, the server, and the userinterface.
- End devices are, for example, a microcontroller with a sensor. Their tasks are to collect data from the environment, perform preliminary processing, and transmit it further.
- The network enables data transmission between devices. Using the example of two people, you could compare it to a conversation. The conversation can take place in various languages, which in turn can be likened to communication protocols such as MQTT, HTTP, or BLE (Bluetooth Low Energy).
- The server is the place where data is collected, further processed, and, if necessary, transmitted onwards.
- The user interface is, for example, a mobile application where you can remotely control the device, or a display presenting the data.
We will be implementing a weather station project step-by-step. It will consist of a microcontroller with sensors and an e-paper display, a server, and a database, and the communication between the server and the microcontroller will occur via the MQTT protocol.
Over the next workshops, we will:
- Install the system on a Raspberry Pi.
- Add an MQTT broker and a server with a database to it.
- Configure the XIAO microcontroller.
- Read data from the sensors and transmit it to the server.
- Finally, add the display to the project.
Go to the website (RPi imager link), download the version for your operating system, and install it.
Connect the SD card where we’ll install the system to your computer. After launching the program, select your Raspberry Pi model and choose the operating system you want to install. I chose the 64-bit Lite version because it doesn't have a desktop environment, which means it takes up much less space. Plus, I feel like a hacker using only the terminal :). Select the storage device where you want to install the system - that is, your sd card—and click Next. Click on "Edit Settings" to change a few of the default configurations:
- The Hostname is the name of your Raspberry Pi. It’s worth setting this up so we won't have to search for the Pi's IP address later when we want to connect to it.
- We will use the username and password to log into the system.
- Set the Wi-Fi network name and password; this can even be a hotspot from your smartphone.
- Also, check the "Enable SSH" option so we can connect to the Raspberry Pi remotely.
Confirm with "Yes", and the system installation process will begin. This may take up to several minutes. Once the installation is complete, insert the card into the Raspberry Pi and connect it to power.
Launch the terminal and connect to the Raspberry Pi by typing the command:
ssh username@hostname.localIf it doesn't connect immediately, make sure your computer is on the same network as the Pi and try again in a moment, as the first full boot-up can take a few minutes.
There is one last thing left to do—a system update. Type the command
sudo apt updateto download available updates, and then install them with:
sudo apt upgradeMQTT broker setupFirst, install the broker and client tools with:
sudo apt install mosquitto mosquitto-clients -yThen check if the Mosquitto service is running and enable it to start automatically on reboot.
# Check version
mosquitto -v
# Check status
sudo systemctl status mosquitto
# Enable auto-start
sudo systemctl enable mosquittoOpen two separate terminal windows (ssh sessions) to test the connection locally.
Terminal 1 (Subscriber):
Bash
mosquitto_sub -h localhost -t testTerminal 2 (Publisher)
mosquitto_pub -h localhost -t test -m "Hello World"(You should see "Hello World" appear in Terminal 1).
- Terminal 2 (Publisher):
Bashmosquitto_pub -h localhost -t test -m "Hello World"(You should see "Hello World" appear in Terminal 1).
4. Create a Password File We need to configure authentication. First, generate a password file for a specific user (replace your_username with your desired name).
Bash
# Navigate to the directory
cd /etc/mosquitto
# Generate password file (you will be prompted to enter a password twice)
sudo mosquitto_passwd -c passwd your_username5. Configure Security Settings Now, edit the configuration file to enforce password authentication and allow external connections.
Bash
sudo nano /etc/mosquitto/mosquitto.confPaste or type the following lines at the end of the file:
Plaintext
listener 1883
allow_anonymous false
password_file /etc/mosquitto/passwdPress CTRL + X, then Y, then Enter to save and exit.
6. Apply Changes Restart the service to apply the new configuration.
Bash
sudo systemctl restart mosquitto7. Final Test (Secured) Try to publish a message.
Test without password (Should fail):
Bash
mosquitto_pub -h localhost -t test -m "This will fail"(You should see a connection refused or not authorized error).
- Test without password (Should fail):
Bashmosquitto_pub -h localhost -t test -m "This will fail"(You should see a connection refused or not authorized error).
Test with password (Should work): Replace your_username and your_password with the credentials you created in Step 4.
Bash
mosquitto_pub -h localhost -t test -m "This works!" -u your_username -P "your_password"- Test with password (Should work): Replace
your_usernameandyour_passwordwith the credentials you created in Step 4.
Bashmosquitto_pub -h localhost -t test -m "This works!" -u your_username -P "your_password"


_MsQPLY30wm.png?auto=compress%2Cformat&w=48&h=48&fit=fill&bg=ffffff)










_3u05Tpwasz.png?auto=compress%2Cformat&w=40&h=40&fit=fillmax&bg=fff&dpr=2)
Comments