헤드리스 Pi 콘솔/journalctl에서 한글이 깨져 보이는 문제로, Pi 번들(02/03/04)에 들어가는 모든 소스의 사람-대상 텍스트를 영어로 전환. 코드·식별자·설정키·경로·숫자·hex·서명 스킴·f-string 플레이스홀더는 불변. - raspberry_pi4/, raspberry_pi4_sht30/: 로그·주석·문서·센서명·위치 영어화 - tools/make_deploy_bundles.py: 생성 템플릿(config_local.py/setup.sh/SETUP.md/PI_META 위치) 영어화 - tools/harden_pi.sh, tools/set_network.sh: echo/주석 영어화 - WIRING.html: 영어화 + SHT30 전압 경고 정정 반영 - 서버 번들(01, php/)은 한글 유지(브라우저 대시보드, Pi에서 안 깨짐) - 전 파이썬/셸 문법검사 통과, JSON 본문 서명 무영향 |
||
|---|---|---|
| .. | ||
| systemd | ||
| .gitignore | ||
| config.py | ||
| config_local.example.py | ||
| install.sh | ||
| leak_sensor.py | ||
| README.md | ||
| requirements.txt | ||
| test_connection.py | ||
| vendor.sh | ||
| WIRING.html | ||
Leak Detection Sensor Module — Raspberry Pi 4 Model B Only
A monitoring module that reads the e-con 5C-08 resistive leak detection sensor via the GPIO of a Raspberry Pi 4 Model B. On a leak it immediately reports to the PHP API server (+ triggers an SMS), and captures an on-site photo with the Pi Camera and uploads it.
This folder is a port of a module originally written for the Raspberry Pi Zero 2 W, adapted to be Pi 4 Model B only. The GPIO (BCM) numbering scheme and the
rpicam/libcameracamera stack are identical on both boards, so the sensor/capture logic is unchanged; the differences are only in the wiring/power/Ethernet/camera connector and the install environment.
1. Files
| File | Role |
|---|---|
leak_sensor.py |
Main — GPIO interrupt leak detection, periodic reporting, capture+upload on leak |
config.py |
Non-secret default settings (sensor/threshold/interval/camera). Loads secrets from config_local |
config_local.example.py |
Operational/secret value template → copy to config_local.py before use (not committed) |
requirements.txt |
Python dependencies (pinned) |
install.sh |
Pi 4 install script (air-gapped offline + online fallback) |
vendor.sh |
Pre-download dependencies for air-gapped use (run on build machine) |
test_connection.py |
Server connection/signature check |
systemd/leak-sensor.service |
Auto-start-on-boot service unit |
2. Hardware (based on Pi 4 Model B)
- Raspberry Pi 4 Model B (BCM2711) + Raspberry Pi OS Bookworm 64-bit
- e-con 5C-08 leak detection sensor (resistive, high-impedance ~1.5MΩ)
- External 4.7MΩ pull-down resistor (required — internal pull resistor is off)
- (Optional) Pi Camera — Pi 4 = 15-pin (1.0mm pitch) standard CSI, Zero 2 W = 22-pin (0.5mm pitch) CSI → Ribbon/camera boards are not compatible (a Pi 4 15-pin ribbon or a 15↔22 adapter is required)
- Power: USB-C 5V/3A (a power margin is recommended when using the camera)
- Network: Pi 4 Gigabit Ethernet (wired) or WiFi
2.1 Pinout (default single sensor)
| Signal | BCM | 40-pin header physical pin |
|---|---|---|
| Sensor input | GPIO17 | 11 |
| 3.3V | — | 1 |
| GND | — | 6 (or 9/14/20/25/30/34/39) |
To add a sensor, add an entry by BCM number to
SENSORSinconfig.py. (e.g. GPIO27=physical pin 13, GPIO22=physical pin 15)
2.2 Electrical design (important)
ACTIVE_LOW = False: when dry GPIO=LOW(0), on leak GPIO=HIGH(1)USE_INTERNAL_PULL = False(keep PUD_OFF): if you turn on the internal 50kΩ pull-down, the 1.5MΩ sensor cannot pull GPIO up to HIGH, causing detection failure. Use only the external 4.7MΩ pull-down.
3. Server compatibility (must verify)
This module reports to a server that receives the leak_alert / leak_recovery events
and photo_upload.php.
✅ The
php/server in this repo is exactly that server (single-server integration complete). Both module 1 (leak + camera) and module 2 (SHT30 temperature/humidity) report to the same cafe24php/server with the raw-body signatureX-Signature = lowercase_hex(HMAC-SHA256(key=API_KEY, msg=request body bytes)), and leak status, photos, and temperature/humidity are shown together on a single dashboard (dashboard.php).
- New install: run only
sql/schema_sht30.sql— the leak elements (leak_sensor_log.is_leak/leak_sensor_status.is_leakcolumns,leak_incident,leak_photo,leak_ingest_noncetables) are already included.Set
API_URL/PHOTO_UPLOAD_URLinconfig_local.pyto this integrated server, and makeAPI_KEYbyte-for-byte identical to theAPI_KEYin the server'sconfig.local.php.
4. Installation
4.1 Prepare configuration values
cp config_local.example.py config_local.py
# Open config_local.py and fill in API_URL / PHOTO_UPLOAD_URL / API_KEY / DEVICE_ID
If config_local.py is missing, execution stops immediately with a clear error (fail closed).
Never commit config_local.py or API_KEY (they are handled by .gitignore).
4.2 Online install (environment with internet)
chmod +x install.sh
./install.sh
4.3 Air-gapped offline install
On a machine with internet of the same architecture (aarch64, ideally the same Pi 4 + Bookworm 64-bit), first fetch the dependencies to build a bundle, then move it to the target Pi 4 to install.
# (build machine, internet YES) create wheelhouse/ + debs/
./vendor.sh
# After copying wheelhouse/ and debs/ into this folder on the target Pi 4:
# (target Pi 4, internet NO)
./install.sh # if debs/ · wheelhouse/ exist, installs offline automatically
If
debs/exists,install.shinstalls offline withdpkg; ifwheelhouse/exists, it installs offline withpip --no-index. It falls back to internet apt/pip only when neither is present. wheel/deb are architecture-dependent, so ones fetched on an x86_64 PC will not work on the Pi 4.
5. Running
source venv/bin/activate
python3 leak_sensor.py
In an environment without RPi.GPIO (a development PC, etc.), it automatically runs in
simulation mode.
Connection check
source venv/bin/activate
python3 test_connection.py
6. Auto-start on boot (systemd)
# Assumes the folder is placed at /home/pi/raspberry_pi4 (if different, edit the path in .service)
sudo cp systemd/leak-sensor.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable leak-sensor
sudo systemctl start leak-sensor
sudo systemctl status leak-sensor
journalctl -u leak-sensor -f
SupplementaryGroups=video is required for camera access.
7. Security notes
- Secret values (
API_KEY), the server URL, and device info live only inconfig_local.py(not committed). Committed files contain only placeholders. - The report body is protected against tampering with a raw-body HMAC signature:
X-Signature = lowercase_hex(HMAC-SHA256(key=API_KEY, msg=request body bytes))(leak_sensor.sign_raw↔ serverconfig.php::verify_signature_raw, same scheme as module 2).- The canonical string for the photo upload signature is
device_id|sensor_id|log_id|timestamp(no spaces) (seeconfig_local.example.py). - The old
sha256(API_KEY + sorted JSON)body-field signature is deprecated, and the server default rejects it (ALLOW_LEGACY_BODY_SIGNATURE=false,php/config.php).
- The canonical string for the photo upload signature is
- If
config_local.pyis exposed, immediately rotateAPI_KEY(change it on the server at the same time).