Siddhant Kumar
Project 069 · Energy

Solar Rooftop Monitor.

Tracks what a rooftop solar array actually generates against what it should — catching the underperformance from shading, soiling and faults that quietly steals a big share of your energy.

Intermediate 12–18 hours 31 min read SolarMonitoringCloud
Jump to source Bill of materials
Solar Rooftop Monitor — reference build illustration MCU VCC · GND · SIG · NC
Difficulty
Intermediate
Build time
12–18 hours
Indicative cost
₹4,000 – ₹7,000
Platform
ESP32 DevKit V1 (ESP-WROOM-32)
Category
Energy
Last updated
28 July 2026
Contents — 26 sections

Project Overview

Tracks what a rooftop solar array actually generates against what it should — catching the underperformance from shading, soiling and faults that quietly steals a big share of your energy.

A rooftop solar array is a silent investment: it sits on the roof, generates power, and — unless you are watching closely — you have no idea whether it is producing what it should. And often it is not. Panels get shaded by a new tree or a chimney, dust and bird droppings build up and cut output, a string develops a fault, an inverter derates, a bypass diode fails — and because the system keeps producing something, these losses are invisible. Studies repeatedly find real-world arrays running well below their potential for exactly these reasons. This project builds a monitor that catches that lost generation by comparing what the array actually produces against what it should, given the sun available.

The key idea is expectation, not just measurement. Measuring generation alone tells you the array made 18 kWh today — but was that good or bad? The monitor measures generation (per string where possible, using current/voltage sensors) and the available sunlight (irradiance) and panel temperature, so it can compute the performance ratio — actual output versus the output the array should have produced under those conditions. A performance ratio that is healthy means the array is fine; one that is low, or falling over time, means energy is being lost, and the monitor can often say why: a sudden drop points to a fault, a gradual decline to soiling, a daily shadow pattern to shading, one string lagging its neighbours to a string-level problem.

Per-string (or per-panel) monitoring is what turns "the array is underperforming" into "string 2 is the problem", because comparing strings that should behave identically instantly localises a fault or a shadow. The monitor logs and trends everything, alerts on abnormal underperformance, and quantifies the lost energy (and money) so a cleaning or a repair can be justified and its benefit verified. It is honest that accurate performance-ratio needs a decent irradiance/temperature reference and that string comparison is the most practical fault signal for a DIY build. But as a monitor that measures generation against expectation, it converts a silent, opaque investment into one you can actually manage — catching the shading, soiling and faults that would otherwise quietly erode your returns for years.

A photovoltaic solar panel in sunlight
Rooftop solar measured against expectation, not just kWh, reveals hidden underperformance. Photograph sourced from Wikimedia Commons — Solar panel.jpg. Reused under the licence stated on that page; please check it before republishing.

What this project does

  • Measures solar generation (per string where possible) via current/voltage
  • Measures irradiance and panel temperature to compute expected output
  • Computes performance ratio — actual vs expected generation
  • Detects underperformance from shading, soiling, faults and derating
  • Localises faults by comparing strings that should behave identically
  • Trends generation and quantifies lost energy/money
  • Alerts on abnormal underperformance and verifies fixes/cleaning

Real-World Applications

SettingHow it is used
Home rooftop solarKnowing your array performs as it should, and catching shading/soiling/faults that steal generation.
Commercial / C&I solarPer-string performance monitoring and fault localisation across larger arrays.
O&M / cleaning optimisationQuantifying soiling loss to schedule cleaning when it pays, and verifying it worked.
Solar fault diagnosisDetecting and localising underperforming strings, failed diodes and derating.

Deployment contexts where a build of this kind earns its keep.

Features & Capabilities

  • Performance ratio (generation vs expectation), not just kWh
  • Per-string comparison to localise faults/shading
  • Irradiance + temperature reference for true expectation
  • Soiling/shading/fault discrimination from the pattern
  • Lost-energy quantification and cleaning/repair verification
  • Trending and abnormal-underperformance alerts
  • Honest about reference-sensor needs

Difficulty, Time & Required Skills

AttributeValue
Difficulty levelIntermediate
Estimated completion time12–18 hours
Indicative build cost₹4,000 – ₹7,000
Primary disciplineEnergy
Reference platformESP32 DevKit V1 (ESP-WROOM-32)

Skills you should have (or will pick up)

  • DC current/voltage measurement per string
  • Irradiance and panel-temperature sensing
  • Performance-ratio and expected-output computation
  • String comparison for fault localisation
  • Trending, lost-energy quantification and alerting

Bill of Materials

Every part below is commonly available from Indian and international hobby-electronics suppliers. Prices are indicative 2026 retail figures in Indian rupees and will drift — treat them as a budgeting guide, not a quotation.

ComponentKey specificationQtyApprox. cost
ESP32 DevKit V1 (ESP-WROOM-32)
Wi-Fi transmit bursts peak near 500 mA — size the regulator accordingly.
Dual-core Xtensa LX6 @ 240 MHz, 520 KB SRAM, 4 MB flash, Wi-Fi 802.11 b/g/n + BLE 4.2, 34 GPIO, 18× 12-bit ADC, 2× 8-bit DAC1₹450
INA219 high-side DC current/power monitor
Reports bus voltage, shunt voltage, current and power directly — no maths needed.
0–26 V bus, ±3.2 A with 0.1 Ω shunt, 12-bit, ±0.5 % gain error1₹260
ACS712 hall-effect current sensor (20 A)
Zero-offset drifts with temperature — re-zero at boot with no load.
±20 A, 100 mV/A, 80 kHz bandwidth, 1.2 mΩ internal resistance, 2.1 kV isolation1₹180
DS18B20 waterproof temperature probe
Dozens can share one GPIO — you address them by ROM code.
−55 to +125 °C, ±0.5 °C from −10 to +85 °C, 9–12-bit resolution, unique 64-bit ROM ID1₹160
BH1750 digital ambient light sensor
Far more linear than an LDR — use it whenever you need real lux, not a relative value.
1–65535 lx, 16-bit, ±20 %, spectral response close to the human eye1₹140
0.96″ SSD1306 OLED display
Static images burn in — invert or scroll the screen periodically.
128 × 64 monochrome, 1.3–3.3 V logic, 100 kHz–400 kHz I²C1₹250
microSD card 32 GB A1 class
For 24/7 loggers buy a high-endurance card — normal cards die in months.
A1 rated, 10 MB/s random write, UHS-I, endurance-grade recommended1₹450
5 V 3 A regulated SMPS adapter
Measure the real output — many "3 A" adapters sag below 4.7 V at 2 A.
100–240 VAC in, 5 V ±5 % out, 3 A, short-circuit and over-voltage protection1₹350
Per-string DC current/voltage sensing
PV DC voltages are high and dangerous — use rated, isolated sensing
Hall/shunt current + voltage divider per string (isolated, rated for PV voltage)2₹2,400
Irradiance reference
A matched reference cell is practical and cheap
A reference cell or a calibrated pyranometer/PV reference for expected output1₹1,500
Panel temperature sensorBack-of-panel temperature sensor (temperature derates output)1₹150
Isolation / safety interfaceIsolated sensing and enclosure appropriate to PV DC1₹600

Estimated total: ₹6,890, excluding tools, shipping and consumables.

Tools and consumables

  • Soldering iron (temperature controlled, 350 °C) with 0.8 mm 60/40 or lead-free solder
  • Digital multimeter — continuity, DC volts and current ranges
  • Wire strippers, flush cutters and a small set of precision screwdrivers
  • Heat-shrink tubing and a heat gun (or a lighter, carefully)
  • A laptop with a USB port and the toolchain listed above

Hardware Specifications

PartSpecificationSupplyInterfaceReference
ESP32 DevKit V1 (ESP-WROOM-32)Dual-core Xtensa LX6 @ 240 MHz, 520 KB SRAM, 4 MB flash, Wi-Fi 802.11 b/g/n + BLE 4.2, 34 GPIO, 18× 12-bit ADC, 2× 8-bit DAC3.3 V logic / 5 V USBUART, SPI, I²C, I²S, CAN, PWMDatasheet
INA219 high-side DC current/power monitor0–26 V bus, ±3.2 A with 0.1 Ω shunt, 12-bit, ±0.5 % gain error3–5.5 VI²C (0x40–0x4F)Datasheet
ACS712 hall-effect current sensor (20 A)±20 A, 100 mV/A, 80 kHz bandwidth, 1.2 mΩ internal resistance, 2.1 kV isolation5 VAnalogueDatasheet
DS18B20 waterproof temperature probe−55 to +125 °C, ±0.5 °C from −10 to +85 °C, 9–12-bit resolution, unique 64-bit ROM ID3.0–5.5 V1-Wire (multi-drop)Datasheet
BH1750 digital ambient light sensor1–65535 lx, 16-bit, ±20 %, spectral response close to the human eye2.4–3.6 VI²C (0x23/0x5C)Datasheet
0.96″ SSD1306 OLED display128 × 64 monochrome, 1.3–3.3 V logic, 100 kHz–400 kHz I²C3.3–5 VI²C (0x3C)Datasheet
microSD card 32 GB A1 classA1 rated, 10 MB/s random write, UHS-I, endurance-grade recommended3.3 VSDIO / SPIDatasheet
5 V 3 A regulated SMPS adapter100–240 VAC in, 5 V ±5 % out, 3 A, short-circuit and over-voltage protection5 VDC barrel / USBDatasheet

Consolidated electrical and interface specifications for every active part in the build.

Power Budget & Supply Sizing

Add up the typical active current of every part, then size the supply with at least 50 % headroom so transmit bursts and motor inrush never brown out the controller.

LoadSupply railTypical current (mA)Notes
ESP32 DevKit V1 (ESP-WROOM-32)3.3 V logic / 5 V USB160Wi-Fi transmit bursts peak near 500 mA — size the regulator accordingly.
INA219 high-side DC current/power monitor3–5.5 V1Reports bus voltage, shunt voltage, current and power directly — no maths needed.
ACS712 hall-effect current sensor (20 A)5 V10Zero-offset drifts with temperature — re-zero at boot with no load.
DS18B20 waterproof temperature probe3.0–5.5 V1.5Dozens can share one GPIO — you address them by ROM code.
BH1750 digital ambient light sensor2.4–3.6 V0.19Far more linear than an LDR — use it whenever you need real lux, not a relative value.
0.96″ SSD1306 OLED display3.3–5 V20Static images burn in — invert or scroll the screen periodically.
microSD card 32 GB A1 class3.3 V100For 24/7 loggers buy a high-endurance card — normal cards die in months.
5 V 3 A regulated SMPS adapter5 V3000Measure the real output — many "3 A" adapters sag below 4.7 V at 2 A.

Summed typical draw is 3292.69 mA. With a 1.5× design margin the supply should deliver at least 5000 mA continuously at the stated rail voltage.

Software Requirements & Development Environment

Reference toolchain: Arduino IDE 2.3.x with the ESP32 board package 3.x (or PlatformIO on VS Code). Anything newer normally works; anything older may lack the board definitions used here.

  • Install the Arduino IDE 2.3.x (or PlatformIO if you prefer a real editor and dependency locking).
  • Add https://espressif.github.io/arduino-esp32/package_esp32_index.json under File → Preferences → Additional Board Manager URLs, then install esp32 from the Boards Manager.
  • Set the correct port under Tools → Port. On Linux add yourself to the dialout group: sudo usermod -aG dialout $USER and log out and back in.
  • Open the Serial Monitor at 115200 baud — every sketch here logs its state there.
  • Keep File → Preferences → Show verbose output during: compilation switched on while you are debugging build errors.

Required libraries

LibraryWhy it is neededInstall
WiFi (ESP32 core) bundledStation/AP connection management for the ESP32.Bundled with the ESP32 Arduino core
PubSubClient 2.8Lightweight MQTT 3.1.1 client for constrained devices.Library Manager → "PubSubClient" by Nick O'Leary
ina219lib
OneWire + DallasTemperature 2.3.x / 3.9.xBus enumeration and conversion commands for DS18B20 probes.Library Manager → "DallasTemperature" (pulls OneWire)
BH1750 1.3.0Digital lux readings with selectable resolution modes.Library Manager → "BH1750" by Christopher Laws
Adafruit SSD1306 + GFX 2.5.xFramebuffer and text/graphics primitives for the OLED.Library Manager → "Adafruit SSD1306"
InfluxDB 2.x + Telegraf 2.7Time-series storage with retention policies and downsampling.docker run -p 8086:8086 influxdb:2.7
Grafana 11.xDashboards, threshold alerting and shareable panels.docker run -p 3000:3000 grafana/grafana-oss

Block Diagram

The block diagram shows the functional decomposition of the system — what senses, what decides, what acts, and where the data ends up.

Solar Rooftop Monitor — system block diagramFunctional block diagram of the Solar Rooftop Monitor system. MeasurePer-string I/VgenerationIrradianceavailable sunPanel tempderatingExpectESP32expected outputPerf ratioactual/expectedDiagnoseString comparelocalise faultSoil/shade/faultpatternActDashboardPR trendLost energyclean/fixrightrightnone
Solar Rooftop Monitor — system block diagram

Circuit Diagram & Wiring

Every signal line in the build is shown below, followed by a pin-by-pin connection table you can work through with a multimeter in hand.

Solar Rooftop Monitor — wiring schematicConnection schematic showing which controller pin drives each peripheral. Sensors / InputsControllerActuators / OutputsESP32 DevKit V1(ESP-WROOM-32)3.3 V logic / 5 V USBINA219 / shunt (string)GPIO 21/22Stringcurrent/voltage(I²C)Irradiance refGPIO 34 / I²CAvailable sunlightPanel temp (DS18B20)GPIO 4Back-of-paneltemperatureOLEDGPIO 21/22Generation / PRWi-FiDashboardmicroSDshared + CSLog/trendIsolated supply3V3 regPower (isolated fromPV DC)
Solar Rooftop Monitor — wiring schematic
PeripheralPeripheral pinController pinSignal
INA219 / shunt (string)SDA/SCLGPIO 21/22String current/voltage (I²C)
Irradiance refAOUT/I²CGPIO 34 / I²CAvailable sunlight
Panel temp (DS18B20)DQGPIO 4Back-of-panel temperature
OLEDSDA/SCLGPIO 21/22Generation / PR
Wi-Fion-chipDashboard
microSDSPIshared + CSLog/trend
Isolated supply+/–3V3 regPower (isolated from PV DC)

Wire one row at a time and tick it off — most "it does not work" reports trace back to a single swapped pair.

Wiring explanation

  • PV DC voltages are high and dangerous even in sunlight — use isolated, appropriately-rated sensing and have a qualified installer do or verify the DC-side connections.
  • Sense current and voltage per string so strings can be compared to localise faults/shading.
  • Place the irradiance reference in the same plane/orientation as the panels so "expected" reflects the sun the array actually sees.
  • Fit a back-of-panel temperature sensor; panel output derates as temperature rises, so temperature is needed for a true expectation.
  • Keep the low-voltage electronics isolated from the PV DC side.
An ESP32 development board with the ESP-WROOM-32 module and USB connector
ESP32 module computing performance ratio from generation, irradiance and panel temperature. Photograph sourced from Wikimedia Commons — ESP32 Espressif ESP-WROOM-32 Dev Board.jpg. Reused under the licence stated on that page; please check it before republishing.

System Architecture

Read the stack from the bottom up: physical hardware, the firmware that drives it, the transport that moves data off the device, and the software a human actually looks at.

Solar Rooftop Monitor — architecture stackLayered architecture from hardware to user interface. Hardware layerESP32 DevKit V1 (ESP-WROOM-32) · ACS712 hall-effect current sensor (20 A)· DS18B20 waterproof temperature probe · BH1750 digital ambient lightsensorDriver layerwifi · pubsub · ina219lib · onewireApplication logicsampling loop · filtering · thresholds · state machineTransport layerWi-Fi → InfluxDB + Grafana · TLS · retry and backoffPresentation layerdashboard · mobile notifications · historical charts
Solar Rooftop Monitor — architecture stack

Working Principle

The core insight is that generation only has meaning against expectation. An array that made 18 kWh today is impossible to judge without knowing how much sun there was — 18 kWh on a bright day may be poor, on a cloudy day excellent. So the monitor measures not just output but the conditions that determine what output should be: the available irradiance (via a reference cell or pyranometer in the panels' plane) and the panel temperature (because PV output derates as cells heat up — a hot panel produces measurably less than a cool one at the same irradiance). From these it computes the performance ratio: actual generation divided by the generation the array should have produced under the measured sun and temperature. Performance ratio is the single number that tells you whether the array is healthy, independent of the weather.

A low or falling performance ratio is the signal that energy is being lost, and the pattern of the loss often reveals the cause. A sudden drop points to a fault — a tripped string, a failed inverter, a blown fuse or bypass diode. A gradual decline over weeks with no rain points to soiling — dust, pollen and droppings accumulating on the glass — which a good rain or a clean reverses (and the monitor can prove the reversal). A loss that recurs at the same time each day and grows with the seasons points to shading from a fixed obstruction whose shadow tracks the sun. And a persistent shortfall may be inverter derating or module degradation. Reading the shape of the underperformance turns "something is wrong" into a likely diagnosis.

The most powerful and practical diagnostic for a DIY build is per-string comparison. Strings of panels wired identically, in the same plane, under the same sun, should generate nearly identically — so when one string lags its neighbours, the problem is almost certainly in that string: a shadow falling on it, a fault, a failed diode, or heavier soiling. This differential approach is beautifully robust because it cancels out the weather entirely — you are not comparing to a model but to an identical sibling under identical conditions, so any divergence is real and localised. "The array is down 15%" becomes "string 2 is producing 30% less than string 1", which points a technician straight at the problem.

What makes the monitor pay is quantification and verification. By continuously comparing actual to expected, it can put a number on the lost energy — and its money value — from soiling or a fault, which is what justifies the cost of a cleaning or a repair (soiling losses often exceed cleaning costs, but only measurement tells you when). And the same measurement verifies the fix: clean the panels and the performance ratio jumps back up by the quantified amount, proving the cleaning paid for itself; repair a string and its output rejoins its neighbours. The design is honest about its needs — a genuinely accurate performance ratio depends on a decent irradiance and temperature reference, and DC-side sensing on a live PV system is hazardous and best left to qualified work — but within that, it transforms rooftop solar from a silent black box into a managed asset, catching the shading, soiling and faults that would otherwise quietly bleed away a meaningful fraction of the generation you paid for.

The maths behind it

Performance ratio

plainPerformance ratio
PR = actual energy / expected energy

expected ≈ (irradiance / STC_irradiance) · P_rated · η_temp
  η_temp = 1 + γ·(T_cell − 25°C)   (γ ≈ −0.4%/°C, negative)

PR near its healthy value = fine; low/falling PR = losses.
PR cancels weather, so it is comparable day to day.

Per-string comparison (differential)

plainPer-string comparison (differential)
Identical strings under identical conditions should match:

  ratio_i = P_string_i / mean(P_other_strings)

  fault/shade on string i if ratio_i << 1 (sustained)
Cancels weather entirely → any divergence is real & localised.

Lost energy / soiling

plainLost energy / soiling
Loss vs expectation over a period:

  lost_kWh = Σ (expected − actual)
  lost_cost = lost_kWh · tariff (or feed-in rate)

Gradual PR decline (no rain) → soiling; step → fault.
Clean/repair → PR recovers by the quantified amount (verify).

Program Flowchart

The firmware is a single cooperative loop. Nothing blocks for long, so networking, sensing and the user interface all stay responsive.

Solar Rooftop Monitor — firmware flowchartControl flow through the main program loop. Read per-string I/V,irradiance, tempCompute expected output + PRPR low or a stringlagging?Diagnose (shade/soil/fault); alertTrendDiagnose (shade/soil/fault);alertTrendQuantify lost energy; report
Solar Rooftop Monitor — firmware flowchart

Assembly Instructions

Build on a breadboard first and only commit to solder once the whole system has run for an hour without a fault.

  1. Install per-string sensing safely

    Fit isolated, appropriately-rated current and voltage sensing on each string so strings can be compared. Have a qualified installer do or verify the PV DC-side work.

  2. Add irradiance and temperature reference

    Mount an irradiance reference (reference cell/pyranometer) in the panels' plane and a back-of-panel temperature sensor, so expected output reflects the real sun and cell temperature.

  3. Set up computation and reporting

    Compute expected output, performance ratio and per-string ratios; log and trend; and set up the dashboard and alerts.

Step-by-Step Implementation Guide

Work through these in order. Each step ends in something you can observe, so a failure is always localised to the step you just finished.

  1. Compute expected output, PR and string ratios

    From irradiance and temperature compute expected output, divide actual by expected for PR, and compare strings to localise problems.

    cppsolar-performance.ino
    #define P_RATED_W  3000.0f      // array/string rated power (STC)
    #define STC_IRR    1000.0f      // W/m2 at STC
    #define GAMMA     -0.004f       // -0.4%/degC temperature coefficient
    
    float expectedPower(float irr, float tCell){
      float etaTemp = 1.0f + GAMMA*(tCell - 25.0f);
      return (irr/STC_IRR) * P_RATED_W * etaTemp;
    }
    
    float performanceRatio(float actualW, float irr, float tCell){
      float exp = expectedPower(irr, tCell);
      return exp>1 ? actualW/exp : 0;
    }
    
    // Compare each string to the mean of the others (weather cancels out).
    int laggingString(float *p, int n){
      for (int i=0;i<n;i++){
        float sum=0; int c=0;
        for(int j=0;j<n;j++) if(j!=i){ sum+=p[j]; c++; }
        float others = c? sum/c : 0;
        if (others>1 && p[i] < 0.7f*others) return i;   // 30% below siblings
      }
      return -1;
    }
    float etaTemp = 1.0f + GAMMA*(tCell - 25.0f)Applies the negative temperature coefficient so the expected output accounts for a hot panel producing less — without this, a fine array on a hot day looks like it is underperforming.
    return exp>1 ? actualW/exp : 0Performance ratio is actual over expected, the weather-independent number that says whether the array is healthy.
    int laggingString(float *p, int n)Compares each string to the mean of the others; because they share the same weather, a string 30% below its siblings is a localised fault or shadow, not a cloudy patch.
  2. Diagnose, quantify and verify

    Classify underperformance by its pattern (sudden fault, gradual soiling, daily shading), quantify lost energy/money, alert, and verify that cleaning/repairs restore performance ratio.

Complete Source Code

The listing below is complete and compiles as written — there are no elided sections. Read the annotations under each block before you upload it.

cppsolar-rooftop-monitor.ino
/* ═══════════════════════════════════════════════════════════════
   Solar Rooftop Monitor — ESP32

   Measures per-string generation against expected output (from
   irradiance + panel temperature), computes performance ratio,
   localises faults/shading by string comparison, and quantifies lost
   energy. DC-side sensing must be isolated/rated (safety).
   ══════════════════════════════════════════════════════════════════ */

#include <WiFi.h>
#include <PubSubClient.h>
#include <Wire.h>
#include <Adafruit_INA219.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <BH1750.h>

#define NSTR 2
#define P_RATED_W 3000.0f
#define STC_IRR 1000.0f
#define GAMMA -0.004f

Adafruit_INA219 ina[NSTR];        // per-string (distinct I2C addr)
OneWire ow(4); DallasTemperature panelT(&ow);
BH1750 lux;                        // stand-in for irradiance ref (scaled)
WiFiClient net; PubSubClient mqtt(net);
float lostWh=0; uint32_t lastMs=0;

float expectedPower(float irr,float tCell){
  return (irr/STC_IRR)*P_RATED_W*(1.0f+GAMMA*(tCell-25.0f));
}

void setup(){
  Serial.begin(115200);
  Wire.begin(21,22);
  for(int i=0;i<NSTR;i++) ina[i].begin();     // addresses set per module
  panelT.begin(); lux.begin();
  WiFi.begin(WIFI_SSID,WIFI_PASS); mqtt.setServer(MQTT_HOST,1883);
  lastMs=millis();
}

void loop(){
  if(!mqtt.connected()&&WiFi.status()==WL_CONNECTED) mqtt.connect("solar-1");
  mqtt.loop();
  uint32_t now=millis(); float dtHr=(now-lastMs)/3600000.0f; lastMs=now;

  panelT.requestTemperatures();
  float tCell = panelT.getTempCByIndex(0);
  float irr   = lux.readLightLevel() * IRR_SCALE;   // → W/m2 (calibrated ref)

  float p[NSTR], total=0;
  for(int i=0;i<NSTR;i++){
    float v = ina[i].getBusVoltage_V();
    float i_a = ina[i].getCurrent_mA()/1000.0f;
    p[i] = v*i_a; total += p[i];
  }

  float expected = expectedPower(irr, tCell);
  float pr = expected>1 ? total/expected : 0;
  lostWh += fmaxf(0, expected-total) * dtHr;         // accumulate lost energy

  // per-string comparison
  int lag = -1;
  for(int i=0;i<NSTR && lag<0;i++){
    float others=0; int c=0;
    for(int j=0;j<NSTR;j++) if(j!=i){ others+=p[j]; c++; }
    if(c && others/c>1 && p[i] < 0.7f*(others/c)) lag=i;
  }

  const char* diag = nullptr;
  if (lag>=0) diag = "string lagging (fault/shade)";
  else if (pr < 0.7f && irr>200) diag = "array underperforming";

  char m[240];
  snprintf(m,sizeof m,
    "{\"total_W\":%.0f,\"pr\":%.2f,\"irr\":%.0f,\"tCell\":%.1f,"
    "\"lag\":%d,\"lost_Wh\":%.0f,\"diag\":\"%s\"}",
    total, pr, irr, tCell, lag, lostWh, diag?diag:"ok");
  mqtt.publish("solar/1/perf", m);
  if (diag) mqtt.publish("solar/1/alert", diag);

  delay(10000);                                      // 0.1 Hz
}
float expected = expectedPower(irr, tCell)Expected output is computed from the measured sun and panel temperature, giving the benchmark that turns raw generation into a judgeable performance ratio.
float pr = expected>1 ? total/expected : 0Performance ratio is the health number — near its healthy value the array is fine; low means energy is being lost.
lostWh += fmaxf(0, expected-total) * dtHrThe shortfall against expectation is accumulated as lost energy, which the dashboard turns into money to justify cleaning or repair.
if(c && others/c>1 && p[i] < 0.7f*(others/c)) lag=iPer-string comparison flags a string well below its siblings — a localised fault or shadow, identified without any weather model.
else if (pr < 0.7f && irr>200) diag = "array underperforming"A low performance ratio in decent sun flags whole-array underperformance (soiling, derating), distinct from a single-string problem.

Configuration & Calibration

Configuration steps

  • Set the rated power, temperature coefficient, and irradiance-reference calibration.
  • Configure per-string sensing and the lagging-string threshold.
  • Set underperformance/alert thresholds and the tariff for lost-energy costing.
  • Configure logging/trending and the dashboard.

Calibration procedure

An uncalibrated sensor produces confident, precise, wrong numbers. Do this once per physical unit and record the constants.

  1. Irradiance reference

    Calibrate the irradiance sensor/reference cell against a known reference in the panels' plane so expected output is accurate.

  2. Per-string sensing

    Verify current/voltage per string against a reference and confirm identical strings read alike in clear sun.

  3. Baseline PR

    Establish the array's healthy performance ratio on clean, clear days as the reference for detecting decline.

Network Architecture & Connectivity

Solar Rooftop Monitor — network topologyPath taken by telemetry from field node to end user. Edge nodesGatewayCloudClientsSolar monitorESP32Stringsper-string sensingWi-Fi 2.4 GHzRouterto serverHTTP/MQTTInfluxDB + GrafanaPR + generationDashboardPR/string trendsPhoneunderperf alerts
Solar Rooftop Monitor — network topology

Communication protocol

Generation, performance ratio, per-string data and lost-energy publish on a slow cadence; underperformance and lagging-string alerts publish on detection.

Topic / endpointDirectionPayload
solar/1/perfnode → dashboardgeneration, PR, per-string, irradiance/temp, lost energy
solar/1/alertnode → ownerunderperformance / lagging string
solar/1/statusnode → ownersensor/link health

Message contract between the device and the broker.

Cloud platform configuration

A dashboard trends performance ratio and per-string generation, quantifies lost energy and cost, and verifies cleaning/repairs; alerts drive O&M.

Dashboard setup

Generation and PR trends, per-string comparison, irradiance/temperature, and lost-energy/cost with cleaning/repair markers.

Mobile app integration

Alerts on abnormal underperformance and lagging strings; cleaning-benefit summaries.

Security considerations

  • Authenticate nodes; secure the energy data.
  • Keep DC-side sensing isolated and safe.
  • Alert on monitor silence.

Testing Procedure & Expected Output

Test from the bottom up. Confirm power, then each sensor in isolation, then the integrated loop — the first failing step tells you exactly where to look.

TestWhat you should see
Clear day, clean panelsPerformance ratio at its healthy value; strings match
Shade one stringThat string lags; lagging-string diagnosis
Soil the array over time (or simulate)PR gradually declines with no rain — soiling signature
Clean and re-measurePR jumps back; recovered energy quantified
Simulate a string faultSudden drop; string localised
Hot dayTemperature correction keeps PR fair (not a false underperformance)

Bench-test checklist. If a row fails, stop and fix it before moving on.

Expected output

The dashboard shows generation, performance ratio, per-string comparison, irradiance/temperature, and lost-energy/cost, with alerts for underperformance and lagging strings.

jsonsolar-perf.json
{
  "total_W": 2180,
  "pr": 0.74,
  "irr": 920,
  "tCell": 52.0,
  "lag": 1,
  "lost_Wh": 3400,
  "diag": "string lagging (fault/shade)"
}

A performance ratio of 0.74 with string 1 lagging points to a localised problem on that string; the accumulated lost energy (3.4 kWh) quantifies what it is costing — turning silent underperformance into an actionable, costed fault.

A Grafana time-series dashboard
Per-string comparison localises faults and shading, and lost-energy figures justify cleaning and repairs. Photograph sourced from Wikimedia Commons — Grafana dashboard.png. Reused under the licence stated on that page; please check it before republishing.

Troubleshooting: Common Errors & Fixes

Can't tell good output from bad

Likely cause. No expectation reference

Fix. Add irradiance + temperature sensing and compute performance ratio

Whole-array PR low on hot days

Likely cause. No temperature correction

Fix. Apply the temperature coefficient with panel temperature

Fault not localised

Likely cause. Only whole-array measurement

Fix. Measure per string and compare; a lagging string localises the fault

Gradual decline mistaken for a fault

Likely cause. Not distinguishing soiling from faults

Fix. Read the pattern — gradual/no-rain = soiling (clean and verify); step = fault

Safety concern on DC side

Likely cause. Unrated/non-isolated PV sensing

Fix. Use isolated, rated sensing; qualified installer for DC-side work

The sketch will not upload — "Failed to connect" or "avrdude: stk500_recv()"

Likely cause. The bootloader is not being reached: wrong port, wrong board, a serial monitor holding the port open, or a USB cable that only carries power.

Fix. Close every serial monitor, confirm Tools → Board and Port, and swap to a known data-capable USB cable. On an ESP32 hold BOOT while the IDE prints "Connecting…", then release. If a peripheral is wired to the UART pins (GPIO 1/3 on ESP32, D0/D1 on Uno) unplug it — it fights the programmer.

The board resets in a loop, or the serial monitor prints "Brownout detector was triggered"

Likely cause. The supply cannot deliver peak current. Wi-Fi transmit bursts, relay coils and servos all pull far more than their average draw.

Fix. Power peripherals from a separate regulated supply with a common ground rather than from the board 5 V pin. Add a 470–1000 µF electrolytic capacitor across the supply near the load, and use a real power adapter rather than a laptop USB port.

Serial monitor shows garbage characters

Likely cause. Baud rate mismatch between Serial.begin() and the monitor, or a floating/shared UART line.

Fix. Set the monitor to 115200 to match the sketch. If it still garbles, the crystal or the USB bridge is being confused by noise — shorten the cable and keep motor wiring away from the USB lead.

An I²C device is not detected

Likely cause. Wrong address, missing pull-ups, swapped SDA/SCL, or a bus too long for the pull-up value.

Fix. Run an I²C scanner sketch first — it should print the device address. Most breakout boards include 4.7 kΩ pull-ups, but if you have chained four of them the parallel resistance is too low; remove the pull-ups from all but one board. Keep the bus under 30 cm at 100 kHz.

Wi-Fi connects but MQTT never does (state -2)

Likely cause. Wrong broker address or port, a firewall in the way, or the broker requiring credentials the sketch is not sending.

Fix. Test from a laptop on the same network first: mosquitto_sub -h <broker> -t "#" -v. If that works, the problem is on the device — check the IP literal, port 1883 (or 8883 for TLS), and that client.setServer() runs before connect(). PubSubClient state codes are documented in its header.

Readings arrive for a while and then stop

Likely cause. The Wi-Fi or MQTT session dropped and the sketch never reconnects, or the broker dropped the client on keep-alive timeout.

Fix. Never assume the link stays up. Check WiFi.status() and client.connected() at the top of every loop and reconnect with exponential backoff. Add a watchdog so a wedged network stack reboots the device instead of going silent.

Performance Optimisation

  • Sample at a modest rate; PR and string comparison need conditions, not high speed.
  • Compute PR with temperature correction for fair comparison across days.
  • Trend PR and per-string ratios to catch decline and localise faults.
  • Quantify lost energy so O&M is justified and verified.
  • Replace every delay() with a millis() comparison — blocking delays are the single most common cause of dropped readings.
  • Sample sensors on a fixed cadence and publish on a slower one; you almost never need to transmit at the sampling rate.
  • Move networking into its own FreeRTOS task so a slow DNS lookup cannot stall the control loop.
  • Use uint8_t / uint16_t where the range allows; on an 8-bit AVR a 32-bit add costs four times as much.
  • Batch several samples into one MQTT publish. Radio time, not CPU time, dominates the energy budget.
  • Set the MQTT keep-alive to a value that matches your reporting interval so the broker does not churn reconnections.
  • For battery builds use deep sleep between samples: an ESP32 drops from ~160 mA awake to about 10 µA asleep, which is the difference between days and months of runtime.

Safety Precautions

  • PV arrays produce dangerous DC voltage in any light and cannot simply be switched off — use isolated, rated sensing and qualified installers for DC-side work.
  • Keep low-voltage electronics isolated from the PV DC side.
  • Accurate performance ratio needs a decent irradiance/temperature reference; label estimates where the reference is rough.
  • Follow rooftop and electrical safety for installation and cleaning.
  • Wear eye protection when soldering or cutting, and solder in a ventilated space — rosin flux fumes are a respiratory irritant.
  • Power the circuit through a bench supply with a current limit while you are testing. A 300 mA limit turns a wiring mistake into a beep instead of a dead board.
  • Disconnect power before changing any wiring. Hot-plugging a sensor onto a live bus is the fastest way to lose a controller.

Maintenance

  • Verify irradiance-reference calibration and per-string sensing periodically.
  • Act on soiling/fault alerts; clean/repair and confirm PR recovery.
  • Re-baseline PR after any array change.
  • Keep DC-side connections inspected and safe.
  • Re-check every screw terminal and header after the first week — thermal cycling loosens connections that felt tight on day one.
  • Rotate the microSD card annually and keep an image of the working system. Cards used as loggers wear out silently.
  • Keep the broker and dashboard containers patched, and rotate device credentials at least once a year.
  • Recalibrate at the interval given in the calibration section, and keep the constants in a text file next to the firmware — not only in flash.
  • Keep a short logbook of firmware versions and what changed. Six months later you will not remember why that constant is 1.083.

Future Improvements & Upgrades

A working v1 is a platform, not a finish line. These are the upgrades that add the most capability for the least rework.

  • Add per-panel monitoring for finer localisation.
  • Add I-V curve tracing for deeper fault diagnosis.
  • Fuse a weather/forecast feed to predict expected generation.
  • Estimate degradation rate over years for warranty/finance.
  • Design a proper PCB. Once the breadboard version has run for a month, moving to a two-layer board removes the intermittent-contact failures that dominate prototype faults.
  • Add over-the-air firmware updates so you never have to physically reach a deployed node again.
  • Add persistent local storage (microSD or the on-chip flash) so a network outage does not create a hole in your data.
  • Move configuration out of the source: a captive-portal setup page or a JSON config file makes the build reusable without a recompile.
  • Add a battery and solar option so the unit survives a power cut and can be sited away from a socket.
  • Write a small test harness that feeds synthetic sensor values through the decision logic, so you can validate thresholds without physically triggering the event.

Frequently Asked Questions

Why not just measure how many kWh it makes?

Because a kWh figure is meaningless without knowing the available sun. Measuring against expectation (irradiance + temperature) gives the performance ratio, which tells you whether the array is healthy regardless of the weather.

How does it find which string has a problem?

By comparing strings that should behave identically. They share the same weather, so a string producing well below its siblings is a localised fault or shadow — no model needed, and the problem is pinpointed.

How does it tell soiling from a fault?

By the pattern. Soiling is a gradual decline over weeks with no rain that a clean reverses; a fault is a sudden step down. Shading recurs at the same time each day. The shape of the loss suggests the cause.

Is it safe to install myself?

PV arrays carry dangerous DC voltage whenever there is light and cannot simply be turned off. DC-side sensing must be isolated and rated, and is best done or verified by a qualified installer.

How does it pay for itself?

By quantifying lost energy. Soiling and faults often cost more than a clean or a repair, but only measurement tells you when — and the same measurement verifies the fix restored the generation.

References & Learning Resources

These are the primary sources worth reading in full. Manufacturer datasheets always outrank forum posts when the two disagree.

  1. Photovoltaic performance ratioReference
  2. PV soiling and cleaningReference
  3. PV temperature coefficientReference
  4. PV DC safety (arc flash / live arrays)Reference
  5. Solar monitoring and fault detectionReference