← เครื่องมือทั้งหมด

SMART FARM · CONTROL · SIMULATOR

Smart Irrigation Simulator

ทดลอง controller cycle ของระบบให้น้ำหลายโซนจาก Measurement → Decision → Command Owner → Runtime → Feedback → Event เพื่อดูว่าเหตุใดระบบจึง Start,…

เริ่มจำลองระบบให้น้ำ
02 / CONTROLLER CYCLE

System state

Tick160 sec / tick
Tankavailablefresh
Owner beforenoneshared pump
Selected ownerzone-aselect-start-request
Owner afterzone-anext cycle
Desired pumpONsoil-policy
Desired valvezone-aevaluate
Observed feedbackunexpected-flowfresh
Timestamp14:00:00scenario clock
Events4session total
History1controller cycles
03 / MQTT FIELD ADAPTER

Desired command → transport preview

Preview นี้แปลง command envelope เป็น MQTT message ตาม contract เดียวกับ validator โดยไม่เชื่อมต่อ Broker จริง และ command topic จะไม่ retain

Topicsite/farm-lab/irrigation/irrigation-main/command
QoS / RetainQoS 1 · retain=false
Expiry60s
{"schema":"thospaak.smart-irrigation.command","version":1,"commandId":"irrigation:2026-10-15T14:00:00Z:zone-a:2026-10-15T13:55:00Z","issuedAt":"2026-10-15T14:00:00Z","expiresAt":"2026-10-15T14:01:00.000Z","ownerZoneId":"zone-a","desired":{"pumpOn":true,"openValveZoneId":"zone-a"},"provenance":{"source":"soil-policy","intent":"evaluate","requestedAt":"2026-10-15T13:55:00Z"}}

MQTT เป็น transport เท่านั้น: message ถูก publish ไม่ได้แปลว่า Pump ทำงานจริง ต้องดู command acknowledgement + Pump/Valve/Flow feedback แยกกัน และ local protection/interlock ยังเป็นคนละชั้น

Availability gateunavailable
ACK lifecyclenone
Last inboundnone
Node Online/Offline, ACK และ field feedback ด้านบนเป็น inbound MQTT simulation เท่านั้น ไม่มี Broker connection จริง และ Availability จะ gate เฉพาะ remote command path ไม่แก้ physical safety state
04 / FIELD NODE CONTRACT

Boot, clock, watchdog และ reconnect

Deployment preview นี้เป็น firmware-facing contract สำหรับ ESP32/PLC/Gateway: force safe outputs ก่อน network, sync clock ก่อนรับ remote command, ใช้ monotonic lease จำกัดเวลาคำสั่ง และไม่ replay command หลัง reconnect

Broker transportmqtts://mqtt.internal.example:8883TLS required · inline secrets forbidden
Command lease20s maxmonotonic deadline
Reconnectnever replay commandrepublish current state + telemetry
  1. 01force-safe-outputs
  2. 02initialize-command-dedup-cache
  3. 03synchronize-device-clock
  4. 04configure-retained-offline-last-will
  5. 05connect-mqtt-with-tls-auth
  6. 06publish-retained-online-availability
  7. 07republish-current-state-and-telemetry
  8. 08subscribe-command-topic

ACK accepted หมายถึง command ผ่าน validation และถูกจับ lease แล้ว ส่วน applied หมายถึง driver command ถูกเขียนออกไป ไม่ใช่หลักฐานว่า Pump/Valve ทำงานจริง—physical feedback ยังต้องกลับมาผ่าน state/Flow telemetry แยกต่างหาก

05 / ESP32 REFERENCE NODE

Reviewed GPIO + firmware boundary

Reference target นี้ใช้ ESP32-WROOM-32 DevKit สองโซนเป็นตัวอย่างที่ตรวจ pin role ได้จริง: actuator GPIO เป็น 3.3V logic ไปยัง isolated driver/contactor interface เท่านั้น ส่วน analog sensor ใช้ ADC1 เพื่อไม่ชนกับ Wi-Fi

Profileesp32-wroom32-devkit-2zone-v1ESP32-WROOM-32 DevKit
Pin validationPASS0 issue(s)
Electrical boundary3.3V logic onlydirect mains/motor drive = forbidden
GPIORoleZoneDirectionSafe / interface note
GPIO 25pump-commandsystemoutput · active-highLogic output to an isolated driver/contactor interface only; never drive a pump or mains load directly.
GPIO 32pump-feedbacksysteminputRead isolated auxiliary-contact or low-voltage pump-run feedback.
GPIO 34flow-pulsesysteminputInput-only GPIO; external pull/bias is required when the flow sensor output needs it.
GPIO 35tank-analogsysteminputADC1 input selected so Wi-Fi does not compete with ADC2; external analog conditioning/calibration remains hardware-specific.
GPIO 21emergency-stop-healthysysteminputActive-high isolated healthy/permissive input with external pull-down so open wiring or reset fails closed.
GPIO 22water-supply-permitsysteminputActive-high isolated water-supply/dry-run permit with external pull-down fail-safe bias.
GPIO 23driver-readysysteminputActive-high isolated actuator-driver ready feedback; LOW/open blocks energizing commands.
GPIO 33process-permitsysteminputActive-high local process/manual permit with external pull-down; all four permissives must be healthy.
GPIO 26valve-commandzone-aoutput · active-highLogic output to an isolated valve-driver interface only; external bias must keep the valve command safe during reset/boot.
GPIO 18valve-feedbackzone-ainputRead isolated valve-position or auxiliary-contact feedback when available.
GPIO 36soil-analogzone-ainputADC1 input; sensor excitation, scaling and calibration are intentionally outside the GPIO contract.
GPIO 27valve-commandzone-boutput · active-highLogic output to an isolated valve-driver interface only; external bias must keep the valve command safe during reset/boot.
GPIO 19valve-feedbackzone-binputRead isolated valve-position or auxiliary-contact feedback when available.
GPIO 39soil-analogzone-binputADC1 input; sensor excitation, scaling and calibration are intentionally outside the GPIO contract.
Startup phasessafe-gpio-init → local-interlock-init → sensor-and-feedback-init → time-sync → mqtt-tls-connect → state-republish → command-subscribe → runtime-loop
Failure policyWi-Fi/MQTT loss keeps local safety; command lease expiry forces Pump OFF + valves closed
SecretsPer-device credential reference + CA trust store; no inline credentials

Pin map นี้เป็น reference สำหรับ low-voltage logic interface เท่านั้น ไม่ใช่ wiring diagram สำหรับไฟเมนส์หรือ motor circuit และยังต้องตรวจ schematic ของบอร์ด/driver/contactor/sensor รุ่นจริงก่อน deployment

06 / BENCH HARNESS

GPIO trace + sampling + fault injection

Harness แบบ deterministic ใช้ reference profile และ field-node contract เดิมเพื่อพิสูจน์ boot-glitch safety, output transition, ADC/flow conversion และ failure behavior ก่อนมี firmware binary หรือ hardware bench จริง

Boot glitch guardPASSreset outputs = high-Z + external fail-safe bias
Tank ADC example51.5%GPIO 35 · good
Flow pulse example0.6 L/min45 pulses / 10s · good
SeqGPIORoleReset / safe levelEffective activeReason
1GPIO 25pump-commandhigh-zNOpower-on-reset-external-bias
2GPIO 26valve-command · zone-ahigh-zNOpower-on-reset-external-bias
3GPIO 27valve-command · zone-bhigh-zNOpower-on-reset-external-bias
4GPIO 25pump-commandlowNOsafe-gpio-init
5GPIO 26valve-command · zone-alowNOsafe-gpio-init
6GPIO 27valve-command · zone-blowNOsafe-gpio-init
software-resetbrownoutwatchdog-resetwifi-dropmqtt-dropclock-invalidlocal-interlock-trip

Local interlock ใน harness สามารถ de-energize effective GPIO ได้ทันทีโดยไม่ปลอมว่า controller desired state เปลี่ยนแล้ว ส่วน Wi-Fi/MQTT loss จะไม่สร้าง physical state ปลอม แต่ปล่อยให้ monotonic command lease/watchdog บังคับ safe state ตามเวลา

07 / FRAMEWORK ADAPTER

ESP-IDF / Arduino ports without safety drift

Framework adapter จำกัด side effects ไว้ที่ ports เดียวกันทั้ง ESP-IDF และ Arduino/PlatformIO ส่วน command lease, dedup, readiness, calibration และ fail-safe semantics ยังอยู่ใน core/harness เดิม

Supported targetsesp-idf · arduino-platformiosame contract · different platform bindings
SNTP gateunsynchronized → synchronizedclock jump = resync-required
Config exportsecret material = falsenvs://mqtt/field-01 · reference only
GPIOADC1Pulse CounterMonotonic ClockSNTP / Wall ClockNVS Config StoreHardware WatchdogReset Reason

Fake-driver regression ใช้ ports ชุดเดียวกันพิสูจน์เส้นทาง MQTT command → field-node acceptance/lease → framework GPIO write → observed GPIO/ADC/pulse feedback → watchdog safe-off โดย framework binding ไม่มีสิทธิ์ bypass local interlock หรือเปลี่ยน command-expiry semantics

08 / ESP-IDF NATIVE BINDING

Exact API map + safe startup order

Binding plan นี้ล็อก native boundary สำหรับ ESP-IDF 5+: GPIO, ADC oneshot, PCNT, esp_timer, SNTP, NVS, task watchdog และ reset reason ถูก map ไปยัง framework ports แบบตรงตัว โดยไม่มี irrigation decision logic ใน native layer

Binding validationPASS9 ports · ESP-IDF 5+
Build componentsesp_driver_gpio · esp_driver_pcnt · esp_adc · esp_timer · esp_netif · mqtt · nvs_flash · esp_systemnative driver ownership only
Safety ownershipCore / harnessnative business logic = forbidden
PortESP-IDF APIHeaderResponsibility
gpiogpio_config · gpio_set_level · gpio_get_leveldriver/gpio.hConfigure reviewed GPIO directions and translate high/low reads and writes only.
adcadc_oneshot_new_unit · adc_oneshot_config_channel · adc_oneshot_readesp_adc/adc_oneshot.hRead raw ADC1 counts from the reviewed Tank/Soil channels; calibration remains in the framework/core contract.
pulseCounterpcnt_new_unit · pcnt_new_channel · pcnt_unit_enable · pcnt_unit_start · pcnt_unit_get_countdriver/pulse_cnt.hExpose a monotonically accumulated Flow pulse total; liters-per-minute conversion remains outside the native layer.
monotonicClockesp_timer_get_timeesp_timer.hConvert ESP-IDF monotonic microseconds to milliseconds for leases, watchdog evaluation, and sampling cadence.
wallClockgettimeofday · gmtime_rsys/time.h · time.hRead synchronized wall clock and format it as UTC ISO-8601; never synthesize freshness from publish time.
timeSyncesp_netif_sntp_init · esp_netif_sntp_sync_wait · esp_netif_sntp_deinitesp_netif_sntp.hRequest and observe SNTP synchronization only; command gating remains in the framework/core contract.
configStorenvs_flash_init · nvs_open · nvs_get_str · nvs_get_blob · nvs_closenvs_flash.h · nvs.hLoad versioned device identity, credential references, CA references, and calibration metadata; no raw secrets are exported.
watchdogesp_task_wdt_add · esp_task_wdt_resetesp_task_wdt.hRegister/feed the runtime task watchdog; actuator safe-off semantics remain in the harness/field-node contract.
resetReasonesp_reset_reasonesp_system.hReturn the raw ESP-IDF reset reason for framework normalization and telemetry.
  1. 01external-fail-safe — Hardware pull/down or driver disable keeps Pump/Valve de-energized before firmware runs.
  2. 02safe-gpio — All reviewed command GPIOs configured to inactive level before network initialization.
  3. 03config — Versioned config + reference-only credentials must validate before remote control can be enabled.
  4. 04reset-reason — Reset reason is normalized but never changes safe-start behavior.
  5. 05network — Connectivity may start only after GPIO safe state is established.
  6. 06time-sync — Remote command path remains blocked until synchronized wall clock is valid.
  7. 07mqtt — MQTT command subscription starts only after safe GPIO + validated config + time-sync gate.
  8. 08sensor-drivers — ADC/PCNT drivers expose raw acquisition only; calibration/freshness stays in the framework/core layer.
  9. 09watchdog — Runtime task is supervised before command processing loop begins.
  10. 10runtime — Runtime loop performs port I/O and feeds watchdog while core owns all control semantics.

Repo นี้ยังไม่ได้ compile ESP-IDF binary; checkpoint นี้เป็น typed native-binding contract + regression validator เพื่อกัน API/order/safety drift ก่อนสร้าง firmware project และ Hardware-in-the-Loop milestone จริง

09 / ZONES

Decision และ runtime ต่อ Zone

Decision เกิดทุก Zone แต่มีเพียง owner ที่ได้ใช้ shared Pump ใน cycle นั้น

ZoneRequestSoilDecisionReasonOwnerRuntimeFault
zone-asoil-policy · evaluate26.0%startautomatic-start-thresholdOWNERwatering · start-watering—
zone-bsoil-policy · evaluate28.0%startautomatic-start-thresholdQUEUEDidle · idle-no-request—
10 / EVENT TIMELINE

เหตุผลที่ตรวจย้อนหลังได้

Event contract เก็บ decision, feedback, state transition และ command-owner change ต่อเนื่องทุก tick โดยใช้ machine-readable code

decisionzone-a · automatic-start-threshold{"action":"start","requestSource":"soil-policy","requestIntent":"evaluate","requestedAt":"2026-10-15T13:55:00Z","soilFreshness":"fresh"}
state-transitionzone-a · start-watering{"from":"idle","to":"watering","commandActive":true}
decisionzone-b · automatic-start-threshold{"action":"start","requestSource":"soil-policy","requestIntent":"evaluate","requestedAt":"2026-10-15T13:56:00Z","soilFreshness":"fresh"}
command-ownerzone-a · owner-acquired{"previousOwner":null,"nextOwner":"zone-a"}
11 / SESSION HISTORY

State progression หลาย tick

History สรุป owner, feedback และ runtime state ต่อ cycle เพื่อเทียบกับ event timeline และใช้ replay/regression ภายหลัง

TickTimeOwner beforeOwner afterFeedbackTankZone states
114:00:00nonezone-aunexpected-flowavailablezone-a:watering · zone-b:idle