GATE AND GARAGE PROJECT - Heltec WiFi LoRa 32 V3
================================================

Each program is in its own folder (Arduino needs the folder name to match the .ino name).
In Arduino IDE: File > Open > pick the .ino file inside its folder.

SETUP (once)
- Board package: "esp32 by Espressif Systems"  -> board "Heltec WiFi LoRa 32(V3)"
- Libraries: RadioLib by Jan Gromes - use a 7.x version BELOW 7.7 (e.g. 7.1.2).
             Newer versions break these programs. Do not accept "update" prompts for it.
             ESP8266 and ESP32 OLED driver for SSD1306 displays (ThingPulse)
- Windows USB driver: Silicon Labs CP210x Universal Windows Driver
- Erase All Flash Before Sketch Upload: Disabled (normal uploads)

WHICH PROGRAM GOES ON WHICH BOARD
1. gate_receiver      - in the Mighty Mule box (relay to CYCL/COM, 12 V light, reed switch, battery sense)
2. gate_remote        - handheld remote (press PRG to open/close)
3. gate_bridge        - in the house on WiFi: http://gate.local (gate + garage sections), ntfy, alerts
4. garage_controller  - by the Genie 3055 opener: http://garage.local + ntfy
5. mailbox_node       - battery board in the mailbox: "You've got mail" alerts via the bridge
   OLED_Test          - optional, just checks a board's screen works

SETTINGS TO CHANGE (line numbers)
gate_receiver.ino
  line 24  SECRET_KEY         same phrase in gate_receiver, gate_remote and gate_bridge
  line 29  HAVE_REED_SWITCH   false until the gate reed switch is installed, then true
  line 30  LIGHT_ON_SECONDS   how long the 12 V light stays on after the gate closes
  line 31  REED_CLOSED_LEVEL  change LOW to HIGH if the light comes on when the gate OPENS
  line 35  HEARTBEAT_MIN      how often it checks in with the bridge (minutes)
  line 36  HAVE_BATTERY_SENSE true once the 2-resistor battery divider is fitted
  line 38  BATT_DIVIDER       adjust until the battery reading matches a multimeter
  line 44  RELAY_ON           change HIGH to LOW if the relays work backwards

gate_remote.ino
  line 14  SECRET_KEY         same phrase as the other two
  line 114 flipScreenVertically - add // at the start if the text is upside down

gate_bridge.ino
  line 32  SECRET_KEY         same phrase as the other gate programs and the mailbox node
  line 33  WIFI_SSID          your WiFi name (2.4 GHz)
  line 34  WIFI_PASS          your WiFi password
  line 35  NTFY_TOPIC         long random topic name, same on every phone
  line 36  PIN                PIN for open/close from ntfy
  line 38  GARAGE_URL         garage controller address (its reserved IP, e.g. http://192.168.1.59)
  line 40  FLIP_SCREEN        false if the text is upside down
  line 44  LOW_BATT_V         "Gate battery low" below this voltage
  line 45  GATE_OFFLINE_MIN   "Gate receiver not responding" after this many minutes
  line 46  WATCH_GARAGE       false = don't alert if the garage controller goes offline
  line 47  NIGHT_CHECK_HOUR   22 = 10 PM; -1 = off
  line 48  NIGHT_AUTO_CLOSE   true = close the gate at the night check instead of alerting
  line 49  MAIL_LOW_BATT_V    "Mailbox battery low" below this voltage
  line 50  MAIL_OFFLINE_HOURS "Mailbox sensor not responding" after this many hours

mailbox_node.ino   (5th board, battery powered, in or on the mailbox)
  line 26  SECRET_KEY         same phrase as the gate programs
  line 28  HEARTBEAT_HOURS    how often it checks in
  line 29  COOLDOWN_S         ignore the door this long after it closes
  line 30  VBAT_CTRL_ACTIVE   LOW for V3.0/V3.1 boards, HIGH for V3.2
  line 31  VBAT_DIVIDER       adjust until the battery reading matches a multimeter
  Wiring: reed switch between 3V3 and GPIO 7; 1 MOhm resistor between GPIO 7 and GND; LiPo on the battery connector

garage_controller.ino   (no SECRET_KEY - it does not use LoRa)
  line 25  WIFI_SSID          your WiFi name
  line 26  WIFI_PASS          your WiFi password
  line 27  NTFY_TOPIC         SAME topic as gate_bridge
  line 28  PIN                your PIN
  line 30  FLIP_SCREEN        false if the text is upside down
  line 35  HAVE_GARAGE_REED   true once the garage door reed switch is installed
  line 36  CLOSED_LEVEL       change LOW to HIGH if open/closed are reversed
  line 37  RELAY_ON           change HIGH to LOW if the relay works backwards
  line 39  LEFT_OPEN_MIN      minutes before "Garage left open" alert (0 = off)
  line 40  REMIND_EVERY_MIN   repeat the reminder this often
  line 41  NIGHT_CHECK_HOUR   22 = 10 PM; -1 = off
  line 42  NIGHT_AUTO_CLOSE   true = close the door at the night check instead of alerting

PHONE COMMANDS (ntfy, from anywhere: https://ntfy.sh/<your topic>)
  open 4821          open the gate          (use your own PIN)
  close 4821         close the gate
  open 4821 15       open the gate for 15 minutes, then close (needs reed switch)
  status             gate status (and battery)
  garage open 4821   open the garage
  garage close 4821  close the garage
  garage status      garage status

ALERTS
  Gate opened / closed (and by whom: remote, phone, timer, vehicle sensor / Mighty Mule)
  Gate 12 V light, timed open, night check (10 PM)
  Gate battery low, gate receiver not responding, garage controller not responding
  Garage opened / closed / left open, garage night check

BATTERY SENSE WIRING (gate receiver)
  Gate battery +  -> 100k resistor -> GPIO 4
  GPIO 4          -> 22k resistor  -> GND
  (Heltec GND must connect to battery -; most 12->5 V converters already do this.)

WIRING: see Gate_and_Garage_Wiring.pdf (page 1 gate, page 2 garage).
Relay pins: DC+ = VCC -> 5V, DC- = GND -> GND, IN -> GPIO 7. Use COM and NO.
GPIO numbers = the numbers printed beside the pins, not pin positions.
