

ESP32 Development Board Expansion Board Compatible with ESP32 WiFi Bluetooth module NodeMCU-32S Lua 30Pin Expansion Board
https://a.aliexpress.com/_Ev7LEk8
MAX485 Module RS-485 TTL Turn RS485 MAX485CSA Converter Module For Arduino Microcontroller MCU Development Accessories
https://a.aliexpress.com/_EI1Gy4c
But now using this 3.3V RS485 – MAX485 Module RS-485 TTL
Still developing the HTML, but functional, getting live data from the BougeRV BJ2440N:-
ESP32 Dev Module

ESP32 Dev Module and RS485 module (or you can use RS3486 3.3v unit)

Turns out this is a mirror of the actual wiring diagram in my mind: the RJ45 crimp we number 12345678 shows 87654321 in the picture.
Working details below. (hours to find this info and then asking and getting some help from BougeRV support to confirm the found field)
Modbus RTU settings:
9600 baud, 8 data bits, no parity, 1 stop bit (8N1).
Pin 8 (brown) +5V, pin 7 (brown/white) Data+, pin 6 (green) Data -, pin 5 (blue/white) GND
Convert RS-485 to 3.3V TTL using a 5V converter; connect the 1st end of the 10K resistor and 15k resistor on one end (to protect against overvoltage) to pin GPIO16 (D16 RX2) on the ESP32;
Connect the other end of the 10k resistor to the TTL converter board; and connect the 2nd end of the 15k resistor to GND.
RS485 module pinouts
DI = TX2 D17 GPIO17
DE and RE to Pin 27 (GPIO27)
R0 = 10k resistor pin D16 GPIO16 (RX2) 15K resistor to GND (giving output 3v)
Vcc = Vin on ESP32
GND to GND everywhere, pin 5 (blue/white) RJ45 crimp
A to pin7 (brown/white) RJ45 crimp (in RJ45 colours)
B to Pin 6 (Green) RJ45 Crimp (in RJ45 colours)
My Sketch at this point was ver 5.4, 23/03/2026
BougeRV BJ2440N RS-485 / Modbus Reverse Engineering Guide (2026)
Introduction
After several months of testing, register scanning, firmware development, and Bluetooth app cross-referencing, the majority of useful BougeRV BJ2440N telemetry registers have now been identified and verified. This page documents the wiring, Modbus settings, confirmed registers, and a working ESP32 implementation.
Hardware Connection
RJ45: Pin 7=A(D+), Pin 6=B(D-), Pin 5=GND, Pin 8=+5V (unused). Use a 3.3V RS485 module,
connect grounds, and use 120Ω termination at the end of the bus.
Modbus Settings
Protocol: Modbus RTU, Baud: 9600, 8N1, Slave ID: 1, Function Code: 0x03 Holding Registers.
OTA (Over-The-Air) updates added, allowing firmware upgrades without physically removing the ESP32 from the shed.
I hope this helps people skip the pain I went through. MODBUS info found through extensive testing and compared with the Bluetooth app.
Confirmed Registers
| Register | Meaning |
|---|---|
| 0x100 | Battery SOC |
| 0x101 | Battery Voltage |
| 0x102 | Charging Current |
| 0x103 | Temperatures |
| 0x104 | Load Voltage |
| 0x105 | Live Load Current |
| 0x106 | Load Power |
| 0x107 | PV Voltage |
| 0x108 | PV Current |
| 0x109 | Charging Power |
| 0x10B | Battery Min Voltage Today |
| 0x10C | Battery Max Voltage Today |
| 0x10D | Max Charge Current Today |
| 0x10E | Max Discharge Current Today |
| 0x10F | Max Charge Power Today |
| 0x113 | PV Generation Today |
| 0x114 | Load Usage Today |
Important Discovery
Older firmware relied on 0x0C and 0x0107 together. Current testing confirms 0x107 is the correct PV voltage source and matches the Bluetooth app day and night.
SOC Warning
0x100 should be treated as a controller estimate. Testing against a BASE50 BMS showed 100%
controller SOC while the BMS reported 95% during active charging, indicating a voltage-based
estimate rather than coulomb counting.
Project Evolution
The ESP32 project now includes OTA updates, LittleFS storage, daily energy logging, web
dashboard, register discovery tools, NTP synchronisation and Cloudflare Tunnel remote access.
Example HTML early versions


later update

next update showing night after lights have finished.


| Register | Description |
|---|---|
| 0x10B | Today’s minimum battery voltage |
| 0x10C | Today’s maximum battery voltage |
| 0x10D | Today’s maximum charging current |
| 0x10E | Today’s maximum discharging current |
| 0x10F | Today’s maximum charging power |
ESP32 Project Evolution
The project started as a simple serial Modbus monitor and has since evolved into:
- Live web dashboard
- Daily energy logging
- Historical reporting
- Register discovery tools
- OTA firmware updates
- Cloudflare Tunnel remote access
- LittleFS storage
- Automatic NTP synchronisation
The current firmware runs continuously on an ESP32 installed in the shed and can be updated remotely without removing the hardware.
The latest code after 80+ revisions – thanks to Claude, Copilot, Grok, Gemini and ChatGPT for assisting with development and testing ideas.
Lessons Learned (The Hard Way)
- Don’t blind-trust AI “Clean-Ups”: Models love to silently drop working debug blocks, structures, or timing delays to save visual space. If you don’t watch them like a hawk, they will truncate your code and leave you guessing what broke.
- OTA is a luxury until it isn’t: A multi-second Modbus scanning loop on a single-threaded ESP web server will completely stall
ArduinoOTA.handle(). One bad timeout, and you are walking out to the shed with a laptop and a physical USB cable to recover a bricked node. - Lock the bus down: Modbus commands cannot overlap. Without the explicit
busBusySafety locks guarding the background polling thread from the HTTP endpoint handlers, concurrent requests will collide and trigger endless timeout errors (Error 226). - The pitch-black isolation test: You cannot find solar controller registers by guessing during a bright sunny day when every value (PV volts, battery current, load power) is fluctuating simultaneously. Wait until darkness, toggle exactly one variable (the load), and look for the only registers that react.
- Lessons Learned: Be careful of AI; it sometimes deletes your working blocks to save space without telling you. Lots of fetch ESP32 from the shed because the OTA sends a dud sketch, so to upload via USB again.
Example Sketch working 01/07/2026
Note the Partition table needs to be –

/******************************************************* * SolarRV ULTRA+ * Version: v17.06.02 (Daily peak charging + SOC caveat) * Date: 01/07/2026 * * Changes vs v17.06.02: * - NEW: 0x10d (today's max charging current) and 0x10f (today's max * charging power) added. Both are already within or just beyond the * existing Modbus block, so the primary read is widened from 15 to * 16 registers (0x100-0x10F) — still a single transaction, no * extra Modbus overhead. Both are DATASHEET status (SRNE doc * defines them clearly; not yet independently bench-verified by us). * They appear in the max-registers comparison tier on the dashboard, * making it easy to see today's peak charging performance at a glance. * - SOC ring sublabel updated to "controller estimate (voltage-based)" * with a tooltip-style note. Reason: BASE50 BMS cross-reference at * 07:07 01/07/26 showed controller reporting 100% SOC while BMS * reported 95% with CMOS:ON (charge FET open, still actively * charging). This proves the controller's SOC is a voltage-curve * lookup, not coulomb counting — it over-reports near the top of * charge. The BMS is the authoritative SOC source for this battery. * - No other logic, routes, OTA, WiFi, or LittleFS code changed. * * --- Previous changelog (v17.06.02) --- * Cross-reference confirmations 01/07/2026: 0x101, 0x102, 0x103, * 0x105, 0x10e, 0x109, 0x114 all confirmed via simultaneous BT-app * + dashboard + /debug capture. 0x10e confirmed as daily max NOT live. * Night-time PV voltage bug confirmed fixed. * * --- Previous changelog (v17.06.00) --- * Ring gauges + 0x105/0x10e clarity + defensive reads + 0x113/0x114. * * --- Previous changelog (v17.05.00) --- * MAJOR: rebuilt readController() from SRNE datasheet. Fixed * night-time stuck-PV-voltage bug. * *******************************************************/#include <WiFi.h>#include <WebServer.h>#include <ArduinoOTA.h>#include <time.h>#include <ModbusMaster.h>#include <Update.h>#include <LittleFS.h>// ==================== PINS / BUS ====================#define RS485_RX 16#define RS485_TX 17#define RS485_EN 4ModbusMaster node;void preTransmission() { digitalWrite(RS485_EN, HIGH); delayMicroseconds(100); }void postTransmission() { delayMicroseconds(100); digitalWrite(RS485_EN, LOW); }// ==================== CONFIG ====================const char* ssid = "WIFI-SSID"; // Change thisconst char* password = "WIFIPassword"; // Change thisconst char* ntpServer = "uk.pool.ntp.org"; const char* otaUser = "upload"; // Change this const char* otaPass = "changethepassword987"; // Change this const unsigned long pollInterval = 30000;const unsigned long ntpInterval = 3600000;const unsigned long otaTimeout = 600000;// ==================== RING SCALING (visual only) ====================// Only affects how "full" the ring gauges look, never the number shown.// Adjust once you know your system's real maximums.const float RING_MAX_PV_A = 20.0f;const float RING_MAX_LOAD_A = 20.0f;const float RING_MAX_CHG_A = 20.0f;// ==================== GLOBALS ====================float pvVolts = 0.0f; // CONFIRMED 0x107float solarCurrent = 0.0f; // CONFIRMED 0x108float solarPower = 0.0f; // DATASHEET 0x109 charging power (W)float dailyWh = 0.0f; // local accumulator (kept as fallback)float realPanelVoltage = 0.0f; // CONFIRMED 0x107 (alias, kept for /debug display)float realLoadVoltage = 0.0f; // CONFIRMED 0x104float realLoadCurrent = 0.0f; // 0x10e today's max discharging current - NOT liveint batterySocPct = 0; // CONFIRMED 0x100 (BT match 01/07/26)float batteryVoltsLive = 0.0f; // CONFIRMED 0x101 (BT match 13.40V = 13.4V, 01/07/26)float chargingCurrent = 0.0f; // CONFIRMED 0x102 (BT match 1.02A = 1.01A, 01/07/26; // also correctly reads 0 during discharge - BASE50 test)int controllerTempC = 0; // CONFIRMED 0x103 high byte (BT exact match 22°C, 01/07/26)int batteryTempC = 0; // CONFIRMED 0x103 low byte (BT exact match 19°C, 01/07/26)float loadCurrentLive = 0.0f; // CONFIRMED 0x105 live load current (read 0.00A with // load off at 07:01 01/07/26, confirms live behaviour)int loadPowerLive = 0; // DATASHEET 0x106float batteryVoltsMaxToday = 0.0f; // DATASHEET 0x10c today's max battery voltagefloat loadCurrentMaxToday = 0.0f; // CONFIRMED 0x10e today's max discharging current // (NOT live - showed 1.04A when live load was 0.00A; // BT history max discharge = 1.01A. Resolved 01/07/26)float todayMaxChgCurrent = 0.0f; // DATASHEET 0x10d today's max charging current ÷100float todayMaxChgPower = 0.0f; // DATASHEET 0x10f today's max charging power (W)// Peak tracking (software-side, reset at midnight with dailyWh)// Records the time-of-day when each daily peak was first reached.// Tells you what time your flat-roof panel actually peaks in practice.float peakPvCurrentVal = 0.0f; // highest 0x108 PV current seen todayString peakPvCurrentTime = "--:--"; // HH:MM when that peak was setfloat peakPvVoltageVal = 0.0f; // highest 0x107 PV voltage seen todayString peakPvVoltageTime = "--:--"; // HH:MM when that peak was setfloat peakChgCurrentVal = 0.0f; // highest 0x10d max charging current seen todayString peakChgCurrentTime= "--:--"; // HH:MM when 0x10d last increasedfloat todayPvWh = 0.0f; // CONFIRMED 0x113 today's PV generation Wh // (reads 0 early morning - controller resets at midnight // and accumulates; showed 81Wh by 23:31 on 30/06/26)float todayLoadWh = 0.0f; // CONFIRMED 0x114 today's load consumption Wh // (26Wh dashboard = 26Wh BT history, 01/07/26)// Candidates - meaning explained by datasheet, some bench-confirmedfloat candBatteryCurrent = 0.0f; // 0x102 (alias of chargingCurrent, CONFIRMED)float candPvCurrent = 0.0f; // 0x108 (alias of solarCurrent, CONFIRMED)float candBatteryVoltage = 0.0f; // 0x10b today's min battery voltagebool lastRegReadOk = false;bool littleFsReady = false;volatile bool busBusy = false;unsigned long lastPoll = 0;unsigned long lastNTP = 0;unsigned long lastSuccessfulRead = 0;bool otaInProgress = false;unsigned long otaPauseStart = 0;WebServer server(80);// ==================== REGISTER SNAPSHOT STRUCT ====================struct RegisterData { // CONFIRMED registers (bench-tested or cross-referenced with BT app) float pvVoltage = 0.0f; // 0x107 - confirmed multiple times float pvCurrent = 0.0f; // 0x108 - confirmed (BT match 0.6A = 0.57A) float loadVoltage = 0.0f; // 0x104 - confirmed load on/off bench test // CONFIRMED via BT-app cross-reference 01/07/2026 float pvPower = 0.0f; // 0x109 charging power (14W = 14W BT) float batteryVoltage = 0.0f; // 0x101 live (13.40V = 13.4V BT) int batterySocPct = 0; // 0x100 (100% matches BT) int controllerTempC = 0; // 0x103 high (22°C = 22°C BT exact) int batteryTempC = 0; // 0x103 low (19°C = 19°C BT exact) float loadCurrentLive = 0.0f; // 0x105 live (0.00A with load off confirmed) int loadPowerLive = 0; // 0x106 DATASHEET only float batteryVoltsMaxToday = 0.0f; // 0x10c DATASHEET only float loadCurrent = 0.0f; // 0x10e today's max discharge (CONFIRMED as max, NOT live) float todayMaxChgCurrent = 0.0f; // 0x10d today's max charging current (DATASHEET) float todayMaxChgPower = 0.0f; // 0x10f today's max charging power W (DATASHEET) // Software peak tracking (reset at midnight) float peakPvCurrentVal = 0.0f; String peakPvCurrentTime = "--:--"; float peakPvVoltageVal = 0.0f; String peakPvVoltageTime = "--:--"; float peakChgCurrentVal = 0.0f; String peakChgCurrentTime = "--:--"; float todayPvWh = 0.0f; // 0x113 CONFIRMED (81Wh by end of day 30/06) float todayLoadWh = 0.0f; // 0x114 CONFIRMED (26Wh = 26Wh BT history) // Candidates (confirmed meaning, kept for continuity) float candBatteryCurrent = 0.0f; // 0x102 charging current (CONFIRMED) float candPvCurrent = 0.0f; // 0x108 (CONFIRMED, alias) float candBatteryVoltage = 0.0f; // 0x10b today's min battery voltage (DATASHEET) unsigned long lastUpdate = 0;};RegisterData regs;// ==================== HELPERS ====================String getDateTime() { struct tm timeinfo; if (!getLocalTime(&timeinfo, 1000)) return "Time not synced"; char buffer[32]; strftime(buffer, sizeof(buffer), "%d/%m/%Y %H:%M:%S", &timeinfo); return String(buffer);}String getWifiStatus() { int rssi = WiFi.RSSI(); String strength = (rssi > -50) ? "Strong" : (rssi > -70) ? "Medium" : "Weak"; return WiFi.SSID() + " | " + strength + " (" + String(rssi) + " dBm)";}// ==================== RING GAUGE (v17.06.00) ====================// Renders a donut-ring gauge + centred value + label as an HTML card.// pct is 0-100. Circumference 94.0 is used (true value for r=15 is// 94.25 - difference is <0.3%, imperceptible at this display size).// Both <circle> tags properly closed with </circle> to satisfy// mobile WebKit renderers.String renderRing(float pct, const String& bigText, const String& label, const String& sublabel, const String& color) { if (pct < 0.0f) pct = 0.0f; if (pct > 100.0f) pct = 100.0f; float offset = 94.0f - (94.0f * pct / 100.0f); String s = "<div class='card' style='text-align:center;'>"; s += "<div class='rlbl'>" + label + "</div>"; s += "<div style='position:relative;width:110px;height:110px;margin:0 auto;'>"; s += "<svg width='110' height='110' viewBox='0 0 42 42'>"; s += "<circle cx='21' cy='21' r='15' fill='none' stroke='#334155' stroke-width='7'></circle>"; s += "<circle cx='21' cy='21' r='15' fill='none' stroke='" + color + "' stroke-width='7' stroke-dasharray='94' stroke-dashoffset='" + String(offset, 1) + "' stroke-linecap='round' transform='rotate(-90 21 21)'></circle>"; s += "</svg>"; s += "<div style='position:absolute;top:0;left:0;width:110px;height:110px;" "display:flex;align-items:center;justify-content:center;" "font-size:1.35em;font-weight:800;color:" + color + ";'>" + bigText + "</div>"; s += "</div>"; if (sublabel.length() > 0) s += "<div class='rsub'>" + sublabel + "</div>"; s += "</div>"; return s;}// ==================== DAILY ENERGY LOG ====================#define ENERGY_LOG_PATH "/energy_log.csv"#define ENERGY_LOG_MAX_DAYS 30String formatLogDate(struct tm* t) { char buf[16]; strftime(buf, sizeof(buf), "%d/%m/%Y", t); return String(buf);}long dateToOrdinal(const String& dmy) { if (dmy.length() < 10) return 0; int d = dmy.substring(0, 2).toInt(); int m = dmy.substring(3, 5).toInt(); int y = dmy.substring(6, 10).toInt(); struct tm t = {0}; t.tm_mday = d; t.tm_mon = m - 1; t.tm_year = y - 1900; t.tm_hour = 12; time_t tt = mktime(&t); return (long)(tt / 86400L);}void appendEnergyLog(const String& dateStr, float wh) { if (!littleFsReady) return; long todayOrdinal = dateToOrdinal(dateStr); String rows[ENERGY_LOG_MAX_DAYS]; int rowCount = 0; if (LittleFS.exists(ENERGY_LOG_PATH)) { File f = LittleFS.open(ENERGY_LOG_PATH, "r"); if (f) { while (f.available() && rowCount < ENERGY_LOG_MAX_DAYS) { String line = f.readStringUntil('\n'); line.trim(); if (line.length() < 11) continue; long age = todayOrdinal - dateToOrdinal(line); if (age >= 0 && age < ENERGY_LOG_MAX_DAYS) rows[rowCount++] = line; } f.close(); } } File f = LittleFS.open(ENERGY_LOG_PATH, "w"); if (!f) { Serial.println("Energy log: write failed"); return; } for (int i = 0; i < rowCount; i++) f.println(rows[i]); f.println(dateStr + "," + String(wh, 1)); f.close();}void checkDailyReset() { time_t now = time(nullptr); struct tm* t = localtime(&now); static int lastDay = -1; if (t && t->tm_year > 120) { int todayMday = t->tm_mday; if (todayMday != lastDay) { if (lastDay != -1 && dailyWh > 0.0f) { time_t yesterdayEpoch = now - 86400L; struct tm* yt_tm = localtime(&yesterdayEpoch); appendEnergyLog(formatLogDate(yt_tm), dailyWh); } dailyWh = 0; lastDay = todayMday; // Reset software peak trackers so each day starts fresh peakPvVoltageVal = 0.0f; peakPvVoltageTime = "--:--"; peakPvCurrentVal = 0.0f; peakPvCurrentTime = "--:--"; peakChgCurrentVal = 0.0f; peakChgCurrentTime = "--:--"; } }}// ==================== REGISTER READ (v17.06.00) ====================// Single read 0x100-0x10E (15 registers, proven safe width) plus a// separate second read for 0x113-0x114 (daily energy totals). Two// reads rather than widening to 21 registers: Grok correctly flagged// that some SRNE variants silently fail on reads wider than ~16// registers. Two transactions avoids that risk entirely.void readController() { if (otaInProgress) return; unsigned long now = millis(); busBusy = true; delay(20); bool readOk = false; // v17.06.02: widened from 15 to 16 registers (0x100-0x10F) to pick // up 0x10f (today's max charging power) at offset 15. Still a // single transaction, well within the safe block-size limit. if (node.readHoldingRegisters(0x100, 16) == node.ku8MBSuccess) { // 0x100: Battery SOC % (DATASHEET) batterySocPct = node.getResponseBuffer(0); // 0x101: Battery voltage live (DATASHEET) batteryVoltsLive = node.getResponseBuffer(1) / 10.0f; // 0x102: Charging current to battery (CONFIRMED - zero during // discharge is correct behaviour, not a failed test) chargingCurrent = node.getResponseBuffer(2) / 100.0f; candBatteryCurrent = chargingCurrent; // 0x103: Controller temp (high byte) + Battery temp (low byte) // SRNE sign-bit format: b7=sign, b0-b6=magnitude { uint16_t raw = node.getResponseBuffer(3); uint8_t ctrlByte = (raw >> 8) & 0xFF; uint8_t battByte = raw & 0xFF; controllerTempC = (ctrlByte & 0x80) ? -(ctrlByte & 0x7F) : (ctrlByte & 0x7F); batteryTempC = (battByte & 0x80) ? -(battByte & 0x7F) : (battByte & 0x7F); } // 0x104: Load voltage (CONFIRMED - bench-tested via load on/off) realLoadVoltage = node.getResponseBuffer(4) / 10.0f; // 0x105: Load current LIVE (DATASHEET - now the hero-card source; // see 0x10e comment below for full resolution) loadCurrentLive = node.getResponseBuffer(5) / 100.0f; // 0x106: Load power direct (DATASHEET) loadPowerLive = node.getResponseBuffer(6); // 0x107: PV voltage (CONFIRMED - sole source, no fallback) pvVolts = node.getResponseBuffer(7) / 10.0f; realPanelVoltage = pvVolts; // 0x108: PV current (CONFIRMED - matched BT app twice at different // nonzero values) candPvCurrent = node.getResponseBuffer(8) / 100.0f; solarCurrent = candPvCurrent; // 0x109: Charging power (DATASHEET - replaces dead legacy calc) solarPower = node.getResponseBuffer(9); // 0x10b: Today's min battery voltage (DATASHEET) candBatteryVoltage = node.getResponseBuffer(11) / 10.0f; // 0x10c: Today's max battery voltage (DATASHEET) batteryVoltsMaxToday = node.getResponseBuffer(12) / 10.0f; // 0x10e: Today's MAX discharging current (CONFIRMED as max, NOT // live - v17.06.02: showed 1.04A while live 0x105 read 0.00A // with load off. BT history max discharge = 1.01A.) realLoadCurrent = node.getResponseBuffer(14) / 100.0f; loadCurrentMaxToday = realLoadCurrent; // 0x10d: Today's max charging current (DATASHEET, offset 13). // Useful for seeing the daily peak charging performance — // e.g. 1.07A at 07:01 01/07/26, likely climbs through midday. todayMaxChgCurrent = node.getResponseBuffer(13) / 100.0f; // 0x10f: Today's max charging power W (DATASHEET, offset 15). // Block widened to 16 registers in v17.06.02 to reach this. todayMaxChgPower = node.getResponseBuffer(15); readOk = true; lastSuccessfulRead = now; } // Second transaction: daily energy totals. Separate read rather than // widening the block above, to avoid width-limit failures on some // SRNE variants. Failure here is non-fatal: dashboard falls back to // the local dailyWh accumulator. delay(20); if (node.readHoldingRegisters(0x113, 2) == node.ku8MBSuccess) { todayPvWh = node.getResponseBuffer(0); // 0x113 today's PV gen (Wh) todayLoadWh = node.getResponseBuffer(1); // 0x114 today's load consumption (Wh) } lastRegReadOk = readOk; busBusy = false; // ---- Software peak tracking (v17.06.02) ---- // Runs after every successful poll. Records the HH:MM time whenever // a new daily peak is set for PV voltage, PV current, or charging // current. Resets are handled in checkDailyReset() at midnight. // Uses the ESP32's NTP-synced local time, so UK BST is correct. // This tells you empirically what time your flat-roof panel peaks. if (readOk) { struct tm timeinfo; if (getLocalTime(&timeinfo, 200)) { char timeBuf[6]; strftime(timeBuf, sizeof(timeBuf), "%H:%M", &timeinfo); String hhmm = String(timeBuf); if (pvVolts > peakPvVoltageVal) { peakPvVoltageVal = pvVolts; peakPvVoltageTime = hhmm; } if (solarCurrent > peakPvCurrentVal) { peakPvCurrentVal = solarCurrent; peakPvCurrentTime = hhmm; } if (todayMaxChgCurrent > peakChgCurrentVal) { peakChgCurrentVal = todayMaxChgCurrent; peakChgCurrentTime = hhmm; } } } // Local daily energy accumulation (unchanged - kept as fallback) static unsigned long lastEnergy = 0; if (lastEnergy > 0) { float hours = (now - lastEnergy) / 3600000.0f; if (hours < 1.0f && solarPower > 1.0f) dailyWh += solarPower * hours; } lastEnergy = now;}void readRegisters() { regs.pvVoltage = pvVolts; regs.pvCurrent = solarCurrent; regs.pvPower = solarPower; regs.batteryVoltage = batteryVoltsLive; regs.loadVoltage = realLoadVoltage; regs.loadCurrent = loadCurrentMaxToday; // 0x10e, comparison tier regs.todayMaxChgCurrent = todayMaxChgCurrent; // 0x10d regs.todayMaxChgPower = todayMaxChgPower; // 0x10f regs.peakPvVoltageVal = peakPvVoltageVal; regs.peakPvVoltageTime = peakPvVoltageTime; regs.peakPvCurrentVal = peakPvCurrentVal; regs.peakPvCurrentTime = peakPvCurrentTime; regs.peakChgCurrentVal = peakChgCurrentVal; regs.peakChgCurrentTime = peakChgCurrentTime; regs.lastUpdate = millis(); regs.batterySocPct = batterySocPct; regs.controllerTempC = controllerTempC; regs.batteryTempC = batteryTempC; regs.loadCurrentLive = loadCurrentLive; // 0x105, hero card regs.loadPowerLive = loadPowerLive; regs.batteryVoltsMaxToday = batteryVoltsMaxToday; regs.todayPvWh = todayPvWh; regs.todayLoadWh = todayLoadWh; regs.candBatteryCurrent = candBatteryCurrent; regs.candPvCurrent = candPvCurrent; regs.candBatteryVoltage = candBatteryVoltage;}String renderCandidates() { String s = "<h3>🔍 Unknown / Candidate Registers (Focus Area)</h3>"; s += "<p style='color:#94a3b8;'>Toggle garden lights ON/OFF and watch which rows change.</p>"; if (otaInProgress) { s += "<p style='color:#f59e0b;'>OTA update in progress - register reads paused to keep the upload fast. Try again after it finishes.</p>"; return s; } const uint16_t addrs[] = {0x08, 0x09, 0x1D, 0x1E, 0x1F, 0x20}; const char* notes[] = { "0x08: Possible PV related?", "0x09: Possible PV related? (paired with 0x08)", "0x1D: Possible status / current / temp", "0x1E: Similar scale to known registers", "0x1F: 2048 = 2^11 → likely flag/status", "0x20: Small value → possible state/flag" }; unsigned long waited = 0; while (busBusy && waited < 500) { delay(5); waited += 5; } s += "<table border='1' cellpadding='6'>"; s += "<tr><th>Addr</th><th>Raw</th><th>÷10</th><th>÷100</th><th>÷256</th><th>Notes</th></tr>"; if (busBusy) { s += "<tr><td colspan='6' style='color:red;'>Bus busy - skipped this load, refresh to retry</td></tr>"; s += "</table>"; return s; } for (uint8_t i = 0; i < 6; i++) { delay(20); yield(); uint8_t result = node.readHoldingRegisters(addrs[i], 1); bool ok = (result == node.ku8MBSuccess); uint16_t raw = ok ? node.getResponseBuffer(0) : 0; String rawDisplay = ok ? String(raw) : "<span style='color:#ef4444;'>ERR</span>"; String rawStyle = (ok && raw != 0) ? " style='color:#fde68a; font-weight:bold;'" : ""; s += "<tr><td>0x" + String(addrs[i], HEX) + "</td>"; s += "<td><b" + rawStyle + ">" + rawDisplay + "</b></td>"; s += "<td>" + String(raw / 10.0f, 2) + "</td>"; s += "<td>" + String(raw / 100.0f, 2) + "</td>"; s += "<td>" + String(raw / 256.0f, 2) + "</td>"; s += "<td>" + String(notes[i]) + "</td></tr>"; } s += "</table>"; return s;}// ==================== WIDE SCAN (0x40-0xBF) ====================// Candidates 0x08, 0x09, 0x1D, 0x1E, 0x1F, 0x20 are now confirmed// dead ends - all held perfectly static across load on/off and a// PV current swing from ~0.39A down to 0A. None of them can be// the live PV/load current or power registers we're actually// after, so this scan moves on to fresh territory: 0x40-0x7F and// 0x80-0xBF, on top of the already-covered 0x00-0x3F.// Same speed discipline as renderCandidates(): one bus-busy wait// up front, then reads straight through in chunks (max 16 regs// per transaction, a safe size for most RTU slaves) - no// redundant per-row locking, and skipped entirely during OTA.String renderWideScan(uint16_t startAddr, uint16_t endAddrInclusive, uint8_t chunkSize) { String s = "<h3>Wide Scan (0x" + String(startAddr, HEX) + " - 0x" + String(endAddrInclusive, HEX) + ")</h3>"; if (otaInProgress) { s += "<p style='color:#f59e0b;'>OTA update in progress - scan paused.</p>"; return s; } unsigned long waited = 0; while (busBusy && waited < 500) { delay(5); waited += 5; } s += "<table border='1' cellpadding='5'>"; s += "<tr><th>Address</th><th>Raw</th><th>÷10</th><th>÷100</th><th>÷256</th><th>÷1000</th></tr>"; if (busBusy) { s += "<tr><td colspan='6' style='color:red;'>Bus busy - skipped, refresh to retry</td></tr>"; s += "</table>"; return s; } uint16_t addr = startAddr; while (addr <= endAddrInclusive) { uint8_t count = chunkSize; if (addr + count - 1 > endAddrInclusive) count = endAddrInclusive - addr + 1; delay(20); yield(); uint8_t result = node.readHoldingRegisters(addr, count); if (result != node.ku8MBSuccess) { s += "<tr><td colspan='6' style='color:#f59e0b;'>0x" + String(addr, HEX) + "-0x" + String(addr + count - 1, HEX) + ": read failed (error " + String(result) + ") - likely unmapped/reserved</td></tr>"; } else { for (int i = 0; i < count; i++) { uint16_t raw = node.getResponseBuffer(i); uint16_t a = addr + i; String rawStyle = (raw != 0) ? " style='color:#fde68a;font-weight:bold;'" : ""; s += "<tr><td>0x" + String(a, HEX) + "</td>"; s += "<td><b" + rawStyle + ">" + String(raw) + "</b></td>"; s += "<td>" + String(raw / 10.0f, 2) + "</td>"; s += "<td>" + String(raw / 100.0f, 3) + "</td>"; s += "<td>" + String(raw / 256.0f, 2) + "</td>"; s += "<td>" + String(raw / 1000.0f, 3) + "</td>"; s += "</tr>"; } } addr += count; } s += "</table>"; return s;}// ==================== INPUT REGISTER PROBE (FC 0x04) ====================// Everything read so far has used function code 0x03 (Read Holding// Registers) via node.readHoldingRegisters(). 0x40-0xBF turned out// to just be the device's model string ("BJ2440N") padded with// spaces - confirms the bus/addressing is working correctly, but// also confirms the live PV/load current and power values are NOT// in the holding-register ranges scanned so far.// Many MPPT controllers (this one is very likely a white-labelled// OEM board, same family as several Renogy/EPEVER-style designs)// split their register map across multiple Modbus function codes -// measurements often live in INPUT registers (function code 0x04)// rather than holding registers (0x03), even though both are// addressed the same way. This probe tries the same low addresses// (0x00-0x1F) plus the known-good 0x0107 via readInputRegisters()// instead, as a quick way to check whether FC 0x04 opens up a// completely different, possibly live, set of values.// Same speed/OTA-safety pattern as the other debug sections.String renderInputRegisterProbe() { String s = "<h3>Input Register Probe (Function Code 0x04)</h3>"; s += "<p style='color:#94a3b8;'>Same addresses, different Modbus function code - testing whether live values live here instead of in holding registers.</p>"; if (otaInProgress) { s += "<p style='color:#f59e0b;'>OTA update in progress - probe paused.</p>"; return s; } unsigned long waited = 0; while (busBusy && waited < 500) { delay(5); waited += 5; } if (busBusy) { s += "<p style='color:red;'>Bus busy - skipped, refresh to retry.</p>"; return s; } s += "<table border='1' cellpadding='5'>"; s += "<tr><th>Address</th><th>Raw</th><th>÷10</th><th>÷100</th><th>÷256</th><th>÷1000</th></tr>"; // Block 1: 0x00-0x1F via input registers, chunked at 16 per transaction uint16_t addr = 0x00; const uint16_t endAddr = 0x1F; while (addr <= endAddr) { uint8_t count = 16; if (addr + count - 1 > endAddr) count = endAddr - addr + 1; delay(20); yield(); uint8_t result = node.readInputRegisters(addr, count); if (result != node.ku8MBSuccess) { s += "<tr><td colspan='6' style='color:#f59e0b;'>0x" + String(addr, HEX) + "-0x" + String(addr + count - 1, HEX) + ": FC 0x04 read failed (error " + String(result) + ") - device may not support input registers, or nothing mapped here</td></tr>"; } else { for (int i = 0; i < count; i++) { uint16_t raw = node.getResponseBuffer(i); uint16_t a = addr + i; String rawStyle = (raw != 0) ? " style='color:#86efac;font-weight:bold;'" : ""; s += "<tr><td>0x" + String(a, HEX) + "</td>"; s += "<td><b" + rawStyle + ">" + String(raw) + "</b></td>"; s += "<td>" + String(raw / 10.0f, 2) + "</td>"; s += "<td>" + String(raw / 100.0f, 3) + "</td>"; s += "<td>" + String(raw / 256.0f, 2) + "</td>"; s += "<td>" + String(raw / 1000.0f, 3) + "</td>"; s += "</tr>"; } } addr += count; } // Sanity check: the one address we KNOW is live and correct via // holding registers. If this fails or reads wildly differently // here, that tells us something about whether FC 0x04 is even // supported on this device at all. delay(20); yield(); uint8_t pvResult = node.readInputRegisters(0x0107, 1); if (pvResult == node.ku8MBSuccess) { uint16_t raw = node.getResponseBuffer(0); s += "<tr><td>0x107 (sanity check)</td><td><b style='color:#86efac;'>" + String(raw) + "</b></td><td>" + String(raw / 10.0f, 2) + " (expect ~PV V)</td><td colspan='3'></td></tr>"; } else { s += "<tr><td>0x107 (sanity check)</td><td colspan='5' style='color:#f59e0b;'>FC 0x04 read failed (error " + String(pvResult) + ") at the one address we know works via FC 0x03 - suggests this device may not respond to input register requests at all</td></tr>"; } s += "</table>"; return s;}// ==================== SETUP ====================void setup() { Serial.begin(115200); pinMode(RS485_EN, OUTPUT); if (!LittleFS.begin(true)) { Serial.println("LittleFS mount failed - energy log disabled this boot"); littleFsReady = false; } else { Serial.println("LittleFS mounted OK"); littleFsReady = true; } Serial2.begin(9600, SERIAL_8N1, RS485_RX, RS485_TX); Serial2.setTimeout(150); node.begin(1, Serial2); node.preTransmission(preTransmission); node.postTransmission(postTransmission); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(300); Serial.print("."); } Serial.println("\nWiFi connected: " + WiFi.localIP().toString()); WiFi.setSleep(false); // <-- POWER SAVING STAYS OFF - DO NOT CHANGE ArduinoOTA.setHostname("SolarRV-ULTRA"); ArduinoOTA.begin(); configTzTime("GMT0BST,M3.5.0/1,M10.5.0/2", ntpServer); // ==================== MAIN DASHBOARD ==================== server.on("/", HTTP_GET, []() { readRegisters(); String pvLit = (regs.pvVoltage > 1.0f) ? "lit" : "dim"; String loadLit = (regs.loadCurrentLive > 0.01f) ? "lit" : "dim"; float pvPct = (RING_MAX_PV_A > 0) ? (regs.pvCurrent / RING_MAX_PV_A * 100.0f) : 0; float loadPct = (RING_MAX_LOAD_A > 0) ? (regs.loadCurrentLive / RING_MAX_LOAD_A * 100.0f) : 0; float chgPct = (RING_MAX_CHG_A > 0) ? (regs.candBatteryCurrent / RING_MAX_CHG_A * 100.0f) : 0; // Prefer real register Wh if nonzero, else fall back to local accumulator float displayPvWh = (regs.todayPvWh > 0) ? regs.todayPvWh : dailyWh; bool pvWhFromReg = (regs.todayPvWh > 0); float displayLoadWh = (regs.todayLoadWh > 0) ? regs.todayLoadWh : 0; String html = "<!DOCTYPE html>\n" "<html><head><meta charset='UTF-8'>" "<meta name='viewport' content='width=device-width,initial-scale=1'>" "<meta http-equiv='refresh' content='60'>" "<title>SolarRV ULTRA+ v17.06.02</title>" "<style>" ":root{--bg:#0b1320;--panel:#121d30;--panel2:#0f1726;" "--hairline:#22324a;--text:#e7edf6;--muted:#7c8ba3;" "--amber:#f0b429;--amber-dim:#5c4a1f;}" "*{box-sizing:border-box}" "body{margin:0;font-family:'Segoe UI',Roboto,Arial,sans-serif;" "background:var(--bg);color:var(--text);padding:16px;}" ".wrap{max-width:820px;margin:auto;}" "h1{font-size:1.05em;font-weight:600;margin:0 0 2px;}" ".ts{color:var(--muted);font-size:0.78em;margin:0 0 16px;}" ".flow{display:flex;align-items:center;justify-content:center;gap:6px;" "margin:0 0 18px;padding:12px 10px;background:var(--panel2);" "border-radius:14px;border:1px solid var(--hairline);}" ".node{display:flex;flex-direction:column;align-items:center;gap:3px;min-width:60px;}" ".ic{font-size:1.3em;opacity:.3;}" ".ic.lit{opacity:1;filter:drop-shadow(0 0 5px rgba(240,180,41,.5));}" ".lbl{font-size:0.6em;color:var(--muted);text-transform:uppercase;letter-spacing:.06em;}" ".arrow{color:var(--hairline);font-size:1.1em;}" ".arrow.lit{color:var(--amber);}" ".rings{display:grid;grid-template-columns:repeat(auto-fit,minmax(130px,1fr));gap:10px;margin-bottom:14px;}" ".card{background:var(--panel);border:1px solid var(--hairline);border-radius:12px;padding:12px;}" ".rlbl{color:var(--muted);font-size:0.75em;text-transform:uppercase;letter-spacing:.04em;margin-bottom:4px;}" ".rsub{font-size:0.7em;color:#475569;margin-top:5px;}" ".stats{display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:10px;margin-bottom:14px;}" ".stat .lbl2{color:var(--muted);font-size:0.72em;text-transform:uppercase;letter-spacing:.04em;margin-bottom:4px;}" ".stat .val{font-size:1.45em;font-weight:600;}" ".stat .src{font-size:0.7em;color:#475569;margin-top:4px;}" ".tier{border-radius:12px;padding:12px 14px;margin-bottom:12px;}" ".tier.ds{background:var(--panel2);border:1px solid var(--hairline);}" ".tier.cand{background:var(--panel2);border:1px dashed var(--amber-dim);}" ".tier .th{font-size:0.75em;font-weight:600;text-transform:uppercase;letter-spacing:.04em;margin-bottom:8px;}" ".tier.ds .th{color:#8fb3e0;}" ".tier.cand .th{color:var(--amber);}" ".tier .row{display:flex;justify-content:space-between;font-size:0.9em;" "padding:4px 0;border-top:1px solid var(--hairline);}" ".tier .row:first-of-type{border-top:none;}" ".tier .row b{color:var(--text);font-weight:600;}" ".tier .note{font-size:0.7em;color:var(--muted);margin-top:8px;line-height:1.4;}" "nav{display:flex;justify-content:center;gap:16px;margin:14px 0 4px;font-size:0.85em;}" "nav a{color:var(--amber);text-decoration:none;}" "footer{margin-top:14px;padding-top:10px;border-top:1px solid var(--hairline);" "display:flex;justify-content:space-between;color:var(--muted);font-size:0.7em;flex-wrap:wrap;gap:4px;}" "@media(max-width:480px){.rings{grid-template-columns:1fr 1fr;}}" "</style></head><body><div class='wrap'>" "<h1>🌞 SolarRV ULTRA+ <span style='color:var(--muted);font-weight:400;font-size:0.85em;'>v17.06.02</span></h1>" "<p class='ts'>" + getDateTime() + "</p>" "<div class='flow'>" "<div class='node'><div class='ic " + pvLit + "'>☀️</div><div class='lbl'>PV</div></div>" "<div class='arrow " + pvLit + "'>→</div>" "<div class='node'><div class='ic lit'>🔋</div><div class='lbl'>Battery</div></div>" "<div class='arrow " + loadLit + "'>→</div>" "<div class='node'><div class='ic " + loadLit + "'>💡</div><div class='lbl'>Load</div></div>" "</div>" "<div class='rings'>" + renderRing((float)regs.batterySocPct, String(regs.batterySocPct) + "%", "Battery SOC", "0x100 (ctrl estimate)", "#22c55e") + renderRing(pvPct, String(regs.pvCurrent, 1) + "A", "PV Current", "0x108 confirmed", "#facc15") + renderRing(loadPct, String(regs.loadCurrentLive, 2) + "A", "Load Current", "0x105 live", "#60a5fa") + renderRing(chgPct, String(regs.candBatteryCurrent, 2) + "A", "Charging", "0x102 confirmed", "#f97316") + "</div>" "<div class='stats'>" "<div class='card stat'><div class='lbl2'>☀️ PV Voltage</div>" "<div class='val'>" + String(regs.pvVoltage, 1) + " V</div>" "<div class='src'>0x107 · confirmed</div></div>" "<div class='card stat'><div class='lbl2'>🔋 Battery Voltage</div>" "<div class='val'>" + String(regs.batteryVoltage, 2) + " V</div>" "<div class='src'>0x101 · confirmed 01/07/26</div></div>" "<div class='card stat'><div class='lbl2'>💡 Load Voltage</div>" "<div class='val'>" + String(regs.loadVoltage, 1) + " V</div>" "<div class='src'>0x104 · confirmed</div></div>" "<div class='card stat'><div class='lbl2'>⚡ Charging Power</div>" "<div class='val'>" + String(regs.pvPower, 0) + " W</div>" "<div class='src'>0x109 · confirmed 01/07/26</div></div>" "<div class='card stat'><div class='lbl2'>💡 Load Power</div>" "<div class='val'>" + String(regs.loadPowerLive) + " W</div>" "<div class='src'>0x106 · datasheet</div></div>" "<div class='card stat'><div class='lbl2'>🌡️ Temps ctrl/batt</div>" "<div class='val'>" + String(regs.controllerTempC) + " / " + String(regs.batteryTempC) + " °C</div>" "<div class='src'>0x103 · confirmed 01/07/26</div></div>" "<div class='card stat'><div class='lbl2'>📈 Today PV Gen</div>" "<div class='val'>" + String(displayPvWh, 0) + " Wh</div>" "<div class='src'>" + (pvWhFromReg ? "0x113 · confirmed" : "local estimate (0x113=0 early AM)") + "</div></div>" "<div class='card stat'><div class='lbl2'>📈 Today Load Use</div>" "<div class='val'>" + String(displayLoadWh, 0) + " Wh</div>" "<div class='src'>0x114 · confirmed 01/07/26</div></div>" "</div>" "<div class='tier ds'>" "<div class='th'>🔵 Datasheet-only — not yet bench-verified by us</div>" "<div class='row'><span>Battery max voltage today (0x10C)</span><b>" + String(regs.batteryVoltsMaxToday, 1) + " V</b></div>" "<div class='row'><span>Load power direct (0x106)</span><b>" + String(regs.loadPowerLive) + " W</b></div>" "<div class='note'>0x106 load power is the only remaining datasheet-only value on the main dashboard. " "Everything else has now been cross-referenced against the BT app (01/07/2026).</div>" "</div>" "<div class='tier cand'>" "<div class='th'>🔍 Today's peaks — time recorded when each was set</div>" "<div class='row'><span>Peak PV voltage (0x107)</span>" "<b>" + String(regs.peakPvVoltageVal, 1) + " V</b>" "<span style='color:var(--muted);font-size:0.85em;margin-left:8px;'>at " + regs.peakPvVoltageTime + "</span></div>" "<div class='row'><span>Peak PV current (0x108)</span>" "<b>" + String(regs.peakPvCurrentVal, 2) + " A</b>" "<span style='color:var(--muted);font-size:0.85em;margin-left:8px;'>at " + regs.peakPvCurrentTime + "</span></div>" "<div class='row'><span>Peak charging current (0x10D)</span>" "<b>" + String(regs.peakChgCurrentVal, 2) + " A</b>" "<span style='color:var(--muted);font-size:0.85em;margin-left:8px;'>at " + regs.peakChgCurrentTime + "</span></div>" "<div class='row'><span>Peak charging power (0x10F)</span><b>" + String(regs.todayMaxChgPower, 0) + " W</b></div>" "<div class='row'><span>Load current max today (0x10E)</span><b>" + String(regs.loadCurrent, 2) + " A</b></div>" "<div class='row'><span>Battery min voltage today (0x10B)</span><b>" + String(regs.candBatteryVoltage, 1) + " V</b></div>" "<div class='note'>Peak times reset at midnight. Since your panel is flat on the shed roof, these " "tell you empirically what time of day your specific installation peaks — accounting for " "your latitude, any shading, and the sun's actual angle rather than a theoretical calculation. " "Battery SOC ring is the controller's voltage-curve estimate — BASE50 BMS (coulomb " "counting) is authoritative: at 07:07 01/07/26 controller showed 100%, BMS showed 95% " "with charge FET still open.</div>" "</div>" "<nav>" "<a href='/energy'>📅 Energy Log</a>" "<a href='/debug'>🔍 Raw Registers</a>" "<a href='/fw_a9x82_internal'>🔄 OTA Update</a>" "</nav>" "<footer>" "<span>📡 " + getWifiStatus() + "</span>" "<span>Last Modbus: " + String((millis() - lastSuccessfulRead) / 1000) + "s ago</span>" "</footer>" "</div></body></html>"; server.send(200, "text/html", html); }); // ==================== /energy ==================== server.on("/energy", HTTP_GET, []() { String s = "<!DOCTYPE html><html><head><meta charset='UTF-8'>" "<meta name='viewport' content='width=device-width,initial-scale=1'>" "<style>body{background:#0b1320;color:#e7edf6;font-family:'Segoe UI',Arial,sans-serif;padding:20px;max-width:480px;margin:auto;}" "h1{font-size:1.1em;font-weight:600;}" "table{width:100%;border-collapse:collapse;margin-top:14px;}" "td,th{padding:8px 6px;border-bottom:1px solid #22324a;text-align:left;font-size:0.92em;}" "th{color:#7c8ba3;font-size:0.75em;text-transform:uppercase;letter-spacing:.04em;}" "a{color:#f0b429;text-decoration:none;}.muted{color:#7c8ba3;font-size:0.85em;}" "</style></head><body>" "<h1>📅 Daily Energy Log</h1>" "<p class='muted'>Last " + String(ENERGY_LOG_MAX_DAYS) + " days · Wh logged at midnight rollover</p>"; if (!littleFsReady) { s += "<p style='color:#f0b429;'>LittleFS not mounted this boot — log unavailable.</p>"; } else if (!LittleFS.exists(ENERGY_LOG_PATH)) { s += "<p class='muted'>No completed days logged yet — check back after midnight.</p>"; } else { File f = LittleFS.open(ENERGY_LOG_PATH, "r"); String lines[ENERGY_LOG_MAX_DAYS]; int n = 0; if (f) { while (f.available() && n < ENERGY_LOG_MAX_DAYS) { String line = f.readStringUntil('\n'); line.trim(); if (line.length() >= 11) lines[n++] = line; } f.close(); } s += "<table><tr><th>Date</th><th>Total Wh</th></tr>"; float weekTotal = 0; for (int i = n - 1; i >= 0; i--) { int comma = lines[i].indexOf(','); if (comma < 0) continue; String d = lines[i].substring(0, comma); String wh = lines[i].substring(comma + 1); s += "<tr><td>" + d + "</td><td>" + wh + " Wh</td></tr>"; if (n - i <= 7) weekTotal += wh.toFloat(); } s += "</table>"; s += "<p class='muted' style='margin-top:14px;'>Last 7 logged days: <b style='color:#e7edf6;'>" + String(weekTotal, 1) + " Wh</b></p>"; } s += "<p style='margin-top:20px;'><a href='/'>← Dashboard</a></p>"; s += "</body></html>"; server.send(200, "text/html", s); }); // Debug Page server.on("/debug", HTTP_GET, []() { String s = "<html><head><meta charset='UTF-8'><style>body{background:#0f172a;color:#e2e8f0;font-family:Arial;padding:20px;}table{margin-bottom:20px;}</style></head><body>"; s += "<h1>🔍 Live Modbus Register Viewer</h1>"; s += "<p>Time: " + getDateTime() + "</p>"; s += renderCandidates(); // 0x00-0x3F already covered by past testing (all dead ends - // see renderCandidates notes). Moving into fresh territory. s += renderWideScan(0x40, 0x7F, 16); s += renderWideScan(0x80, 0xBF, 16); // New: try function code 0x04 (input registers) instead of 0x03 // (holding registers) at the same low addresses, since 0x40-0xBF // turned out to just be the device's model string. s += renderInputRegisterProbe(); // Targeted scan: 0x0107 (PV voltage, known-good) sits far outside // everything mapped so far (0x00-0xBF = config/flags/model string, // all confirmed dead for live telemetry). If there's a live // measurement bank, it's most likely clustered near 0x0107 rather // than back near the config block. Reusing renderWideScan() since // it's already generic - no new function needed. s += renderWideScan(0x0100, 0x0120, 16); delay(20); yield(); if (node.readHoldingRegisters(0x0107, 1) == node.ku8MBSuccess) { uint16_t raw = node.getResponseBuffer(0); s += "<h3>Raw PV Voltage (0x0107)</h3><p>Raw: <b>" + String(raw) + "</b> → ÷10 = <b>" + String(raw / 10.0f, 2) + " V</b></p>"; } s += "<br><a href='/'>← Dashboard</a> | <a href='/debug'>Refresh</a>"; s += "</body></html>"; // v17.04.00: no-cache headers on this response only. Does NOT change // Modbus poll rate, WiFi sleep, OTA password, or date format - purely // stops Cloudflare/browser from serving a stale cached copy, so every // /debug load (including a remote fetch) reflects a genuinely fresh // register read. server.sendHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0"); server.sendHeader("Pragma", "no-cache"); server.send(200, "text/html", s); }); // OTA Page with Reboot Button server.on("/fw_a9x82_internal", HTTP_GET, []() { if (!server.authenticate(otaUser, otaPass)) return server.requestAuthentication(); String html = R"rawliteral(<!DOCTYPE html><html><head><meta charset="UTF-8"><title>OTA Update</title><style>body{font-family:Arial;background:#0f172a;color:#e2e8f0;padding:40px;text-align:center;}</style></head><body><h1>🌞 SolarRV OTA Update</h1><form method="POST" action="/fw_a9x82_internal" enctype="multipart/form-data"> <input type="file" name="update" accept=".bin"><br><br> <input type="submit" value="Upload Firmware"></form><p style="margin-top:30px;"><a href="/resume">Cancel & Resume Modbus</a></p><div style="margin-top:40px; padding-top:20px; border-top:1px solid #334155;"> <p style="color:#94a3b8;">Need a clean restart without flashing?</p> <form method="POST" action="/reboot" onsubmit="return confirm('Reboot the device now?');"> <input type="submit" value="🔁 Reboot Device" style="background:#dc2626;color:white;padding:12px 30px;border:none;border-radius:6px;font-size:16px;cursor:pointer;"> </form></div></body></html>)rawliteral"; server.send(200, "text/html", html); }); server.on("/fw_a9x82_internal", HTTP_POST, []() { server.sendHeader("Connection", "close"); server.send(200, "text/plain", (Update.hasError()) ? "Update Failed!" : "Update Success! Rebooting..."); delay(1000); ESP.restart(); }, []() { HTTPUpload& upload = server.upload(); if (upload.status == UPLOAD_FILE_START) { if (!server.authenticate(otaUser, otaPass)) { Serial.println("OTA REJECTED"); otaInProgress = false; return; } otaInProgress = true; otaPauseStart = millis(); if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { Update.printError(Serial); otaInProgress = false; return; } } else if (upload.status == UPLOAD_FILE_WRITE) { if (otaInProgress) Update.write(upload.buf, upload.currentSize); } else if (upload.status == UPLOAD_FILE_END) { otaInProgress = false; Update.end(true); } }); server.on("/resume", HTTP_GET, []() { if (!server.authenticate(otaUser, otaPass)) return server.requestAuthentication(); otaInProgress = false; server.sendHeader("Location", "/"); server.send(302, "text/plain", ""); }); server.on("/reboot", HTTP_POST, []() { if (!server.authenticate(otaUser, otaPass)) return server.requestAuthentication(); server.send(200, "text/plain", "Rebooting..."); delay(500); ESP.restart(); }); server.begin(); Serial.println("Web server started");}void loop() { ArduinoOTA.handle(); server.handleClient(); unsigned long now = millis(); static unsigned long lastWifi = 0; if (now - lastWifi > 10000) { lastWifi = now; if (WiFi.status() == WL_DISCONNECTED) WiFi.begin(ssid, password); } if (now - lastNTP > ntpInterval) { lastNTP = now; configTzTime("GMT0BST,M3.5.0/1,M10.5.0/2", ntpServer); } checkDailyReset(); if (otaInProgress && (now - otaPauseStart > otaTimeout)) otaInProgress = false; if (!otaInProgress && (lastPoll == 0 || (now - lastPoll >= pollInterval))) { lastPoll = now; readController(); } yield();}
I wanted to utilise the pi-hole software but didn’t want to use my Raspbury pie, I wanted to use hyper V virtualisation and a basic cut down version of mini Ubuntu, http://archive.ubuntu.com/ubuntu/dists/yakkety/main/installer-amd64/current/images/netboot/mini.iso









