Components of the Full Stack IoT System:




Establishing MQTT architecture




There are some useful guides on MQTT online. For example:

Broker configuration

sudo apt install mosquitto
sudo apt install mosquitto-clients

The server will usually be executed automatically. In which case you should be able see that the server is bound to port 1883 on your Linux desktop machine:

You can see with netstat -at command
Adding a username/password to the mosquitto server

You need to edit the configuration file for the mosquitto server.

Sensor and Actuator set up

We will use ADXLE345 and RPI as our interface to real world data

You can learn more about ADXL345 sensor from this link

Electronics is out of context in this blog post so i'll wont go into details about I2C bus that enables connecting devices to rpi such as ADXL SENSOR in our project.But ill put a image below that can give you idea.

You can learn more about I2C(Inter-Integrated Circuit)

Here is figure how you can establish I2C connection with rpi and two sensors(ADXL345,DS3231) ![I2C bus connection of RPI and Sension]

Design and develop an MQTT publisher sensor application:

In this part of the blog we will develop an application that captures external data through sensor and sends the data to broker.Thus publishing the external data

As an enthusiast of Object-Oriented Programming (OOP), you appreciate the benefits of designing systems with clear abstractions and well-defined interactions. In this guide, we will explore how to apply OOP principles while connecting and manipulating a device connected to the I2C bus on a Linux-based operating system. Understanding the Linux file-system and its hierarchical structure will allow us to control various aspects of the operating system, including user privileges, web configurations, and memory allocation.

OOP Design for I2C Communication: Applying OOP principles to I2C communication will allow us to encapsulate the low-level details of I2C interactions within classes or objects, providing a clean and reusable interface. We can create an I2CDevice class that abstracts away the complexities of device addressing, read/write operations, and error handling. This class can act as a driver to interact with specific I2C devices.

Conclusion:

By combining the power of OOP design and Linux file-system manipulation, we can create efficient and organized code for interacting with I2C devices on a Raspberry Pi or any Linux-based system. This approach enables us to build modular and maintainable systems that effectively control and communicate with external hardware while taking advantage of the Linux environment's flexibility and robustness.*

Here is a link of the code for establishing connection for I2C bus

Manipulating Sensor values

As i said with OOP desing architecture our based class will be called I2C bus allowing us to maintain reliable connection and manipulate device registers of the external devices that is on the I2C bus.

Code for publishing the values captured from sensor

Here is a link of allowing us to CRUD operations on registers of adxl345

Understanding the Code:

The provided C++ code implements a class called "ADXL345" that facilitates communication with the ADXL345 accelerometer over the I2C bus. Let's go through the main aspects of the code:

I2C Communication: The ADXL345 class inherits from the "I2CDevice" class, which encapsulates the low-level I2C communication. The I2CDevice class handles reading and writing to I2C registers, making it easier for us to focus on the accelerometer functionality.

Conclusion:

By following this guide, you've learned how to interact with the ADXL345 accelerometer on a Raspberry Pi using the I2C protocol. The provided C++ code simplifies the communication process and allows you to read acceleration data and calculate orientation angles easily. You can further extend this project to integrate the accelerometer data into your own applications, such as motion-based control or tilt sensing in IoT projects. Happy exploring with the ADXL345 accelerometer!

Exploring MQTT Communication and ADXL345 Integration on Raspberry Pi

C++ code that demonstrates how to integrate the ADXL345 accelerometer with MQTT communication on a Raspberry Pi. The code uses the Eclipse Paho MQTT C library to publish data from the accelerometer, including CPU temperature, pitch and roll values, to an MQTT broker.*

Conclusion:

By following this guide, you've learned how to integrate the ADXL345 accelerometer with MQTT communication on a Raspberry Pi. The C++ code provided enables you to read pitch and roll values from the accelerometer, obtain the CPU temperature, and publish this data as JSON payloads to an MQTT broker. This integration opens up possibilities for various applications, such as real-time monitoring, remote sensing, or IoT projects. Happy exploring with MQTT and ADXL345 accelerometer data on your Raspberry Pi!

MQTT Subscriber for Raspberry Pi with GPIO Control

Here you can find the Code for subscriber module

C++ code that acts as an MQTT subscriber on a Raspberry Pi and simultaneously controls a GPIO pin to turn an LED on or off based on received MQTT messages. The code uses the Eclipse Paho MQTT C library to communicate with an MQTT broker and the WiringPi library to control the GPIO pin.

Library and Header Inclusions:

Conclusion:

In this blog post, we explored a system architecture that combines MQTT communication and GPIO control on a Raspberry Pi. We developed two separate C++ programs: one for publishing sensor data to an MQTT broker and the other for subscribing to MQTT messages and controlling an LED based on received data. The system allows us to remotely monitor sensor data and control an LED using the MQTT protocol.

System Architecture:

The system architecture consists of two main components:

MQTT Publisher:

From here, you can expand and adapt the system to various use cases, such as home automation, environmental monitoring, and industrial automation. The power of MQTT and the Raspberry Pi enables you to create sophisticated IoT applications that connect and control a wide range of devices and sensors. Happy exploring!