Skip to content

A secure and extensible .NET system for collecting, storing, and analyzing photovoltaic (solar panel) data using Azure and SQL Server — deployable on edge IoT devices or in the cloud.

License

Notifications You must be signed in to change notification settings

MrNetic/PhotovoltaicStack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

☀️ PhotovoltaicStack

.NET Azure License: MIT GitHub Repo

PhotovoltaicStack is a secure and modular backend system designed to collect, store, and process photovoltaic (solar panel) telemetry data from external providers such as Huawei Smart PV APIs.
It’s engineered using .NET 8 and Azure services, with a strong focus on security, observability, and enterprise-grade design.


🧩 Upcoming Features

⚡ Intelligent Power Plug Controller An upcoming release will introduce a smart control application that dynamically manages an electricity plug based on recent energy data:

✅ The plug will only turn ON if the difference between generated and consumed energy over the last 10 minutes is positive, ensuring energy-efficient, self-sustaining usage.

This feature will bridge the PhotovoltaicStack backend with IoT-based automation, creating a complete closed-loop energy management system.

🧠 Deployment Example: Running on Raspberry Pi (ARM64)

The PhotovoltaicStack Data Gatherer has been successfully compiled for ARM64 and deployed as a systemd service on a Raspberry Pi IoT device.
This demonstrates its ability to run efficiently on low-power edge devices while maintaining full compatibility with Azure and Key Vault authentication, currently running from my house...

The service is configured as a one-shot systemd job, triggered periodically by a timer (photovoltaicstack.timer), and executes successfully on every run.

✅ Service executed successfully on ARM64 (Raspberry Pi)
🕒 Triggered by systemd timer
🔋 Demonstrates full cross-platform compatibility, note: same code runs on Azure Container Apps or IoT edge devices.

image image

📊 Data Collection in Action

The screenshot below shows real telemetry data successfully collected from the Huawei Smart PV API and stored in the Azure SQL Database by the PhotovoltaicStack.DataGatherer background service.

image

This query was executed in SQL Server Management Studio (SSMS), confirming that the system is continuously retrieving and persisting data for further analytics and automation.

✅ Data successfully gathered and stored in Azure SQL Database
☁️ Queried via SSMS for validation and analysis
🔁 Continuous data ingestion cycle validated end-to-end


🔌 Foundation for Intelligent Power Management

This telemetry dataset, containing real-time solar energy production and consumption metrics will serve as the foundation for the upcoming Intelligent Power Plug Controller.

That application will automatically analyze the energy surplus of the last 10 minutes and control an IoT-connected plug accordingly.

Logic preview:
If (GeneratedEnergy - ConsumedEnergy) > 0 → Plug = ON
Else → Plug = OFF

This will close the loop between data collection, storage, and real-world automation, evolving PhotovoltaicStack into a complete, secure, and autonomous solar energy management platform.

⚙️ Overview

PhotovoltaicStack is part of a long-term initiative to build an open, cloud-native backend stack for solar energy monitoring and analytics.
The core component is a background service (PhotovoltaicStack.DataGatherer) that authenticates with external providers, fetches data securely, and persists it to an Azure SQL Database (or any other SQL Server instance).

✅ This implementation has been tested and validated to work with the Huawei SUN2000-4KTL-L1 Inverter, ensuring full compatibility with Huawei Smart PV telemetry endpoints.

The system follows Clean Architecture principles with strict separation of concerns:

  • Domain Core business models and logic.
  • Infrastructure Persistence layer (db, repositories).
  • External Integration with Huawei APIs.
  • Shared Common utilities, logging, and cross-cutting concerns.
  • DB SQL Server database project (SSDT).
  • DataGatherer Console/worker app for scheduled data collection.

Ping me if you would like to contribute ([email protected])


🌐 API Source Reference

The API call structure and data models implemented in this project are based on the official Huawei Smart PV OpenAPI documentation:

🔗 Huawei Smart PV OpenAPI – Monitoring

This ensures accurate representation of endpoints, telemetry models, and authentication workflows aligned with Huawei’s enterprise integration standards.

🧩 The implementation has been successfully tested with Huawei SUN2000-4KTL-L1 inverters through the FusionSolar cloud platform.

🏗️⚡ Architecture

PhotovoltaicStack follows a layered and modular architecture designed for clean separation of concerns and secure, scalable execution.

System flow (simplified):

Huawei Cloud APIs
⬇️ (OAuth2 + HTTPS)
DataGatherer Service
⬇️
Infrastructure Layer – DB / Repositories
⬇️
Azure SQL Database
⬇️
Serilog + Application Insights → Azure Monitor / Log Analytics


🧩 Key Architectural Patterns

  • Dependency Injection throughout the stack
  • Serilog for structured logging with correlation IDs
  • Retry & resilience policies (Polly : coming soon)
  • Managed Identity + Key Vault for secure secret handling
  • Containerized deployment via Docker / Azure Container Apps

⚙️ Getting Started Prerequisites .NET 8 SDK

SQL Server (local or Azure SQL)

Optional: Docker for containerized execution.

1️⃣ Clone the Repository bash Copy code git clone https://github.com/MrNetic/PhotovoltaicStack.git cd PhotovoltaicStack 2️⃣ Configurations, follow template, it relies on Azure Key Vault for handling secrects. ⚠️ In production, secrets are never stored in configuration files : they’re retrieved from Azure Key Vault via Managed Identity.

3️⃣ Run Locally

bash

Copy code

cd src/PhotovoltaicStack.DataGatherer dotnet run

or with Docker:

bash

Copy code

docker build -t photovoltaicstack:latest -f Dockerfile . docker run --env-file .env photovoltaicstack:latest

or directly from visual studio

🧩 Configuration Structure

PhotovoltaicStack uses a layered configuration model based on appsettings.json and Azure Key Vault. The local configuration file (appsettings.json) defines parameters (like endpoints, polling intervals, and database targets(without exposing sensitive data)), while credentials are securely stored and retrieved from Azure Key Vault using Managed Identity.

Below is the configuration layout used by the system: { "ExternalProvider": "Huawei",

"Huawei": { "WebServiceBaseURL": "https://eu5.fusionsolar.huawei.com/thirdData", "APIs": { "Login": "/login", "GetStationRealKpi": "/getStationRealKpi", "OtherAPI": "/other-endpoint" }, "UsernameSecret": "External-Huawei-Username", "PasswordSecret": "External-Huawei-Password", "TokenExpireTimeInMinutes": 10, "PollingFrequencyInMinutes": 5, "StationCodes": "YOURSTATIONCODE:EXampleNE=171971489" },

"KeyVaultURI": "https://YOURKEYVAULT.vault.azure.net/", "ConnectionStrings": { "PhotovoltaicStackDB": "Server=YOURDATABASE.database.windows.net;Database=PhotovoltaicStack;TrustServerCertificate=true;" } } 🔒 Key Points UsernameSecret and PasswordSecret are Key Vault secret names, not plaintext credentials.

At runtime, the service retrieves them securely using Azure Managed Identity.

The ConnectionStrings section only defines the database location : credentials are also stored in Key Vault.

PollingFrequencyInMinutes defines how often the data gatherer polls Huawei APIs.

KeyVaultURI points to the Azure Key Vault used by the container or App Service instance.

Secrets are never committed or logged : the system follows Zero Trust principles.

You can find an example file at: 📁 /src/PhotovoltaicStack.DataGatherer/appsettings.json.example

🧠 Design Principles

-Clean Architecture Domain at the center, independent from external frameworks.

-SOLID Every service, interface, and repository adheres to SOLID design.

-Secure by Default Uses Managed Identity, Key Vault, and least privilege DB access.

-Observable Structured logging (Serilog) + telemetry (OpenTelemetry integration planned).

-Cloud-Native Built for Azure Container Apps & Azure SQL.

🔐 Security & Secrets Management No credentials are committed to the repository.

Azure Key Vault stores API keys and secrets.

Managed Identity ensures the container authenticates securely with Azure.

Logs are enriched with Correlation IDs for traceability.

The system follows Zero Trust and least privilege principles across all layers.

🧪 Testing Tests (unit + integration) are under development. Planned:

Unit tests for Domain models and services.

Integration tests for Infrastructure using Testcontainers for .NET with SQL Server.

Mocking of Huawei APIs for offline testing.

📈 Observability Tool Purpose Serilog Structured logs with timestamps and correlation IDs. Azure Application Insights Telemetry and performance metrics. OpenTelemetry Planned for distributed tracing and metrics export.

🛠️ CI/CD Pipeline (Planned) Stage Action Build Compile, restore dependencies, run analyzers. Test Unit & integration tests using GitHub Actions. SAST Security scan with CodeQL. Docker Build Build and tag container image. Deploy Push to Azure Container Registry and deploy to Azure Container Apps Job.

🗺️ Roadmap Initial Huawei integration (telemetry pull)

DB persistence layer

Serilog logging

Docker support

Azure Managed Identity integration

Health checks endpoint

Polly retry/circuit breaker

OpenTelemetry metrics & traces

API & WebUI for visualization

Intelligent Plug Controller for real-time automation ⚡

🧑‍💻 Author Paulo Condeça Principal SQL Server DBA & Secure Backend Engineer 🇮🇪 Based in Ireland • MSc in Software Design with Cybersecurity

About

A secure and extensible .NET system for collecting, storing, and analyzing photovoltaic (solar panel) data using Azure and SQL Server — deployable on edge IoT devices or in the cloud.

Topics

Resources

License

Stars

Watchers

Forks