100%
pt100_mesh_datalogger Connectors view
Description

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:
    1. Appends the batch to the daily CSV file (YYYY-MM-DD.csv) with setvbuf buffering.
    2. fflush() + fsync().
    3. Reads back the appended region and checks SHA-256.
    4. On mismatch: truncates to the original size and leaves FRAM untouched.
    5. On success: consumes the matching FRAM records.
  • 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_full flag surfaces via status.

Resume / crash safety

  • On boot or day rollover the logger:
    1. Opens today’s file, truncates to the last newline if the tail was partial.
    2. Scans the tail to find the last written seq.
    3. Drops any FRAM records with seq <= last_sd_seq to 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

  • status
  • raw (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 show
  • cal clear
  • cal add <raw_c> <actual_c>
  • cal list
  • cal 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

  1. Calibration persistence: Add points, apply, reboot, and confirm status shows the same coefficients and calibrated readings remain adjusted.
  2. Batching size: Monitor SD writes (logic analyzer or debug prints) to confirm large buffered writes (64–256 KB) rather than per-sample writes.
  3. Crash during flush: Pull power mid-flush; on reboot confirm the CSV tail is repaired and no duplicated seq appears on SD after FRAM drains.
  4. Tail repair: Manually append a partial line to a CSV, reboot, and confirm it is truncated to the last newline automatically.
  5. Mesh resilience: Run leaves with the root powered off; verify local FRAM accumulation and later FRAM→SD flush when root/SD returns.
  6. SD removal: Unmount/remove SD, ensure FRAM continues to grow; remount and verify backlogged records flush with verified appends.
Comments
Sign in to comment

No comments yet. Be the first to ask about this board.