# FirebaseOTA 3x6 wall unit

A wall-recessed replacement for a **3 x 6 double patress box** (146 x 86 mm
faceplate, 120.6 x 60.3 mm screw centres).  It holds a 130 x 70 mm carrier PCB,
a pre-made 30-pin ESP32 DevKit V1, a 0.96" OLED and a light-piped status LED.

The back can is **136 x 76 x 34 mm** and fits a **137 x 77 mm** wall opening.
The faceplate is 146 x 86 x 4 mm and sits flush on the wall.

![faceplate](preview/preview_face.png)
![exploded](preview/preview_exploded.png)

## What is in this folder

| Path | Purpose |
|---|---|
| `enclosure/patress_3x6.scad` | Parametric source for every printed part |
| `enclosure/render_stl.py` | Renders the previews from the exported STLs |
| `stl/patress_3x6_face.stl` | Faceplate, 146 x 86 x 23.5 mm |
| `stl/patress_3x6_back.stl` | Recessed can, 136 x 76 x 34 mm |
| `stl/patress_3x6_tray.stl` | DevKit clip tray + 2 left standoff posts, 46 x 65.4 x 18 mm |
| `stl/patress_3x6_pipe.stl` | Status-LED light pipe, 5.5 x 5.5 x 21.5 mm |
| `pcb/` | EasyEDA carrier board, BOM, CPL, netlist and checks |
| `preview/` | Rendered previews of the five printed parts and the stack |

The PCB is documented separately in [`pcb/README_RevA.md`](pcb/README_RevA.md).

## Printed parts and material

| Part | Material | Notes |
|---|---|---|
| Faceplate | PETG or ASA, white | 0.2 mm layers, 4 walls, 25 % infill |
| Back can | PETG or ASA, white | 0.2 mm layers, 4 walls, 20 % infill |
| DevKit tray | PETG, any colour | 0.2 mm layers, 4 walls, 20 % infill |
| Light pipe | Clear PETG or clear PLA | 0.12 mm layers, 100 % infill, no supports |

PETG is preferred for the wall parts: it is tougher than PLA in a warm wall
cavity and survives the occasional knock.  ASA is better if the wall gets
direct sun.  Do not use plain PLA for the back can if the box is on an
external wall.

### Orientation

* **Faceplate** - front face down on the bed.  The OLED window and the label
  frame bridge; no supports.
* **Back can** - open front up, back floor on the bed.  The wall-screw ears
  and the cable-tie posts print without supports.
* **Tray** - flat on the plate, rails and the two standoff posts up.  No
  supports; the posts are 7 mm diameter and 18 mm tall.
* **Light pipe** - flange on the bed, shaft vertical.  100 % infill so the
  light does not scatter.

Print the faceplate with a **brim** if your bed has poor adhesion; the part is
146 mm across and the 4 mm rim is the only first-layer contact.

## Hardware

| Item | Qty | Use |
|---|---:|---|
| M3 x 8 mm screw | 2 | Carrier PCB to the right-hand faceplate standoffs |
| M3 x 12 mm screw | 2 | Carrier PCB to the left-hand tray standoff posts |
| 3.5 x 12 mm countersunk screw + nut (M3 x 12 also fits) | 4 | Faceplate to the back-can ears |
| M3 heat-set insert (optional) | 4 | Alternative to the can-ear nuts |
| 3.5 mm wall plug (optional) | 4 | Only if you replace the can-ear fixing |
| M20 cable gland | 1 | Mains in / switched load out |
| M12 cable gland | 1 | Sensor or PZEM cable |
| 2 mm clear filament or 3 mm acrylic rod | 1 | Optional light-pipe alternative |

The faceplate has four **8 mm countersinks** at the patress centres.  The can
ears have **4.6 mm clearance holes**; fit a nut for the screw you use (M3 or
3.5 mm) on the back of each ear, or melt in an M3 heat-set insert before
assembly.  The faceplate screws pull the faceplate onto the can and clamp the
wall between them.

The carrier is fixed with four M3 x 8 screws into the faceplate standoffs at
**X +/-51, Y +/-21**.  The two left-hand screws also pass through the DevKit
tray ears, so the tray is trapped between the carrier and the standoffs.

## Assembly order

1. **Print and clean up** all four parts.  Ream the M3 holes and the light-pipe
   bore with a 3.4 mm drill turned by hand.  Test-fit the light pipe.
2. **Fit the can ears.**  Press an M3 nut into the back of each of the four
   ears, or fit a heat-set insert.  The nuts sit inside the can and are
   accessible before the carrier goes in.
3. **Build the carrier.**  Solder the carrier as described in the PCB README.
   Do not fit the DevKit yet.
4. **Fit the light pipe.**  Push the pipe through the faceplate from the room
   side.  The 5.5 mm flange seats in the 5.6 mm counterbore; a drop of clear
   cement or a friction fit holds it.  The 3 mm shaft passes through the
   3.4 mm hole.
5. **Fit the OLED panel.**  The bare 26 x 14 mm panel sits in the frame on the
   back of the faceplate, with the **FPC at the top** (towards the J3 header).
   The frame opening is 26.2 x 14.2 mm, so the panel is a light push fit.
   Secure it with a strip of 3M VHB or a small bead of neutral-cure silicone
   around the frame, not on the glass.  The FPC leaves through the 10 mm slot
   in the top of the frame.  The panel is normally supplied with the FPC at the
   bottom; fit it upside down and rotate the display 180 degrees in firmware.
6. **Fit the carrier.**  Offer the carrier up to the four standoffs.  Plug the
   OLED FPC into J3 first if the cable is short.  Fit the two right-hand M3 x 8
   screws.  Fit the tray over the two left-hand standoffs, then the two left
   screws through the tray ears and the carrier.
7. **Fit the DevKit.**  Solder the two 15-way female headers to the carrier (or
   use the sockets supplied with the DevKit).  Plug the DevKit in with the
   **antenna at the top** (towards the top of the faceplate) and the **USB at
   the bottom**.  The tray rails and snap tabs should hold the module.
8. **Flash the DevKit now.**  The USB socket faces the can floor and is not
   reachable through the faceplate.  Flash on the bench before the can goes on,
   or use OTA afterwards.  See *Flashing* below.
9. **Fit the can.**  Feed the mains and sensor cables through the glands
   first.  Slide the can over the carrier and locate it on the faceplate lip.
   Fit the four 3.5 x 12 (or M3 x 12) screws through the faceplate into the can ears and
   tighten evenly.  The faceplate should pull down flush.
10. **Wire and test** before the final wall fix.  Check the 5 V rail, the OLED,
    the LED and each relay.  Then isolate the mains and finish the install.

## Wall installation

1. **Cut the opening.**  137 x 77 mm, at least 38 mm deep.  Check for cables
   and pipes before cutting.  The can is 136 x 76 mm, so there is 0.5 mm
   clearance on each side; clean the cut edges so the can slides in.
2. **Pull the cables.**  Leave 250 mm of service loop.  Fit the M20 gland to
   the mains entry and the M12 gland to the sensor entry.
3. **Offer the can in.**  The can is a push fit in the opening.  The faceplate
   is larger than the opening and covers the cut edges.
4. **Fix the faceplate.**  Fit the four 3.5 x 12 (or M3 x 12) screws through the faceplate
   into the can ears.  For a permanent install, run a bead of acrylic sealant
   around the can behind the faceplate, or use two dabs of silicone on the
   can's side walls.  Do not use solvent cement on the printed parts.
5. **Check the flush fit.**  The faceplate is 4 mm thick and the bezel adds
   1.5 mm.  If the wall is textured, add a thin foam gasket behind the
   faceplate.

A standard double patress box uses 120.6 x 60.3 mm centres; the faceplate and
the can ears use the same centres so the unit can replace an existing box
without moving the fixing holes.

## Cable entries

The can has two entries in the back floor:

| Entry | Position (enclosure X, Y) | Size | Board cut-out (local x, y) |
|---|---|---:|---|
| Mains in / load out | `(34, -8)` | 20 mm | 20 mm at `(99, 43)` |
| Sensor / PZEM | `(15, -20)` | 12 mm | 12 mm at `(80, 55)` |

The carrier has matching non-plated cut-outs, so the cables can pass from the
back of the box to the front of the board:

* **Mains** - comes through the 20 mm gland and the 20 mm board cut-out, then
  runs **above the HLK-PM01** (around Y = +32) to J8 at the top of the board.
  Keep this cable away from the OLED and the relay headers.
* **Sensor / PZEM** - comes through the 12 mm gland and the 12 mm board
  cut-out, then runs **below the relay headers** and around the left edge of
  the tray to J2.

Pull the cables and fit the glands **before** the carrier and can are closed
up.  If you need a second load cable, use a two-cable M20 gland or drill a
second 20 mm entry in the can and a matching cut-out in the board; do not force
two thick cables through one gland.

## Mains wiring

> **Danger.** This unit carries 230 V AC.  Build and install it only if you are
> competent to work with mains.  Otherwise buy a certified smart relay.

J8 is the only mains connector:

| Pin | Net | Use |
|---:|---|---|
| 1 | `AC_L` | Mains live **in** |
| 2 | `AC_L_F` | Fused live **out** to the load |
| 3 | `AC_N` | Mains neutral **out** to the load |
| 4 | `AC_N` | Mains neutral **in** |

* Mains **in** goes to pins 1 and 4.
* The switched load goes to pins 2 and 3.
* The fuse (F1) is in series between pins 1 and 2.
* The MOV clamps L-N on the incoming side.
* Use a 500 mA slow-blow fuse for the HLK and a fuse sized for the load.
* Keep the mains wiring short, sleeved and mechanically secure.  Do not let
  it touch the low-voltage side, the OLED or the DevKit.
* The HLK-PM01 provides isolation, but the AC side is live at all times.

    The onboard Songle SRD-05VDC-SL-C relays (K1-K4) switch the mains load.
Pin 1 provides 5 V rail, Pin 2 is GND, and Pin 3 carries the GPIO signal
to the transistor base.  The actual power relays (K1-K4) are soldered onto
the carrier board; their coil pins connect to the 5 V rail and GND through
the transistor drivers, and their contact pins (COM/NO/NC) switch the mains
loads that are routed to the J9 switched-load terminal block.

## OLED panel

The enclosure is designed for a **bare 0.96" 26 x 14 x 1.5 mm I2C OLED panel**
with a 4-pin FPC, not the common 27.3 x 27.3 mm module.  The bare panel is what
lets the faceplate sit close to the HLK-PM01.

* Window: 24 x 12 mm; active area 21.7 x 10.9 mm.
* Frame opening: 26.2 x 14.2 mm; panel is a light push fit.
* FPC exits the **top** of the frame through a 10 mm slot.
* J3 pinout: `3V3`, `GND`, `GPIO21` (SDA), `GPIO22` (SCL).
* The panel is fitted upside down relative to the usual orientation, so set
  the display rotation to 180 degrees (or mirror both axes) in firmware.
* Check the flex pin order before soldering.  Bare panels are not all wired
  the same way; if in doubt, buzz the flex out with a meter.

The OLED is optional.  If you do not fit it, leave `oled = false` in the SCAD
to print a faceplate without the window and frame.

## Status LED and light pipe

The carrier has a 3 mm LED at local `(66, 44)`, which maps to enclosure
`(1, -9)`.  The faceplate hole is 3.4 mm with a 5.6 mm counterbore.  The light
pipe is 21.5 mm long: the flange sits in the counterbore and the rounded tip
stops 0.5 mm above the PCB, over the LED dome.  Print it in clear PETG at
100 % infill.

If the pipe is too tight, ream the faceplate hole with a 3.4 mm drill by hand.
If it is too loose, a drop of clear cement on the flange is enough.

## Flashing and USB access

The DevKit's USB socket faces the bottom of the can, so it is **not**
accessible through the faceplate.  Flash the board before the final assembly:

1. Fit the DevKit to the tray and carrier.
2. Connect USB on the bench and flash.
3. Unplug, fit the can, and wire the unit.
4. Use OTA for later updates.

If you need repeated USB access, print the faceplate with `oled = false` and
drill a 12 mm service hole in the can bottom wall in line with the USB socket,
or leave the can off during bench development.  A right-angle USB cable helps.

## Firmware notes

* The DevKit is a **30-pin DOIT ESP32 DevKit V1**.  The carrier pin map is in
  `pcb/NETLIST_RevA.md`; the antenna is at the top and USB at the bottom.
* Relay GPIOs: `GPIO25`, `GPIO26`, `GPIO27`, `GPIO32` (J4-J7).
* PZEM: `GPIO16` (RX) / `GPIO17` (TX) on J2.
* OLED: `GPIO21` (SDA) / `GPIO22` (SCL) on J3.
* The status LED is hard-wired to 5 V through R1; it is a power indicator, not
  a software-controlled LED.

## Known limitations (Rev A)

* The carrier is a **prototype**, not a certified mains product.
* The mains and sensor cables pass through cut-outs in the carrier.  Keep the
  mains cable on the top side and the sensor cable on the bottom side; do not
  bundle them together.
* The Songle SRD-05VDC-SL-C relays (K1-K4) are onboard with driver transistors; the PZEM remains an external module.  Check that they fit
  the can before closing it; the PZEM in particular is deeper than the space
  behind the carrier and is normally mounted outside the can.
* The OLED panel is a bare panel with a fragile FPC.  Strain-relieve the FPC
  with a small piece of tape on the frame.
* The wall fixing relies on the faceplate screws into the can ears.  For a
  heavy cable bundle or a ceiling installation, add an independent wall fixing.
* The STLs are ready to print, but the SCAD is the source of truth.  If you
  change a dimension, re-export all four parts and re-run the PCB checks.

## Rebuilding the models

```bash
# enclosure
cd enclosure
openscad -o ../stl/patress_3x6_face.stl -D 'part="face"' patress_3x6.scad
openscad -o ../stl/patress_3x6_back.stl -D 'part="back"' patress_3x6.scad
openscad -o ../stl/patress_3x6_tray.stl -D 'part="tray"' patress_3x6.scad
openscad -o ../stl/patress_3x6_pipe.stl -D 'part="pipe"' patress_3x6.scad
python3 render_stl.py

# carrier
cd ../pcb
python3 generate_easyeda.py
python3 check_board.py
python3 export_docs.py
python3 render_preview.py
```

`part="assembly"` is a preview only; do not print it.
