Skip to content

This project moves into the Internet of Things (IoT) space, focusing on data ingestion, real-time visualization, and creating a rules engine. Core Idea: A web dashboard that monitors data from simulated smart home devices (thermostats, motion sensors, lights) and allows users to create automation rules

Notifications You must be signed in to change notification settings

aaron-seq/NexusHome_IoT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

66 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

NexusHome IoT Platform v2.1.0

.NET 8 License: MIT Docker SignalR

Advanced IoT-enabled Smart Home Energy Management System with AI-powered Predictive Analytics, Real-time Monitoring, and Automated Optimization.


Features

🏑 Smart Home Management

  • Multi-Protocol Device Support: MQTT, HTTP, CoAP, Matter protocol compatibility
  • Real-time Device Monitoring: Live status updates via SignalR WebSocket connections
  • Energy Consumption Tracking: Detailed power usage analytics and cost calculations
  • Room-based Organization: Logical grouping and management of devices by location

πŸ€– AI-Powered Intelligence

  • Predictive Maintenance: ML.NET-based failure prediction with 90%+ accuracy
  • Energy Optimization: Dynamic power management based on usage patterns and pricing
  • Smart Automation: Rule-based and learning-based device automation
  • Anomaly Detection: Real-time identification of unusual device behavior

πŸ“Š Analytics & Visualization

  • Interactive Dashboards: Real-time energy consumption and device status displays
  • Historical Data Analysis: Comprehensive reporting with trend identification
  • Cost Optimization Reports: Detailed savings analysis and recommendations
  • Performance Metrics: System health monitoring and diagnostic tools

πŸ”’ Enterprise Security

  • JWT Authentication: Secure token-based user authentication
  • Role-Based Access Control: Multi-tier permission system
  • Device Certificates: Secure device-to-platform communication
  • End-to-End Encryption: TLS/SSL protection for all data transmission

πŸ› οΈ Technology Stack

Core Framework

  • .NET 8.0 - Latest LTS version with performance enhancements
  • ASP.NET Core - High-performance web framework
  • Entity Framework Core 8.0 - Advanced ORM with SQL Server support
  • SignalR - Real-time bi-directional communication

IoT & Communication

  • MQTTnet - High-performance MQTT client/server
  • Azure IoT Hub - Cloud-based device management (optional)
  • Matter Protocol - Universal IoT connectivity standard
  • WebSocket - Real-time web communication

Data & Analytics

  • SQL Server - Primary relational database
  • Redis - High-performance caching and session storage
  • InfluxDB - Time-series data storage
  • ML.NET - Machine learning and predictive analytics

Monitoring & DevOps

  • Docker & Docker Compose - Containerized deployment
  • Grafana - Advanced data visualization
  • Prometheus - Metrics collection and monitoring
  • Serilog - Structured logging with multiple sinks

Quick Start Guide

Prerequisites

Ensure you have the following installed on your development machine:

1. Clone & Setup



# Clone the repository

git clone https://github.com/aaronseq12/NexusHome_IoT.git
cd NexusHome_IoT

# Create necessary directories

mkdir logs data uploads certificates

# Copy environment configuration

cp appsettings.json appsettings.Development.json

2. Database Setup

Option A: Using SQL Server (Recommended)



# Update connection string in appsettings.Development.json

# Default: "Server=localhost;Database=NexusHomeIoT;Trusted_Connection=true;MultipleActiveResultSets=true;TrustServerCertificate=true"

# Install EF Core tools (if not already installed)

dotnet tool install --global dotnet-ef

# Create and apply database migrations

dotnet ef migrations add InitialCreate
dotnet ef database update

Option B: Using Docker SQL Server



# Start SQL Server container

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=NexusHome@2025!" \
-p 1433:1433 --name nexus-sqlserver -d \
mcr.microsoft.com/mssql/server:2022-latest

# Update connection string to use SQL Server authentication

# "Server=localhost;Database=NexusHomeIoT;User=sa;Password=NexusHome@2025!;TrustServerCertificate=true"

3. MQTT Broker Setup

Option A: Using Docker (Recommended)



# Create MQTT configuration directory

mkdir -p Configuration

# Create basic Mosquitto configuration

cat > Configuration/mosquitto.conf << EOF
listener 1883
listener 9001
protocol websockets
allow_anonymous true
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
log_type all
EOF

# Start MQTT broker

docker run -it -p 1883:1883 -p 9001:9001 \
-v \$(pwd)/Configuration/mosquitto.conf:/mosquitto/config/mosquitto.conf \
eclipse-mosquitto:2.0

Option B: Install Mosquitto Locally



# Ubuntu/Debian

sudo apt-get install mosquitto mosquitto-clients

# macOS

brew install mosquitto

# Windows - Download from https://mosquitto.org/download/

4. Run the Application

Development Mode (Recommended)



# Restore NuGet packages

dotnet restore

# Build the application

dotnet build

# Run the application

dotnet run

# Application will be available at:

# - HTTP: http://localhost:5000

# - HTTPS: https://localhost:5001

# - API Documentation: http://localhost:5000/api-docs

Using Docker Compose (Full Stack)



# Start all services (recommended for full experience)

docker-compose up -d

# View logs

docker-compose logs -f nexushome-app

# Stop all services

docker-compose down

5. Verify Installation

  1. Web Interface: Navigate to http://localhost:5000
  2. API Documentation: Visit http://localhost:5000/api-docs
  3. Health Check: Check http://localhost:5000/health/ready
  4. Grafana Dashboard: Access http://localhost:3000 (admin/NexusHome@2025!)

API Endpoints

Device Management


GET    /api/devices              \# Get all devices
GET    /api/devices/{deviceId}   \# Get specific device
POST   /api/devices/{deviceId}/toggle  \# Toggle device state
POST   /api/devices/telemetry    \# Submit device data
GET    /api/devices/{deviceId}/energy  \# Get energy consumption

Energy Analytics


GET    /api/energy/consumption   \# Total consumption data
GET    /api/energy/cost         \# Cost analysis
GET    /api/energy/forecast     \# Energy usage predictions

Automation Rules


GET    /api/automation/rules    \# Get all automation rules
POST   /api/automation/rules    \# Create new rule
PUT    /api/automation/rules/{id}  \# Update rule
DELETE /api/automation/rules/{id}  \# Delete rule

Real-time Communication (SignalR)


// Connect to device status hub
const connection = new signalR.HubConnectionBuilder()
.withUrl("/hubs/device-status")
.build();

// Subscribe to device updates
connection.invoke("JoinDeviceGroup", "smart-thermostat-01");


πŸ—οΈ Architecture Overview


β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Frontend (Blazor + React)                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    API Gateway + Load Balancer                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Application Layer                                              β”‚
β”‚  β”œβ”€β”€ Controllers (REST API)                                     β”‚
β”‚  β”œβ”€β”€ SignalR Hubs (Real-time)                                   β”‚
β”‚  └── Background Services                                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Business Logic Layer                                           β”‚
β”‚  β”œβ”€β”€ Device Management                                          β”‚
β”‚  β”œβ”€β”€ Energy Analytics                                           β”‚
β”‚  β”œβ”€β”€ AI/ML Services                                            β”‚
β”‚  └── Automation Engine                                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Infrastructure Layer                                           β”‚
β”‚  β”œβ”€β”€ Data Access (EF Core)                                      β”‚
β”‚  β”œβ”€β”€ External APIs                                              β”‚
β”‚  └── Message Queuing (MQTT)                                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Data Storage Layer                                             β”‚
β”‚  β”œβ”€β”€ SQL Server (Operational)                                   β”‚
β”‚  β”œβ”€β”€ InfluxDB (Time Series)                                     β”‚
β”‚  └── Redis (Caching)                                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜


Configuration

Environment Variables



# Database Configuration

ConnectionStrings__DefaultConnection="Server=localhost;Database=NexusHomeIoT;Trusted_Connection=true"
ConnectionStrings__Redis="localhost:6379"

# Security Settings

JwtAuthentication__SecretKey="your-secret-key-here"
JwtAuthentication__Issuer="NexusHome.IoT"
JwtAuthentication__Audience="NexusHome.Clients"

# MQTT Configuration

MqttBroker__Host="localhost"
MqttBroker__Port=1883
MqttBroker__Username="nexususer"
MqttBroker__Password="your-mqtt-password"

# External APIs

WeatherApi__ApiKey="your-openweather-api-key"

appsettings.json Key Sections

  • ConnectionStrings: Database and external service connections
  • JwtAuthentication: JWT token configuration
  • MqttBroker: MQTT broker settings and topic configuration
  • EnergyOptimization: AI/ML model parameters
  • SecuritySettings: Rate limiting and security policies
  • Logging: Structured logging configuration

Testing

Unit Tests



# Run all tests

dotnet test

# Run with coverage

dotnet test --collect:"XPlat Code Coverage"

# Run specific test category

dotnet test --filter "Category=Integration"

API Testing



# Using curl to test device endpoint

curl -X GET "http://localhost:5000/api/devices" \
-H "Accept: application/json"

# Submit device telemetry

curl -X POST "http://localhost:5000/api/devices/telemetry" \
-H "Content-Type: application/json" \
-d '{
"deviceId": "smart-thermostat-01",
"sensorData": {"temperature": 23.5, "humidity": 45},
"timestamp": "2025-10-06T20:45:00Z"
}'

Load Testing



# Install k6 for load testing

# Test API performance

k6 run --vus 10 --duration 30s scripts/load-test.js


Monitoring & Observability

Health Checks

  • Application Health: /health/ready - Application readiness
  • Database Health: /health/live - Database connectivity
  • External Dependencies: MQTT, Redis, external APIs

Metrics & Logging

  • Structured Logging: Serilog with JSON formatting
  • Metrics Collection: Prometheus-compatible endpoints
  • Distributed Tracing: Built-in ASP.NET Core tracing
  • Performance Counters: Real-time application metrics

Dashboards

  • Grafana: System performance and business metrics
  • Application Insights: Azure-based monitoring (optional)
  • Custom Dashboards: Energy consumption and device analytics

Deployment Options

Development Environment



# Local development with hot reload

dotnet watch run

# Docker development environment

docker-compose -f docker-compose.yml -f docker-compose.override.yml up

Production Deployment

Docker (Recommended)



# Build production image

docker build -t nexushome-iot:latest .

# Run with production configuration

docker run -d -p 80:80 --name nexushome-prod \
--env-file .env.production \
nexushome-iot:latest

Cloud Platforms

  • Azure App Service: Direct deployment with Azure integration
  • AWS ECS/Fargate: Container-based deployment
  • Google Cloud Run: Serverless container deployment
  • Kubernetes: Scalable orchestrated deployment

Vercel Deployment (API Only)



# Install Vercel CLI

npm i -g vercel

# Configure for .NET deployment

# Note: Vercel has limited .NET support, consider API-only deployment

vercel --prod


Security Best Practices

Authentication & Authorization

  • JWT tokens with configurable expiration
  • Role-based access control (RBAC)
  • API key authentication for devices
  • OAuth 2.0 integration support

Data Protection

  • SQL injection protection via Entity Framework
  • Input validation and sanitization
  • HTTPS enforcement in production
  • Secure password hashing (BCrypt)

Network Security

  • CORS configuration for web access
  • Rate limiting to prevent abuse
  • Security headers middleware
  • IP whitelisting support

Device Security

  • Device certificate authentication
  • Encrypted MQTT communication
  • Device provisioning and lifecycle management
  • Regular security updates and patches

Development Guidelines

Code Standards

  • C# Coding Conventions: Microsoft C# coding standards
  • API Design: RESTful principles with OpenAPI documentation
  • Database Design: Normalized schema with proper indexing
  • Error Handling: Comprehensive exception handling and logging

Architecture Patterns

  • Clean Architecture: Separation of concerns with dependency inversion
  • Repository Pattern: Data access abstraction
  • CQRS: Command Query Responsibility Segregation for complex operations
  • Event-Driven: Asynchronous processing with background services

Performance Optimization

  • Async/Await: Non-blocking I/O operations
  • Caching Strategy: Multi-level caching with Redis
  • Database Optimization: Query optimization and connection pooling
  • Resource Management: Proper disposal and memory management

🀝 Contributing

We welcome contributions to the NexusHome IoT Platform! Please read our contributing guidelines:

Getting Started

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup



# Install development dependencies

dotnet tool restore

# Run pre-commit hooks

dotnet format --verify-no-changes
dotnet test

# Update documentation

# Update CHANGELOG.md with your changes

Code Review Process

  • All submissions require review approval
  • Automated tests must pass
  • Code coverage should not decrease
  • Follow established coding standards

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments

  • Microsoft .NET Team - For the excellent .NET 8 framework
  • Eclipse Mosquitto - For the reliable MQTT broker
  • ML.NET Team - For machine learning capabilities
  • Open Source Community - For the amazing libraries and tools

πŸ“ž Support & Contact

Documentation

  • API Documentation: Available at /api-docs when running
  • Architecture Docs: See /docs directory
  • Deployment Guides: Platform-specific deployment instructions

Community Support

  • GitHub Issues: Bug reports and feature requests
  • GitHub Discussions: Community Q&A and discussions
  • Stack Overflow: Tag questions with nexushome-iot

Professional Support


πŸ—“οΈ Roadmap

Version 2.2.0 (Q1 2025)

  • Voice control integration (Alexa, Google Assistant)
  • Mobile app (React Native/Flutter)
  • Advanced AI models for energy prediction
  • Multi-tenant architecture support

Version 2.3.0 (Q2 2025)

  • Edge computing support
  • Blockchain-based device identity
  • Advanced solar panel integration
  • Community energy sharing features

Long-term Vision

  • Global smart grid integration
  • Carbon footprint tracking
  • Advanced weather correlation
  • Machine learning model marketplace

Happy Coding!

Built with ❀️ by Aaron Sequeira and the NexusHome community


Now let me provide you with the essential startup commands:

##  **How to Run Locally - Step by Step**

1. **Update your project files** with the code I provided above
2. **Install prerequisites**:
```bash
# Install .NET 8 SDK (if not already installed)
# Download from: https://dotnet.microsoft.com/download/dotnet/8.0

# Verify installation
dotnet --version
  1. Create the directory structure:
mkdir -p Core/Domain Core/Services/Interfaces
mkdir -p Infrastructure/Data Infrastructure/Services Infrastructure/Configuration
mkdir -p Application/Hubs Application/DTOs
mkdir -p API/Controllers API/Middleware
mkdir -p Configuration Scripts
  1. Database setup (Choose one option):

Option A - SQL Server Express (Recommended):

# Install Entity Framework tools
dotnet tool install --global dotnet-ef

# Create migration
dotnet ef migrations add InitialCreate

# Update database
dotnet ef database update

Option B - Docker SQL Server:

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=NexusHome@2025!" \
  -p 1433:1433 --name nexus-sqlserver -d \
  mcr.microsoft.com/mssql/server:2022-latest
  1. Run the application:
# Restore packages
dotnet restore

# Build the project
dotnet build

# Run in development mode
dotnet run
  1. Access the application:

The application will start with demo data and you can begin testing the APIs immediately!

About

This project moves into the Internet of Things (IoT) space, focusing on data ingestion, real-time visualization, and creating a rules engine. Core Idea: A web dashboard that monitors data from simulated smart home devices (thermostats, motion sensors, lights) and allows users to create automation rules

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published