Skip to content

Commit 386d8e9

Browse files
committed
Merge feat/multicore-task-architecture into claude/fix-ota-download-hang
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012JY8RZscs5W8tLQMuZB95K
2 parents bd1999f + d4545c8 commit 386d8e9

7 files changed

Lines changed: 58 additions & 18 deletions

‎docs/multicore-architecture.de.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ während die blockierende DS18B20-Konvertierung auf Kern 0 isoliert wird.
2626
| **Kern 0** (PRO_CPU) | Sensor-I/O | `SensorTask`: DS18B20-Konvertierung/-Auslesen und interne ESP32-Temperatur |
2727
| **Kern 1** (APP_CPU) | Regelung und zustandsbehaftete I/O | Arduino-`loop()`: Watchdog, Degradation, Regeln, Relais, Status-LED, Netzwerk/OTA, MQTT-Serialisierung, Frontpanel-UI und OLED-Rendering |
2828

29+
## Unterschiede je Board
30+
31+
| Board | Kerne | SensorTask | Arduino-`loop()` |
32+
| ----- | ----- | ---------- | ---------------- |
33+
| `esp32dev`, `norvi_ae01_r` (ESP32) | 2 | Kern 0, Priorität 2 | Kern 1, Priorität 1 |
34+
| `olimex_esp32_c6_evb` (ESP32-C6) | 1 | Kern 0, Priorität 2 | Kern 0, Priorität 1 |
35+
36+
Auf dem ESP32-C6 ist das Pinning kein zweiter, isolierter Kern. Das Ownership-Modell bleibt gleich
37+
(Single-Writer, Snapshots), aber `SensorTask` verdrängt die Regelschleife, sobald er lauffähig ist. Die
38+
750-ms-Konvertierung wird mit `vTaskDelay()` abgewartet, die Loop läuft währenddessen weiter; die
39+
OneWire-Transaktionen selbst (Bus-Scan, Rescan nach Fehlmessungen, Auslesen) blockieren die Loop für ihre
40+
Dauer. Die Worst-Case-Loop-Latenz auf dem C6 bei DS18B20-Recovery, MQTT-Reconnect und Display-Aktivität
41+
sowie die Watchdog-Reserve müssen auf dem Gerät gemessen werden; sie gehören zum Hardware-Test-Gate.
42+
2943
## Warum diese Grenze
3044

3145
Eine 12-Bit-DS18B20-Konvertierung kann ungefähr 750 ms dauern. In der Arduino-Loop würde sie

‎docs/multicore-architecture.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ DS18B20 conversion is isolated on Core 0.
2626
| **Core 0** (PRO_CPU) | Sensor I/O | `SensorTask`: DS18B20 conversion/readout and internal ESP32 temperature |
2727
| **Core 1** (APP_CPU) | Control and stateful I/O | Arduino `loop()`: watchdog, degradation, rules, relays, StatusLED, network/OTA, MQTT serialization, front-panel UI and OLED rendering |
2828

29+
## Board differences
30+
31+
| Board | Cores | SensorTask | Arduino `loop()` |
32+
| ----- | ----- | ---------- | ---------------- |
33+
| `esp32dev`, `norvi_ae01_r` (ESP32) | 2 | Core 0, priority 2 | Core 1, priority 1 |
34+
| `olimex_esp32_c6_evb` (ESP32-C6) | 1 | Core 0, priority 2 | Core 0, priority 1 |
35+
36+
On the ESP32-C6 the pinning is not a second isolated core. The ownership model is unchanged (single
37+
writer, snapshots), but `SensorTask` preempts the control loop whenever it is runnable. The 750 ms
38+
conversion is waited out with `vTaskDelay()`, so the loop runs during it; the OneWire transactions
39+
themselves (bus scan, rescan after failures, readout) do block the loop for their duration. Worst-case
40+
loop latency on the C6 during DS18B20 recovery, MQTT reconnect and display activity, and the
41+
watchdog margin, have to be measured on the device; they are part of the hardware test gate.
42+
2943
## Why this boundary
3044

3145
A 12-bit DS18B20 conversion can take roughly 750 ms. Running it in the Arduino loop stalls rule

‎docs/norvi-ae01-r.de.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,11 @@ Die 8-Byte-ROM-Adresse jedes Sensors wird im NVS gespeichert (Preferences-Namesp
171171
`ds18b20`, Keys `solar_adr` und `pool_adr`). Bei jedem folgenden Boot sucht die
172172
Firmware auf dem Bus nach einem Gerät mit der gespeicherten Adresse. Wird es
173173
gefunden, wird es unabhängig von der Scan-Reihenfolge verwendet. Wird es nicht
174-
gefunden (z. B. nach Austausch), erscheint eine Warnung und der Standard-Index
175-
kommt zum Einsatz.
174+
gefunden (z. B. nach Austausch), erscheint eine Warnung und die Rolle meldet
175+
einen ungültigen Wert (NaN), statt einen anderen Sensor zu lesen. Die Firmware
176+
spricht weiter die gespeicherte ROM an, sodass die Rolle wieder gültig wird,
177+
sobald dieser Sensor antwortet. Nach einem Austausch muss der neue Sensor im
178+
Sensor-Setup zugeordnet werden.
176179
177180
---
178181

‎docs/norvi-ae01-r.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ The 8-byte ROM address of each sensor is stored in NVS (Preferences namespace
172172
`ds18b20`, keys `solar_adr` and `pool_adr`). On every subsequent boot, the
173173
firmware scans the bus for a device matching the stored address. If found, that
174174
device is used — regardless of its bus scan position. If the stored sensor is
175-
not found (e.g., it was replaced), the firmware prints a warning and falls back
176-
to the default device index.
175+
not found (e.g., it was replaced), the firmware prints a warning and reports
176+
that role as invalid (NaN) instead of reading another sensor. It keeps
177+
addressing the stored ROM, so the role recovers as soon as that sensor responds
178+
again. After replacing a sensor, assign the new one in the sensor setup.
177179
178180
---
179181

‎src/CoreScheduler.cpp‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/**
55
* @file CoreScheduler.cpp
6-
* @brief Starts and monitors the dedicated Core-0 sensor task.
6+
* @brief Starts and monitors the sensor task (Core 0; the only core on ESP32-C6).
77
*/
88

99
#include "CoreScheduler.hpp"
@@ -18,7 +18,10 @@
1818
namespace PoolController {
1919

2020
void CoreScheduler::begin() {
21-
// Core 0 = PRO_CPU_NUM (sensor I/O); Core 1 = APP_CPU_NUM (control loop).
21+
// Dual-core ESP32 (esp32dev, NORVI): SensorTask on PRO_CPU (Core 0), the
22+
// Arduino loop on APP_CPU (Core 1). The ESP32-C6 has a single application
23+
// core, so both tasks share it and SensorTask (priority 2) preempts the
24+
// loop (priority 1) while it runs; see docs/multicore-architecture.md.
2225
const BaseType_t core0 = PRO_CPU_NUM;
2326

2427
if (!SensorTask::start(TASK_PRIORITY_SENSOR, TASK_STACK_SENSOR, core0)) {

‎src/DallasTemperatureNode.cpp‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,13 @@ bool DallasTemperatureNode::resolveFilter() {
111111
}
112112
}
113113

114-
LOG_ERROR(" ✖ %s: filter address not found on bus! Falling back to device index %d\n", _id, deviceIndex_);
115-
if (activeSensor->getAddress(deviceAddress_, deviceIndex_)) {
116-
publishSelectedAddress();
117-
_sensorFound = true;
118-
return true;
119-
}
120-
121-
memset(deviceAddress_, 0, sizeof(deviceAddress_));
114+
// An explicitly mapped role accepts only its own ROM. Falling back to the
115+
// device index could hand the pool probe to the solar role on a shared bus.
116+
// Keep addressing the configured ROM so it is read again once it responds.
117+
char adr[18];
118+
address2String(filter, adr, sizeof(adr));
119+
LOG_ERROR(" ✖ %s: configured sensor [%s] not found on bus\n", _id, adr);
120+
memcpy(deviceAddress_, filter, sizeof(DeviceAddress));
122121
publishSelectedAddress();
123122
_sensorFound = false;
124123
return false;
@@ -196,11 +195,15 @@ uint8_t DallasTemperatureNode::getDeviceCount() const {
196195
return count;
197196
}
198197

199-
void DallasTemperatureNode::getDeviceAddressString(char *buffer, size_t size) const {
200-
DeviceAddress addr;
198+
void DallasTemperatureNode::copySelectedAddress(DeviceAddress out) const {
201199
lockCache();
202-
memcpy(addr, cachedSelectedAddress_, sizeof(DeviceAddress));
200+
memcpy(out, cachedSelectedAddress_, sizeof(DeviceAddress));
203201
unlockCache();
202+
}
203+
204+
void DallasTemperatureNode::getDeviceAddressString(char *buffer, size_t size) const {
205+
DeviceAddress addr;
206+
copySelectedAddress(addr);
204207
address2String(addr, buffer, size);
205208
}
206209

‎src/DallasTemperatureNode.hpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class DallasTemperatureNode {
5353

5454
/** @brief Get number of devices from the thread-safe discovery snapshot. */
5555
uint8_t getDeviceCount() const;
56-
const uint8_t *getDeviceAddress() const { return deviceAddress_; }
56+
/** @brief Copy the selected ROM from the published cache (safe from any task). */
57+
void copySelectedAddress(DeviceAddress out) const;
5758
void getDeviceAddressString(char *buffer, size_t size) const;
5859
bool getDetectedDeviceAddress(uint8_t index, DeviceAddress addr) const;
5960
float getDetectedDeviceTemperature(uint8_t index) const;

0 commit comments

Comments
 (0)