Imported from GitHub: rasusmilch/PT100_Mesh_Datalogger · commit 6ebc7f5
Description
PT100 + MAX31865 Temperature Data Logger (ESP32-S3, ESP-IDF)
README
PT100 + MAX31865 Temperature Data Logger (ESP32-S3, ESP-IDF)
This application turns an ESP32-S3 N8R2 into a UTC-centric PT100 data logger with FRAM-first buffering, SD-card CSV batching/verification, DS3231 RTC support, mesh streaming, and serial-console calibration.
Hardware / wiring
All signal pins are configurable under idf.py menuconfig -> PT100 Logger:
- Shared SPI bus:
MOSI,MISO,SCLK - Chip-selects:
MAX31865 CS,FRAM CS,SD CS - DS3231 I2C:
SDA,SCL(address selectable)
Configure mesh root/leaf role and Wi-Fi credentials in the same menu.
Build / flash
idf.py set-target esp32s3
idf.py menuconfig # configure pins, mesh role, batch sizes, flush thresholds
idf.py build flash monitor
Logging pipeline (FRAM → SD with verification)
- Sensor task samples MAX31865 at
log interval(NVS-backed). - Each record is appended as a fixed-size binary struct (with CRC) to a FRAM ring buffer; the persistent header tracks read/write indices and the next sequence number.
- The SD task builds large CSV batches (~64–256 KB, configurable) from FRAM without consuming it, then:
- Appends the batch to the daily CSV file (
YYYY-MM-DD.csv) withsetvbufbuffering. fflush()+fsync().- Reads back the appended region and checks SHA-256.
- On mismatch: truncates to the original size and leaves FRAM untouched.
- On success: consumes the matching FRAM records.
- Appends the batch to the daily CSV file (
- CSV header (written once per day):
schema_ver,record_id,seq,epoch_utc,iso8601_local,raw_rtd_ohms,raw_temp_c,cal_temp_c,flags,node_id - FRAM is limited (default 32 KB); when it fills, logging pauses (no overwrite) until a flush frees space. A
fram_fullflag surfaces viastatus.
Resume / crash safety
- On boot or day rollover the logger:
- Opens today’s file, truncates to the last newline if the tail was partial.
- Scans the tail to find the last written
seq. - Drops any FRAM records with
seq <= last_sd_seqto guarantee no duplicates.
- If FRAM corruption is detected, consumption stops and the corrupted record can be skipped explicitly (see logs).
Timekeeping
- DS3231 is treated as UTC and seeds system time at boot.
- Mesh root uses SNTP, updates DS3231, and broadcasts time over the mesh; leaves can request/broadcast time updates.
Serial console commands
statusraw(one sample: raw/calibrated temp + resistance)log interval <ms>log watermark <records>(FRAM flush high-water mark)log flush_period <ms>(periodic SD flush interval)log batch <bytes>(target SD batch size)log showcal clearcal add <raw_c> <actual_c>cal listcal apply(1 point = offset-only; 2–4 points fit deg1–deg3)flush(best-effort FRAM→SD flush with verification)diag check(diagnostics mode only; sensor/FRAM/SD/mesh/time quick health check)
All configuration changes persist to NVS.
Mesh / host streaming
Mesh mode (leaf → root → broker/serial)
- Leaf nodes publish samples into the mesh; logging to FRAM continues if the mesh or upstream network is down.
- The root bridges mesh records to the MQTT broker and/or the DATA UART (CSV), and these exports are best-effort only.
Direct Wi-Fi leaf mode (leaf → broker)
- Leaves can bypass the mesh and publish directly to the broker when configured for direct Wi-Fi.
FRAM/SD logging plus the DATA UART output never depend on network availability.
- Leaf nodes send samples upstream; logging to FRAM continues if mesh is down.
- Root node prints one CSV row per record over UART (after the CSV header).
Root upstream router credentials can be provided via the wifi_ssid /
wifi_pass NVS settings (from your console tooling or provisioning flow). If
those are not set, the root falls back to
CONFIG_APP_WIFI_ROUTER_SSID / CONFIG_APP_WIFI_ROUTER_PASSWORD in Kconfig.
Test plan
- Calibration persistence: Add points, apply, reboot, and confirm
statusshows the same coefficients and calibrated readings remain adjusted. - Batching size: Monitor SD writes (logic analyzer or debug prints) to confirm large buffered writes (64–256 KB) rather than per-sample writes.
- Crash during flush: Pull power mid-flush; on reboot confirm the CSV tail is repaired and no duplicated
seqappears on SD after FRAM drains. - Tail repair: Manually append a partial line to a CSV, reboot, and confirm it is truncated to the last newline automatically.
- Mesh resilience: Run leaves with the root powered off; verify local FRAM accumulation and later FRAM→SD flush when root/SD returns.
- SD removal: Unmount/remove SD, ensure FRAM continues to grow; remount and verify backlogged records flush with verified appends.
No comments yet. Be the first to ask about this board.