Skip to content

PJalv/SDP-IoT-Device-Control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

IoT Device Control System

Spring 2024 Senior Design Project

Dylan St Laurent & Jorge Suarez

project-logo

license last-commit repo-top-language repo-language-count


Table of Contents

Overview

Big Picture This Senior project is structured to leverage a combination of hardware components and software technologies to provide a comprehensive IoT device control system. Here's an overview of the project's structure and the technologies used:

Components:

  1. ESP32 Microcontrollers: These are responsible for device control, data collection, and communication.
  2. Raspberry Pi: Serves as a local server or gateway, facilitating the interface between ESP32 devices and the cloud server.
  3. Cloud Server: Manages backend services, databases, and ensures data synchronization and remote access.
  4. Mobile App: Enables users to interact with the IoT system, control devices, and view data.

Software Technologies:

  • ESP-IDF: This is used for programming ESP32 devices, providing essential IoT tools and libraries.
  • FreeRTOS: Provides a real-time operating system for ESP32 devices, ensuring efficient resource management and task scheduling. We leverage FreeRTOS to separate vital ESP functions like WiFi and MQTT, allowing each to operate independently and efficiently.
  • MQTT Protocol: Provides efficient real-time messaging across devices and servers.
  • Bun.js: Implemented on the Raspberry Pi for fast package management and development.
  • React Native: Utilized for developing the cross-platform mobile application.
  • WebSocket: Supports real-time data transmission to the mobile app.
  • Go (Golang): Specifically used on the cloud server for its robust support for concurrency. Go routines and channels are employed to manage multiple device data streams simultaneously, significantly enhancing the system's scalability and its ability to handle large volumes of IoT device communications efficiently.

Features

Feature Description
βš™οΈ Architecture Utilizes a modular architecture with technologies such as Go, React Native, and Expo, orchestrated by CMake for IoT device control.
πŸ”Œ Integrations Incorporates JWT for security, MQTT for device messaging, and WebSocket for real-time communication, supporting web and mobile functionalities.
🧩 Modularity Features distinct components like fan_device and main, which enhance reusability and maintainability.
πŸ›‘οΈ Security Employs JWT and secure communication protocols such as MQTT and WebSocket to ensure data protection and secure access.
πŸš€ Scalability Supports increased traffic and load efficiently through its modular architecture and scalable technologies.

Repository Structure

└── SDP-IoT-Device-Control/
    β”œβ”€β”€ README.md
    β”œβ”€β”€ schematics
    β”‚   β”œβ”€β”€ AudioDriver
    β”‚   β”œβ”€β”€ Espressif
    β”‚   β”œβ”€β”€ FanSystem
    β”‚   β”œβ”€β”€ LED_Device
    β”‚   └── Power
    └── source_code
        β”œβ”€β”€ IOT-App
        β”œβ”€β”€ cloud_websocket
        β”œβ”€β”€ dashboard_gui
        β”œβ”€β”€ fan_device
        β”œβ”€β”€ led_device
        └── utils

Modules

Fan Device Main Module
File Summary
audio.h Enables setting up I2S audio with a defined buffer size for the fan device in the SDP-IoT-Device-Control repository.
init.h Initializes and finalizes the setup for the IoT fan device. Manages the initialization of FreeRTOS and GPIO, essential for device control. Part of the IoT Device Control repository structure under fan_device.
main.c Initializes system, sets up WiFi and MQTT tasks, processes events, maintains heartbeat, and handles counts. Coordinates device functionality within the SDP-IoT-Device-Control repositorys architecture.
tasks.h Publishing status, playing audio, controlling breeze mode, managing tasks, establishing Wi-Fi connection, handling MQTT communication, managing heartbeats, and processing events. Crucial for fan system operation within the IoT device control architecture.
storage_nvs.h Manages fan configuration data using Non-Volatile Storage (NVS) for the fan device within the SDP-IoT-Device-Control repositorys architecture. Key functionalities include setting and retrieving fan power, function, and duty cycle information.
fan.h Implements fan control functionalities and interfaces with LED driver for RPM and power button handling. Manages duty cycle adjustments and interrupts, integrating with MQTT data for IoT device communication within the parent repositorys IoT device control architecture.
Cloud WebSocket Broker (JavaScript)
File Summary
broker.js Establishes connectivity between MQTT broker and WebSocket server, facilitating real-time data exchange. Handles JWT token generation and verification, synchronizing data with the broker. Manages reconnections and error handling, enhancing reliability for IoT device control system.
Cloud WebSocket Server (Go)
File Summary
server.go Orchestrates WebSocket communication for IoT devices. Manages client connections, token verification, and message distribution in a secure manner. Handles commands and responses, gracefully falling back on failure. Monitors domain status and switches services dynamically for robust operation.
LED Device Managed Components (Espressif LED Strip)
File Summary
led_strip_spi.h Implements creation of LED strip on SPI MOSI channel. Manages LED strip configuration and SPI specific settings to create LED strip handle successfully, handling errors like invalid arguments or unsupported configurations.
led_strip.h Defines functions to manage RGB, RGBW, and HSV colors for LED strips. Contains methods to set colors for individual pixels, refresh LED memory, clear LED strip, and free resources. Enables control and customization of LED strip colors in IoT devices.
LED Device Main Module
File Summary
led_config.c Creates LED configuration for LED device with specified GPIO, LED count, and pixel format. Initializes LED strip object using SPI backend for improved performance, leveraging DMA support.
main.c The main.c file in the led_device module of the SDP-IoT-Device-Control repository serves as the main entry point for controlling LED devices. It integrates with various system components like I2S drivers, FreeRTOS tasks, LED strip libraries, MQTT protocols for communication, and Wi-Fi configurations. The code handles LED configurations, GPIO interactions, and JSON parsing to facilitate LED device functionality. Through this file, the LED device module manages LED operations, synchronization, and communication with the broader IoT infrastructure.This code supports the overarching architecture of the repository by providing a crucial component for controlling LED devices within the IoT ecosystem, ensuring seamless integration and communication with other system modules and functionalities.
storage_nvs.h Manages LED device configuration data using Non-Volatile Storage in the repositorys LED device module, enhancing persistence and reliability.
Dashboard GUI
File Summary
gui.py Facilitates interaction with MQTT broker through Eel GUI for IoT device control. Dynamically updates broker settings, reads JSON storage, and publishes messages. Handles MQTT connection and displays connection status in the GUI, enhancing user experience.
store.py Manages MQTT connections, updates device statuses, and detects disconnected devices. Subscribes to specific topics, parses messages, and updates JSON storage. Handles message receiving and device disconnection checks for LED and fan devices in the IoT system.
storage.json Stores device status, power, and configurations for fan and LED devices-Facilitates real-time monitoring and control of devices via the dashboard GUI within the IoT system
Dashboard GUI Web (JavaScript)
File Summary
settings.js Retrieves, displays, and updates broker settings and status for IoT device control. Integrates with backend APIs and UI elements. Facilitates MQTT connection handling and status monitoring, ensuring seamless communication with devices.
led.js Improves LED control interface. Dynamically updates LED settings and colors based on user inputs. Facilitates toggling power and selecting operation modes using MQTT messaging. Enhances user experience by enabling real-time interaction with LED device.
app.js Implements MQTT connection and data update logic for IoT devices integration. Manages device statuses and controls via a dashboard interface. Visualizes device status and allows dynamic device control. Dynamically updates interface elements based on device data.
fan.js Manages fan speed control, power toggling, and data updates using MQTT messages. Dynamically displays fan status, RPM, and mode in a responsive GUI. Enables fan mode selection and updates fan parameters through MQTT communication.
Dashboard GUI Web (HTML)
File Summary
index.html Generates a responsive dashboard GUI with cards for fan and LED devices. Allows toggling power and settings, displaying device status dynamically. Incorporates Bootstrap CSS and icons for a user-friendly interface.
Settings.html Creates a responsive settings interface for configuring the IoT devices broker connection. Features include input fields for broker name, IP address, and port number, with a Connect' button. Leverages Bootstrap for styling and jQuery for functionality.
eel.js Enables dynamic communication between Python and JavaScript, facilitating function exposure and asynchronous calls. Handles WebSocket interactions with an embedded Python app, supporting customization of window size and position for a web-based dashboard GUI.
FanSettings.html Showcases an interactive web interface for managing fan settings. Offers power toggling, speed adjustment, breeze mode selection, and real-time statistical data display. Enhances user experience with Bootstrap styling and jQuery functionalities. Integrated for seamless device control in the SDP-IoT ecosystem.
LEDSettings.html Defines the interactive LED device settings interface in the dashboard. Displays color and function options, power toggle, and current stats visualization. Utilizes Bootstrap templates and jQuery for dynamic behavior, enhancing user control over the LED device.
Utility Modules
File Summary
wifi.h Enables WiFi connectivity for IoT devices. Declares WiFi connection variables and functions. Facilitates seamless integration with parent repositorys cloud and device modules.
mqtt.h Defines MQTT functionality for IoT devices, supporting integer and JSON payloads. Manages data with semaphores and tasks, handling message events through subscriptions and publications. Facilitates efficient communication within the SDP-IoT-Device-Control architecture.
IoT App
File Summary
App.js Defines navigation structure for IoT device control app using React Navigation. Screens for Home, Device List, Fan Control, and LED Control are specified with custom styling. Context from DeviceProvider wraps the app for device management.
---

Getting Started

System Requirements:

  • ESP32 Microcontroller: Required for device control and data collection.
  • Linux-based Machine for Broker: We used a Raspberry Pi with a touchscreen for this purpose.
  • Linux Machine for Cloud Server: This could be the same machine as the broker or a separate one.

Cloning the Repository

To get started with the SDP-IoT-Device-Control project, you need to clone the repository to your local machine. Follow the steps below:

  1. Open your terminal: Ensure you have Git installed on your system. If not, you can download and install it from here.

  2. Clone the repository: Use the following command to clone the repository to your local machine:

    git clone https://github.com/PJalv/SDP-IoT-Device-Control.git
  3. Navigate to the project directory: Change your current directory to the project directory.

    cd SDP-IoT-Device-Control
  4. Set up environment variables: Create a .env file in the root of your project and add the necessary environment variables as specified in the documentation.

Installation

Environment Variables

Create a .env file in the root of your project with the following content:

 BROKER_NAME='<your_broker_name>'
 BROKER_ADDRESS='<your_broker_address>'
 BROKER_PORT='<your_broker_port>'
 SERVER_ADDRESS='<your_server_address>'
 JWT_SECRET='<your_jwt_secret>'
 OPENAI_APIKEY='<your_openai_api_key>'

ESP32 Credential Setup

Edit the creds-template.h file with your network and broker credentials and save it as credentials.h

Usage

Microcontroller Setup

Ensure you have ESP-IDF installed and configured. Use the menuconfig terminal of ESP-IDF to configure the partition.csv file.

Set the COM port for your ESP32 device and then run the following commands to build, flash, and monitor the application:

$ idf.py set-target esp32
$ idf.py menuconfig
$ idf.py build
$ idf.py -p [PORT] flash monitor

Raspberry Pi Setup

The Raspberry Pi hosts the broker, the dashboard GUI, and connects to the WebSocket server. Follow these steps to set it up:

  1. Install the necessary dependencies:
    $ sudo apt-get update
    $ sudo apt-get install mosquitto mosquitto-clients
    $ sudo apt-get install npm
  2. Install Bun, a fast JavaScript runtime:
    $ curl -fsSL https://bun.sh/install | bash
  3. Clone the repository and navigate to the dashboard GUI directory:
    $ git clone https://github.com/PJalv/SDP-IoT-Device-Control.git
    $ cd SDP-IoT-Device-Control/source_code/dashboard_gui
  4. Install the required packages using Bun:
    $ bun install
  5. Start the dashboard GUI:
    $ bun run start

Server Setup

The server is a Go application. Follow these steps to set it up:

  1. Install Go from the official website: https://golang.org/dl/
  2. Clone the repository and navigate to the server directory:
    $ git clone https://github.com/PJalv/SDP-IoT-Device-Control.git
    $ cd SDP-IoT-Device-Control/source_code/server
  3. Build and run the server:
    $ go build server.go
    $ ./server

App Setup

The app is built using Expo. Follow these steps to set it up:

  1. Install Expo CLI:
    $ npm install -g expo-cli
  2. Clone the repository and navigate to the app directory:
    $ git clone https://github.com/PJalv/SDP-IoT-Device-Control.git
    $ cd SDP-IoT-Device-Control/source_code/IOT-App
  3. Install the required packages:
    $ npm install
  4. Start the Expo development server:
    $ expo start

Project Roadmap

  • Refactor Fan Device
  • Refactor LED Device

Contributor Graph


License

This project is protected under the MIT License.


Acknowledgments

  • Advisor: Professor Tim Lin
    • Electrical and Computer Engineering Department, College of Engineering
    • hlin@cpp.edu

Return


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published