P4 Gateway P4 Gateway documentation

P4 Gateway documentation

Introduction

The P4 Gateway turns the Guition JC-ESP32P4-M3-DEV board into a LAN gateway for Home Assistant. The ESP32-P4 runs the gateway, the web UI and sound recognition; the ESP32-C6 in the module is the 2.4 GHz radio. One role runs at a time and is switched in the web UI, from Home Assistant or from Telegram.

RoleP4C6Home Assistant
Thread border routerOpenThread BR, REST on port 8081ot_rcpOpenThread Border Router + Thread integrations, Matter
Thread routerjoins an existing Thread networkot_rcpnothing, extends the mesh
Zigbee coordinatorUART–TCP bridge, port 6638ZBOSS NCPZigbee2MQTT, adapter: zboss
Zigbee routermonitor and commandsown router firmwarejoins by permit join
ESPHome BLE proxyESPHome imageesp-hostedESPHome integration

Independent of the role (except ESPHome): sound recognition with the onboard microphone (YAMNet, 521 sound classes), noise level in dB(A), notifications, user accounts and the Telegram bot.

Hardware

Module JC-ESP32P4-M3: ESP32-P4NRW32 (16 MB flash, 32 MB PSRAM) with an ESP32-C6. Inside the module the P4 and the C6 share only SDIO (used by the ESPHome role) and the C6 reset. Thread and Zigbee need a UART, which exists only on header JP1: three jumper wires (female–female dupont) are needed.

JP1 fromJP1 toPurpose
13 (P4 GPIO4, TX)20 (C6 U0RXD)UART P4 → C6
15 (P4 GPIO5, RX)22 (C6 U0TXD)UART C6 → P4
17 (P4 GPIO20)24 (C6 IO9 / BOOT)the P4 flashes the C6 through its ROM bootloader

Check pin 1 with a multimeter first (3.3 V against GND; pin 2 shows 5 V). Pin 26 stays free, the P4 drives the C6 reset inside the module. The ESPHome role works without jumpers.

USB-C next to the Ethernet jack: CH340, console and flashing (opening the port resets the board). Ethernet IP101 at 100 Mb/s; power over USB-C.

First installation

  1. Back up the factory flash of the P4 (it also holds the factory C6 app):
    scripts/backup_flash.sh /dev/cu.wchusbserial* esp32p4 backups/p4_backup.bin
  2. Wire the three JP1 jumpers (above).
  3. Flash the gateway: scripts/flash_p4.sh /dev/cu.wchusbserial* (the firmware comes from scripts/build_all.sh into dist/).
  4. Open http://p4gw-xxxxxx.local/ (the name ends with the last digits of the MAC). The gateway starts in maintenance mode.
  5. Radios › Status and maintenance › Back up C6 flash (about 3.5 min) and keep the file: it is the only copy of the factory C6 firmware.
  6. System › User management › Users › New user: the first account is the admin. From then on the gateway asks for sign-in.
  7. Role: choose the role. Zigbee roles flash the C6 (about 25 s), Thread roles take about 15 s.

Flash layout v3 (from v1.6): the P4 keeps only the small C6 bundles; the large C6 firmwares come from the release package, which the gateway downloads when the C6 needs them (or an upload of c6fw.bin). Boards with the older layout move once over USB: scripts/migrate_layout_v3.sh <port> (settings, Thread network, users and recordings stay).

Flash layout v4: gateway slots of 4 MB instead of 3 MB (the unused ESPHome slot is gone). Boards with layout v3 move once over USB: scripts/migrate_layout_v4.sh <port> (everything stays; --rollback <stamp> goes back).

Web UI basics

Header: status tags, outlined when the link works and grey when it is off. Point at a tag (or tap it) for details. From the left: LAN, the active role, its client (Zigbee2MQTT or Home Assistant over the OTBR REST API), the P4 Gateway integration (HA), MQTT and internet; on the right the uptime of the gateway with the Zigbee2MQTT session or the C6 uptime, and the gateway clock.

Menu on the left: sections and their pages; Thread, Zigbee and ESPHome are greyed out while no radio runs their network, and pages that need it do not open. At the bottom: language (flags), theme (system, light, dark), the signed-in user (My account, sign-out) and Restart, which after a confirmation resets the C6 radio and right after it the P4.

A page the account may only read shows a note and its buttons that change something are disabled. Hidden pages are not in the menu at all.

tip_lantip_roletip_peertip_hatip_mqtttip_internettip_uptime

Dialogs

login
Sign-in
dialog_wizard
Setup wizard (opens by itself without a user account, later from System › Information)
dialog_restart
Restart
dialog_new_user
New user
dialog_edit_user
Edit user with own permissions
dialog_totp
Two-factor sign-in setup
dialog_telegram_pair
Telegram pairing

Web UI pages

Overview

The state of the gateway at a glance. The diagram on top shows LAN, the main board, both radios and the network each radio serves; every node opens its page and shows its details on hover (chip, firmware, memory, network, traffic).

Main board: ESP32-P4

Firmware version, uptime, last reset, temperature, CPU load per core, internal RAM and PSRAM.

MAIN BOARD: ESP32-P4

LAN: Ethernet of the P4

Ethernet link, IPv4 and IPv6 addresses, MAC, hostname.

LAN: ETHERNET OF THE P4

Radio a: esp32-c6 · internal

Role and its network, the firmware of the radio, its MAC, temperature, memory and uptime (telemetry of the role firmware).

RADIO A: ESP32-C6 · INTERNAL

Radio b: esp32-c5 · external, jp1

With a radio B on JP1: the same for it; details under Radios › Status and maintenance.

RADIO B: ESP32-C5 · EXTERNAL, JP1
Whole page (1)
Overview
Whole page

Data flows

Where the data of each network and service goes and who receives it: sources (Thread, Zigbee and Bluetooth devices, the microphone), the services of the gateway and the consumers (Home Assistant, Zigbee2MQTT, MQTT broker, Telegram, web UI and API).

Data flows

Three columns linked by lines coloured by state (flows, waiting, off). A node opens its settings; hovering it lists every flow through it with the way (protocol, port) and the traffic.

DATA FLOWS

Every flow

The same as a table: from, to, way, state, traffic since start and now, a link to the settings.

EVERY FLOW
Whole page (1)
Data flows
Whole page

Radios › Roles

Choose what each radio does: radio A is the C6 of the board, radio B the optional XIAO ESP32-C5 on JP1. At most one Thread network, one Zigbee network and one ESPHome proxy; switching restarts the gateway, each radio keeps its own networks.

Roles of the radios

A row per role and a column per radio: active, selected (switch pending), on radio B/A (the other radio runs that network) or Switch; the last row switches radio B off. The switch above the table shows the same as a list or as tiles (remembered in the browser).

ROLES OF THE RADIOS

How to

  1. Pick the role of a radio and press Switch.
  2. The gateway restarts; a dialog shows the progress (a radio is flashed when its role needs other firmware).
  3. Set up the network on its page (Thread, Zigbee, ESPHome) and Home Assistant as shown under Home Assistant › Integration.

Also possible: the Role and Radio B role selects of the P4 Gateway integration, Telegram /role zigbee_coordinator or /role b thread_br, MQTT p4gw/<host>/role/set (radio A).

Whole page (1)
Radios › Roles
Whole page

Radios › Status and maintenance

Both radios: radio A (the C6 of the board) and radio B (the external radio on JP1, docs/dual-radio.md).

Radio A (C6 of the board)

Chip, role, package and the C6 details (MAC, revision, flash, temperature, memory, firmwares stored for it); Forget Thread network (not while it runs Thread), Reflash C6 now (after an RCP or NCP failure) and Back up C6 flash (in maintenance mode, about 3.5 min).

RADIO A (C6 OF THE BOARD)

Radio B (external, JP1)

Chip, role, firmware and package, temperature and free memory, the wiring and Test wiring (resets the radio, only while it has no role): it names the line to check when one does not work.

RADIO B (EXTERNAL, JP1)

How to

Radio B: XIAO ESP32-C5 on JP1 (GPIO32 TX, GPIO33 RX, GPIO46 reset, GPIO47 boot, GND), powered over its own USB-C (5 V from JP1 is too weak for its radio).

Whole page (1)
Radios › Status and maintenance
Whole page

Radios › Radio surroundings

Scan of the 2.4 GHz band to place a Thread, Zigbee or Wi-Fi network.

Scan

Quick (Thread roles, no outage, about 13 s) or full (any role, about a minute without the role).

SCAN

Recommendation

Best channels for Thread and Zigbee.

RECOMMENDATION

2.4 GHz spectrum

Wi-Fi and 802.15.4 channels together.

2.4 GHZ SPECTRUM

5 GHz spectrum

Wi-Fi networks in the 5 GHz band (full scan on an ESP32-C5).

5 GHZ SPECTRUM

IEEE 802.15.4 channels

Energy, networks and rating per channel 11–26.

IEEE 802.15.4 CHANNELS

Thread and Zigbee networks

Networks found nearby.

THREAD AND ZIGBEE NETWORKS

Wi-Fi networks

Access points with channel and signal (full scan).

WI-FI NETWORKS
Whole page (1)
Radios › Radio surroundings
Whole page

Thread › Information

State of the Thread network (Thread roles only).

Thread

Role in the network (leader, router, child), network name, channel, PAN ID, addresses.

THREAD

Border routing

Prefixes routed to the LAN (OMR), NAT64, SRP server and the last contact of Home Assistant.

BORDER ROUTING
Whole page (1)
Thread › Information
Whole page

Thread › Topology

Map of the mesh: routers and their children, link quality; device names from the Matter Server when available.

Network map

Ring or signal layout (shorter edge = better link), zoom and pan; point at a node for details.

NETWORK MAP

Devices in the network

Matter devices with vendor, product and firmware.

DEVICES IN THE NETWORK

Neighbors

Direct neighbours of the gateway with RSSI and link quality.

NEIGHBORS

Routers

All routers of the partition.

ROUTERS
Whole page (1)
Thread › Topology
Whole page

Thread › Diagnostics

The radio co-processor and the OpenThread command line.

Radio co-processor (RCP)

RCP version and failures; after a failure the gateway reflashes the C6 by itself.

RADIO CO-PROCESSOR (RCP)

MAC counters

Frames sent and received, retries and errors.

MAC COUNTERS

OpenThread CLI

Commands of the OpenThread CLI, e.g. state, neighbor table, ping.

OPENTHREAD CLI
Whole page (1)
Thread › Diagnostics
Whole page

Thread › Settings

Dataset of the network and transmit power.

Network dataset

Name, channel, PAN IDs; the network key and TLVs only on request. Apply dataset joins another network.

NETWORK DATASET

Transmit power

-15 to 20 dBm, kept across restarts.

TRANSMIT POWER

How to

Join the preferred network of Home Assistant (one Thread network instead of two):

  1. Home Assistant: Settings › Devices & services › Thread › (network) › show the active dataset TLVs and copy them.
  2. Gateway: Thread › Settings › paste into Apply dataset and confirm.
Whole page (1)
Thread › Settings
Whole page

Zigbee › Information

The coordinator bridge, or the router and its network (Zigbee roles only).

Coordinator bridge

TCP port 6638 for Zigbee2MQTT, the connected client and the session.

COORDINATOR BRIDGE
in the Zigbee coordinator role

Zigbee router

Router state, parent, channel and PAN.

ZIGBEE ROUTER
in the Zigbee router role

Network membership

Join network (steer) after permit join in the coordinator; leave or factory reset.

NETWORK MEMBERSHIP
in the Zigbee router role

Transmit power

Transmit power of the router.

TRANSMIT POWER
in the Zigbee router role
Whole page (2)
Zigbee › Information
Whole page · in the Zigbee coordinator role
Zigbee › Information
Whole page · in the Zigbee router role

Zigbee › Network and devices

The Zigbee network seen through Zigbee2MQTT over MQTT (works in any role).

Zigbee2MQTT

Base topic and bridge state; needs the MQTT connection of the gateway.

ZIGBEE2MQTT

Permit join

Open the network for new devices for a while.

PERMIT JOIN

Network map

Network map from Zigbee2MQTT with link quality.

NETWORK MAP

Zigbee devices

Devices with model, power source and last seen.

ZIGBEE DEVICES
Whole page (2)
Zigbee › Network and devices
Whole page
Zigbee › Network and devices
Whole page · in the Zigbee coordinator role

Zigbee › Network backups

Copies of the coordinator and router network data kept in the gateway flash; made before leaving a Zigbee role and automatically (daily or weekly).

Zigbee network backups

Radio, generation, size and time of each copy; download; Back up now (while a radio runs Zigbee). The page opens in any role.

ZIGBEE NETWORK BACKUPS
Whole page (1)
Zigbee › Network backups
Whole page

Zigbee › Diagnostics

Traffic of the bridge and the C6 link.

Traffic

Bytes and frames between Zigbee2MQTT and the NCP, dropped data.

TRAFFIC
in the Zigbee coordinator role

C6 link

UART speed, errors and C6 resets; Reset C6.

C6 LINK
in the Zigbee coordinator role

Zigbee router

Router counters and log.

ZIGBEE ROUTER
in the Zigbee router role
Whole page (2)
Zigbee › Diagnostics
Whole page · in the Zigbee coordinator role
Zigbee › Diagnostics
Whole page · in the Zigbee router role

ESPHome

The ESPHome Bluetooth proxy as the role of a radio: it runs on the radio itself over Wi-Fi while the gateway keeps working with the other radio. Greyed in the menu while no radio runs it; the Wi-Fi can be set beforehand.

ESPHome BLE proxy on a radio

The steps: Wi-Fi, role, adoption in Home Assistant.

ESPHOME BLE PROXY ON A RADIO

Wi-Fi of the ESPHome radio

SSID and password the gateway sets over Improv on the radio's UART when the role starts (the password is a secret setting), and the state of the ESPHome radio: Improv state, device, URL.

WI-FI OF THE ESPHOME RADIO

How to

The image comes from the release and holds no secret: no access point, Home Assistant sets the API encryption key when it adopts the device.

Whole page (1)
ESPHome
Whole page

Sound › Live

Microphone, noise level and the recognition model.

Microphone

On or off, gain, level gate (the model runs only above it), live level, a 5 s recording.

MICROPHONE

Noise level

A-weighted level LAS, LAeq and LAmax over 60 s in dB(A). Calibrate: enter the reading of a sound level meter.

NOISE LEVEL

Sound recognition (YAMNet)

Recognition on or off, run time and CPU share of the model, model upload.

SOUND RECOGNITION (YAMNET)

Heard now

Top classes of the last windows with their scores.

HEARD NOW

How to

Calibrate the noise level: put a sound level meter (or a phone app) next to the gateway, set it to A-weighting and slow, wait for a steady sound and enter its reading under Noise level › Calibrate. Without calibration the level is an estimate (±6 dB).

Whole page (1)
Sound › Live
Whole page

Sound › Events

Groups of sound classes sent to Home Assistant as events (dog barking, doorbell, glass breaking, smoke alarm…).

Events sent to Home Assistant

Presets (household, security, animals, minimal), each event with classes, threshold, windows, hold and cooldown; edit, add, export and import.

EVENTS SENT TO HOME ASSISTANT

How to

  1. Pick a preset or press Add event.
  2. Choose the classes (Sound selection shows all 521), threshold (0.5 to start) and timing.
  3. Save: Home Assistant gets an event entity and a binary sensor per enabled event.
Whole page (1)
Sound › Events
Whole page

Sound › Detection log

Last detections with class, score, level and duration.

Detection log

Filter by event; a row shows which class triggered it.

DETECTION LOG
Whole page (1)
Sound › Detection log
Whole page

Sound › Sound selection

All 521 AudioSet classes as a tree; excluded classes never trigger anything.

All sounds

Search, Czech names, the events that use a class.

ALL SOUNDS
Whole page (1)
Sound › Sound selection
Whole page

Sound › Learned sounds

Own sounds the model does not know: recorded samples and a profile (embedding similarity or a tone).

Record

Record 0.96 s samples of the sound, or upload a WAV.

RECORD

Background

Record the normal background; the suggested threshold lies between it and the samples.

BACKGROUND

Learned sounds

Profiles with samples, threshold and test.

LEARNED SOUNDS
Whole page (1)
Sound › Learned sounds
Whole page

Home Assistant › Integration

Steps for Home Assistant with the current address of the gateway; one-click buttons for the integration.

P4 Gateway integration

Open the HACS repository, add the integration (My Home Assistant buttons).

P4 GATEWAY INTEGRATION

Thread border router → Home Assistant

OTBR integration URL, Thread and Matter steps.

THREAD BORDER ROUTER → HOME ASSISTANT

Zigbee coordinator → Zigbee2MQTT (recommended)

Zigbee2MQTT configuration.

Whole page (2)
Home Assistant › Integration
Whole page
Home Assistant › Integration
Whole page · in the Zigbee coordinator role

Home Assistant › MQTT

Optional MQTT link with Home Assistant discovery (the integration does not need it).

MQTT (optional)

Broker URI (mqtt://, mqtts://, ws://, wss://), user, password, TLS certificate, advanced options; state and last error.

MQTT (OPTIONAL)

How to

With the P4 Gateway integration in use, turn off Home Assistant discovery here, otherwise every entity exists twice. MQTT is still needed for Zigbee › Network and devices (Zigbee2MQTT topics).

Whole page (1)
Home Assistant › MQTT
Whole page

Home Assistant › Matter

Home Assistant found in the network and the Matter Server that names the devices in the Thread map.

Home Assistant and Matter

Home Assistant found over mDNS; Matter Server URL for device names in the Thread map.

HOME ASSISTANT AND MATTER
Whole page (1)
Home Assistant › Matter
Whole page

System › Information

Hardware and firmware details.

Firmware slots

Gateway A/B, ESPHome: version, state, which runs and which boots.

FIRMWARE SLOTS

ESP32-P4

Chip revision, CPU, temperature, flash and PSRAM.

ESP32-P4

Memory

Internal RAM and PSRAM, minimum since start, NVS.

MEMORY

Firmware

Version, build, ESP-IDF, reset reason.

FIRMWARE
Whole page (1)
System › Information
Whole page

System › LAN

Ethernet settings and traffic, device name and time.

LAN settings

DHCP or a static address with netmask, gateway and DNS; link speed and duplex.

LAN SETTINGS

Current state

What is in effect now.

CURRENT STATE

Device name

Hostname (applies after a restart); the gateway answers as <name>.local.

DEVICE NAME

Time

Gateway time, last sync and the state of each NTP server; up to three servers and the time zone of the gateway (a listed zone or a POSIX rule). The zone holds for the whole gateway: times in the web UI and the log, Telegram quiet hours, the nightly Zigbee backup.

TIME

Traffic

RX/TX rate, totals since start and the split per service (web UI, OTBR REST, Zigbee2MQTT, MQTT, mDNS, DNS/NTP, HTTPS, Thread routed).

TRAFFIC

How to

  1. Choose Static, fill in the address, netmask, gateway and DNS, press Apply.
  2. The page opens on the new address; confirm the banner within 120 s. Without confirmation the previous settings come back by themselves.
  3. Zigbee2MQTT uses the address: change it there too. The P4 Gateway integration finds the new address over mDNS.
Whole page (1)
System › LAN
Whole page

System › Wi-Fi

The Wi-Fi uplink: a radio with the role Wi-Fi uplink connects the gateway to the home Wi-Fi, as its only connection or as a backup of the LAN.

Wi-Fi settings

Network (with a scan), password, DHCP or a static address.

WI-FI SETTINGS

Current state

Which radio runs the uplink, its address, signal and whether it carries the traffic.

CURRENT STATE

Traffic over Wi-Fi

Rates and totals per service, like System › LAN.

TRAFFIC OVER WI-FI
Whole page (1)
System › Wi-Fi
Whole page

System › Hardware

I2C sensors on connector CN3 (or JP1): scan, recognition, names and what goes to Home Assistant.

I2C bus (GPIO7 SDA, GPIO8 SCL)

Wiring of CN3 and JP1, the codec on the bus and Scan the bus.

I2C BUS (GPIO7 SDA, GPIO8 SCL)

Found on the bus

Every address that answered: the configured sensor, a choice of chips when several fit (✓ sure), or what the address usually is.

FOUND ON THE BUS

Sensors

Name (shown in Home Assistant), chip, address, current values, state, Expose and Enabled; the read interval.

SENSORS

Add manually

Address and type for a sensor the scan cannot settle.

ADD MANUALLY

Supported sensors

24 chip families with their addresses (sensors.md).

SUPPORTED SENSORS

How to

  1. Connect the sensor to CN3 (1 GND, 2 3.3 V, 3 SCL, 4 SDA) with the gateway off and start it.
  2. The start scans the bus and adds what it recognises; Scan the bus does it again. For a chip the scan cannot tell apart pick it under Found on the bus and press Add.
  3. Give it a name and Save. The P4 Gateway integration shows its values as sensors; MQTT does too with the group I2C sensors.
Whole page (1)
System › Hardware
Whole page

System › GPIO (JP1)

Free pins of header JP1 as inputs, outputs, PWM, pulse counters, a UART-TCP bridge, a second I2C bus, 1-Wire temperatures or a WS2812 LED strip, set up and controlled from the page.

Header JP1

All 26 pins: power, radio pins locked with the reason (hover), free pins in green, configured ones in blue with their value. 3.3 V logic, not 5 V tolerant, about 20 mA per pin.

HEADER JP1

Pin settings

Name for Home Assistant, mode and its options: pull resistor, inverted, debounce (input), open drain and the state after a restart (output, PWM), frequency (PWM), edges and glitch filter (counter).

PIN SETTINGS

Configured pins

Live values; switch an output or pulse it for 1 s, move a PWM duty, clear a counter, set a strip's colour, brightness and effect, search a 1-Wire bus; the UART bridge shows its client and bytes (gpio.md).

CONFIGURED PINS

How to

  1. Wire the circuit with the gateway off; a relay or a LED strip goes through a transistor or a driver module, a relay with a pull-down (pins are off for 1-2 s after power on).
  2. Click a free (green) pin, name it, choose the mode and its options, Save.
  3. Switch or watch it in Configured pins; Free the pin turns it off again.
Whole page (1)
System › GPIO (JP1)
Whole page

System › RS485

Modbus devices on RS485 (connector J4) and Modbus TCP, from templates: values, writes, search, own templates.

RS485 bus

Wiring and the bus settings (baud rate, parity, stop bits, timeout) shared by all RS485 devices; request statistics.

RS485 BUS

Add a device

Template, name, connection (RS485, Modbus TCP, GoodWe UDP, or Emulation: a virtual device showing the values of another device as this template's device) with its address or source, read interval and how Home Assistant shows it (integration, MQTT, both, none).

ADD A DEVICE

Devices

State, main values, Home Assistant and enable per device; the arrow shows every value with controls for the writable ones. A virtual device says what it emulates and how many of its values come from the source; opened, where each value comes from.

DEVICES

Find devices

Tries every address (and baud rates) with a read of a template.

FIND DEVICES

Manual request

Reads or writes registers; shows them as u16, s16, u32 and float32 in both word orders.

MANUAL REQUEST

Templates

Built-in and own templates: export, copy as a new one, edit with a check, import, delete (modbus.md).

TEMPLATES

How to

  1. Connect A and B of the bus to J4 (and GND), set the bus to the devices' baud rate.
  2. Pick the template, the device's address and a name, press Add; not sure about the address: Find devices.
  3. The integration shows the device as its own device in Home Assistant; for MQTT choose it per device and allow the group Modbus devices.
  4. No template for your device: copy a similar one, edit the registers (the manual request helps) and save.

Emulation (a client that accepts only a certain meter, e.g. an inverter or a Victron GX expecting an ABB B23 while an Eastron SDM630 is connected): Add a device, template ABB B23 / B24, connection Emulation, the SDM630 as the source; then offer it under System › Modbus TCP server. Matching quantities are taken over, units converted, totals summed from the phases; it is read only (modbus.md).

Whole page (1)
System › RS485
Whole page

System › Modbus TCP search

Finds Modbus TCP devices and GoodWe Wi-Fi modules in a network and adds a recognised one in one click.

Search the network

Network (up to /22, default the gateway's), ports, unit ids to ask and GoodWe modules on UDP 8899. Only reads; the Modbus devices keep being read. A /24 takes about 20-60 s.

SEARCH THE NETWORK

Found

Every address that answered: Victron GX (with its VE.Bus unit) and GoodWe recognised by the serial number, other devices with the unit and the answer. Add adds the device with its template, RS485 opens it in the add form and the manual request (modbus.md).

FOUND

How to

  1. Enable Modbus TCP on the device (Victron GX: Settings › Integrations › Modbus TCP server).
  2. Check the network and press Search.
  3. Press Add at the recognised device; it appears under System › RS485 › Devices. An unknown device: RS485 and pick or write a template.
  4. A GoodWe Wi-Fi module (XS, MS, D-NS) answers only on UDP 8899: keep GoodWe dongles on UDP 8899 checked, it is added on connection GoodWe UDP with unit 127.
Whole page (1)
System › Modbus TCP search
Whole page

System › Modbus TCP server

Offers the gateway's Modbus devices to other Modbus TCP clients in the network (Victron, SCADA, a PLC, a vendor app).

Devices in the network

The shared port (default 502) and the devices offered: unit id there (0: not there), own port (any unit id reaches the device; for clients fixed to unit 1 or 255), requests per second to the device, cache time (how long an answer to a client serves the next ones; 0: every read to the device), writes and the addresses allowed to write (empty: anyone in the network).

DEVICES IN THE NETWORK

State

Every port with its clients, and per device the requests answered from the cache, sent to the device, refused (over the rate: exception 6, a write not allowed: 1) and failed (no answer: 11).

STATE

How to

  1. Add the device under System › RS485 first (RS485, Modbus TCP or GoodWe UDP).
  2. Add a device, choose it, give it a unit id on the shared port and/or an own port, Save.
  3. Point the client to the gateway's address, port 502 with that unit id (or the own port).
  4. Values the gateway reads anyway come from its cache within the read interval, answers to clients for the cache time; the same read of two clients goes to the device once. Other registers go to the device, at most the set rate. The RS485 bus manages about 10-20 requests a second for everything (modbus.md).
  5. Modbus TCP has no sign-in: switch writes on only where needed and list the client's address.
  6. A virtual device (emulation) answers every read from its values in the format of its template; no read reaches its source, writes are refused (exception 1), its source offline answers exception 11.
Whole page (1)
System › Modbus TCP server
Whole page

System › Firmware › Online update

Updates from the manifest (by default the latest GitHub release), older releases (rollback).

Online update

Installed and offered version of the gateway firmware and of the C6 package with their state and Install; Check reads the manifest now. Firmwares in the C6 package lists every C6 firmware installed and offered.

ONLINE UPDATE

Update settings

Manifest URL: GitHub Releases fills in the address of the latest release (the default), your own web server works too; saved empty turns the online update off. Checked every 6 hours, nothing is installed without a request.

UPDATE SETTINGS

Releases for this gateway

Releases that run on the flash layout of the board, one expandable row each with its notes, build and link: Gateway and C6 install that release (an older one is a rollback), Reflash writes the installed one again.

RELEASES FOR THIS GATEWAY

How to

  1. Install the gateway first when both are newer: a C6 package of a newer format is offered only to a gateway that reads it.
  2. C6 package: the gateway downloads it into RAM, checks its sha256 against the manifest, stores it and restarts; the C6 then gets the new firmware (about 2 minutes without Thread or Zigbee).
  3. Rollback: open Releases for this gateway and press Gateway or C6 at an older release. Settings stay; functions added later are missing until the next update.

Also from Home Assistant (Firmware and C6 radio firmware update entities, update.install with version) and Telegram (/update, /releases, /install, /install c6, /install v1.6).

Whole page (1)
System › Firmware › Online update
Whole page

System › Firmware › Manual update

Uploads without internet.

Manual update

p4gw.bin (written to the other slot, confirmed after 60 s, otherwise rolled back) and a radio package, c6fw.bin or c5fw.bin (the radio of its chip gets the new firmware on the next start; also when the gateway asks for it).

MANUAL UPDATE

How to

The files come from a GitHub release or from scripts/build_all.sh.

Whole page (1)
System › Firmware › Manual update
Whole page

System › Maintenance and backup

Restart and the settings backup; maintenance of the radios is under Radios › Status and maintenance.

Maintenance

Restart (radio A, then the P4).

MAINTENANCE

Settings backup

Export and import of all settings; passwords, accounts and tokens only when chosen.

SETTINGS BACKUP
Whole page (1)
System › Maintenance and backup
Whole page

System › Diagnostics

Tools when something does not work.

Ping

Ping a host from the gateway.

PING

Diagnostics

Core dump after a crash (download, erase), log before the last restart.

DIAGNOSTICS

Log

Live log with filters by source, level and tag; save to a file.

LOG
Whole page (1)
System › Diagnostics
Whole page

System › API

The HTTP API of the gateway (the same description as the HTTP API chapter, served by the gateway at /api/help).

Getting started

From the token to the first call: where to create a token, a field that fills it into the examples (kept only in that browser tab), the address of this gateway.

GETTING STARTED

Endpoints

Every endpoint with its permission, parameters, body, response, errors and effects, and examples for curl, Python and a Home Assistant rest_command built for this gateway; Try it runs a GET request at once.

ENDPOINTS
Whole page (1)
System › API
Whole page

System › Notifications

The Telegram bot (admins) and where Home Assistant notifications are set.

Telegram bot

Token from @BotFather, on/off; state and paired users. Quiet hours use the gateway time zone (System › LAN › Time).

TELEGRAM BOT

Home Assistant

The integration gets every notification; levels per topic are set in its options.

HOME ASSISTANT

How to

  1. Telegram: open @BotFather, send /newbot, choose a name and a user name ending with bot.
  2. Paste the token here, tick Bot on, save. The state turns to running, @yourbot.
  3. Every user pairs a chat in My account › Telegram and notifications.
Whole page (1)
System › Notifications
Whole page

System › User management › Users

Accounts of the web UI (admins only).

Users

Name, role, 2FA, state (active, locked, disabled, must change the password), last sign-in, sessions; New user, Edit, delete.

USERS

How to

  1. New user: name, role and a temporary password (generated); the user changes it at the first sign-in.
  2. Edit: role, disable, new password, turn off 2FA (lost phone), unlock, and own permissions page by page instead of the role.

Admins always have every right; the last admin cannot be removed or demoted.

Whole page (1)
System › User management › Users
Whole page

System › User management › Roles and permissions

What the user and viewer roles see and may change, page by page: hidden, read or edit. The gateway enforces it for every API call.

Roles and permissions

Matrix of pages × roles; Defaults returns the default levels.

ROLES AND PERMISSIONS
Whole page (1)
System › User management › Roles and permissions
Whole page

System › User management › API tokens

Tokens for Home Assistant and scripts (Authorization: Bearer p4gw_…), each with a role; shown only once.

API tokens

Name, role, created, last use; New token, Revoke.

API TOKENS
Whole page (1)
System › User management › API tokens
Whole page

System › User management › Reset requests

Requests sent from the sign-in page (Forgot password); admins also get a notification.

Password reset requests

Set password (temporary, changed at the next sign-in) or Dismiss.

PASSWORD RESET REQUESTS
Whole page (1)
System › User management › Reset requests
Whole page

System › User management › Security

Rules of the sign-in.

Sign-in security

Sign-out after inactivity, how long "Stay signed in" lasts, minimum password length, attempts before a lock and its duration, two-factor sign-in required per role.

SIGN-IN SECURITY
Whole page (1)
System › User management › Security
Whole page

My account

Own account: password, two-factor sign-in, Telegram and notifications, periodic reports.

Account

Change password (other sessions end), sign out other sessions.

ACCOUNT

Two-factor sign-in

Set up with Google Authenticator (or another TOTP app) and 10 recovery codes.

TWO-FACTOR SIGN-IN

Telegram and notifications

Pair a chat, level per topic, quiet hours, language of the bot, test message.

TELEGRAM AND NOTIFICATIONS

Periodic reports

Up to 4 reports to the own chat: name, devices (Modbus, virtual ones too, I2C sensors, GPIO; only those the account may read), every 15 min to 7 days or own minutes, from a time of day (7 days: a weekday), on/off; Preview, Send now, the next report.

PERIODIC REPORTS

How to

Two-factor sign-in: Set up › scan the QR code › enter the 6-digit code › keep the recovery codes (each signs in once instead of the app code).

Telegram: Pair › open the link in Telegram and press Start (or send /start <code>). Then set the levels per topic and save.

Periodic reports: Add a report › tick the devices, choose the period and the time › Save. A report holds the current values, the minimum, maximum and average of measured values and the difference of counters (energy, pulses) over the period; the counters' start values survive a restart. In quiet hours it comes without sound (notifications.md).

Whole page (1)
My account
Whole page

Home Assistant

P4 Gateway integration

  1. Install: Open HACS repository (Home Assistant › Guide) or copy custom_components/p4gw to /config/custom_components/; restart Home Assistant.
  2. The gateway appears under Settings › Devices & services › Discovered (mDNS _p4gw._tcp), or add it: Add integration › P4 Gateway › address.
  3. With user accounts on the gateway it asks for an API token: create one under System › User management › API tokens (role admin, or user when the integration should not restart or update) and paste it. The token does not depend on any user or their 2FA.
  4. Configure (integration options): per topic from which level a persistent notification appears (off, critical only, warnings and critical, all).

Entities: active role, Thread state, noise and noise max in dB(A), role select, sound recognition switch, one event and binary sensor per sound event, Notification event (for automations), firmware update and C6 radio firmware update, restart, identify, Zigbee backup and update check buttons, diagnostic sensors. Devices of their own, connected via the gateway: each Modbus device set to integration (System › RS485) with the entities of its template, a virtual device (emulation) with its sensors only, the I2C sensors (System › Hardware) and <host> GPIO with the pins set to integration (System › GPIO). Through MQTT instead: choose MQTT per device and allow its discovery group.

Thread and Matter

  1. Settings › Devices & services › Add integration › OpenThread Border Router, URL http://<gateway>:8081.
  2. Thread › Configure: mark the network as preferred, or join the gateway to the existing network (Thread › Settings › Apply dataset).
  3. Phone: Companion app › Sync Thread credentials. Matter: Matter Server add-on, Add device › Matter.
  4. Network: IPv6 and router advertisements on the Home Assistant host, no multicast filtering between Home Assistant and the gateway.

Zigbee2MQTT

serial:
  port: tcp://<gateway>:6638
  adapter: zboss
advanced:
  transmit_power: 20

One TCP client at a time. ZHA cannot use this coordinator (no ZBOSS support in Home Assistant).

ESPHome BLE proxy

Role › ESPHome BLE proxy; Home Assistant discovers the ESPHome node, enter its API key. Back with the Gateway role select and Return to gateway.

Telegram bot

CommandWhat it doesRightConfirmation
/helpcommands the account may use––
/statusrole, LAN, internet, MQTT, uptime, temperatureOverview, read–
/lanlink, addresses, trafficSystem › LAN, read–
/thread, /zigbeestate of the roleInformation, read–
/noisenoise in dB(A)Sound › Live, read–
/eventslast detectionsSound › Detection log, read–
/modbus, /sensors, /gpiovalues of the Modbus devices, I2C sensors, GPIO pinsSystem › RS485 / Hardware, read–
/updategateway and C6 versions, build, release notesSystem › Firmware, read–
/releasesreleases this gateway can install (rollback)System › Firmware, read–
/install, /install c6, /install v1.14install the gateway firmware or the C6 package, or a listed releaseSystem › Firmware, edityes
/restartrestart C6 and P4Radios › Status and maintenance, edityes
/identifyblink the identify iconOverview, edityes
/role <name>switch the roleRole, edityes
/sound on|offsound recognitionSound › Live, edityes
/mute 1hmute sound notifications (30m, 1d, off)––

Confirmation: Confirm / Cancel buttons (2 minutes); for an account with two-factor sign-in the bot then asks for the authenticator code — send it as a normal message. Notifications arrive within about 5 s; security ones only to admins; in quiet hours only critical ones. Periodic reports of chosen devices: My account › Periodic reports.

HTTP API

A gateway without any user account is open: no sign-in is needed and every endpoint works (create the first admin with POST /api/users). Once an account exists, every endpoint except /api/help, /api/auth/state, /api/auth/login and /api/auth/reset-request needs one of three proofs, tried in this order: an API token sent as Authorization: Bearer <token> (an admin creates it in System > User management > API tokens, or with POST /api/tokens, and it has the role chosen then), HTTP Basic with user name and password (for clients of older versions; works only for users without two-factor sign-in), or the session cookie p4s that POST /api/auth/login sets for the web UI. Missing or wrong credentials give 401; insufficient rights give 403 forbidden; an account that must change its password or set up two-factor gets 403 password_change_required or totp_setup_required. Each endpoint's perm is the page of the web UI it belongs to and level 1 (read) or 2 (edit); GET needs the read level, other methods edit, admin means admins only, public means no sign-in, * means any signed-in user, self means the own account. All errors are JSON {"error": "message"}; successful replies are JSON unless noted.

Base URL http://<gateway> (its address or p4gw-xxxxxx.local), JSON in and out, errors as {"error": "…"} with 400, 401, 403 or 409. The web UI of each gateway (System › API) shows the same reference with examples built for that gateway (its address, your token, its radios) and tries GET requests at once.

curl -s -H 'Authorization: Bearer p4gw_…' http://192.168.1.10/api/status

Status and system

PathWhat it doesPermission
GET/api/helpThis API description (the content of api.json), no sign-in needed.no sign-in
POST/api/identifyMakes the identify icon blink in the web UI header, to find the gateway.
body
{
  "seconds": 10
}
overview · edit
GET/api/statusFull gateway state: firmware, uptime, memory, roles of both radios, Ethernet, flash slots, radio firmware, hardware, update and link state.signed in
GET/api/wsWebSocket push channel for Home Assistant: the gateway sends text frames, frames from the client are read and dropped.signed in

Sign-in and own account

PathWhat it doesPermission
POST/api/auth/loginSigns in and sets the session cookie p4s (HttpOnly, SameSite=Strict).
body
{
  "user": "jiri",
  "password": "secret-password",
  "code": "123456",
  "remember": true
}
no sign-in
POST/api/auth/logoutEnds the current session and clears the cookie.own account
GET/api/auth/meThe signed-in identity with its page levels.own account
POST/api/auth/passwordChanges the own password.
body
{
  "old": "old-password",
  "new": "new-password-123"
}
own account
POST/api/auth/reset-requestAsks the admins to reset a forgotten password; no sign-in needed.
body
{
  "user": "jiri"
}
no sign-in
GET/api/auth/sessionsLists the own sessions.own account
POST/api/auth/sessions/revokeEnds all own sessions except the current one.own account
GET/api/auth/stateLogin page state, no sign-in needed.no sign-in
POST/api/auth/totp/disableTurns two-factor off for the own account.
body
{
  "password": "current-password"
}
own account
POST/api/auth/totp/enableConfirms the pending secret with a code and turns two-factor on.
body
{
  "code": "123456"
}
own account
POST/api/auth/totp/setupStarts two-factor setup: creates a pending secret and a QR code.own account

Users, roles and tokens

PathWhat it doesPermission
GET/api/auth/policySign-in policy: sessions, lockout, password length, required two-factor.administrators
POST/api/auth/policyChanges the sign-in policy; send only the fields to change.
body
{
  "idle_h": 12,
  "remember_d": 30,
  "lock_attempts": 5,
  "lock_min": 15,
  "password_min": 10,
  "totp_required": [
    "admin",
    "user"
  ]
}
administrators
GET/api/auth/requestsOpen password reset requests.administrators
POST/api/auth/requests/dismissDismisses the reset request of a user.
body
{
  "name": "petr"
}
administrators
GET/api/auth/rolesPage levels of the roles user and viewer, with factory defaults.administrators
POST/api/auth/rolesSets page levels of the roles user and viewer.
body
{
  "user": {
    "system/firmware": 1
  },
  "viewer": {
    "thread/settings": 0
  },
  "reset": false
}
administrators
GET/api/tokensLists API tokens (the secret value is never shown again).administrators
POST/api/tokensCreates an API token.
body
{
  "name": "homeassistant",
  "role": "admin"
}
administrators
POST/api/tokens/deleteRevokes an API token.
body
{
  "name": "homeassistant"
}
administrators
GET/api/usersLists user accounts and the page names used for levels.administrators
POST/api/usersCreates a user, or changes an existing one (by name).
body
{
  "name": "petr",
  "role": "user",
  "password": "start-password-1",
  "must_change": true,
  "disabled": false,
  "totp_reset": false,
  "unlock": false,
  "levels": {
    "system/maint": 1,
    "thread/settings": -1
  }
}
administrators
POST/api/users/deleteDeletes a user account.
body
{
  "name": "petr"
}
administrators

Roles and radios

PathWhat it doesPermission
GET/api/c6/backupDownloads a full flash dump of a radio.system/maint · edit
POST/api/c6/reflashMarks a radio to be reflashed with the firmware of its role and restarts the gateway.system/maint · edit
GET/api/radiosState of both radios: chip, flashed firmware, flashing progress, role.system/maint · read
GET/api/radios/b/consoleRaw text the radio B prints on its UART (ROM banner, boot log, panic), for diagnostics.system/maint · edit
POST/api/radios/b/flashFlashes firmware of a chosen bundle into radio B (only while it has no role).
body
{
  "bundle": "ot_rcp",
  "force": false
}
system/maint · edit
POST/api/radios/b/probeWiring test of radio B: resets it and listens on the UART.system/maint · edit
POST/api/radios/thread/forgetErases the stored Thread network (dataset and settings) of a radio, so its next Thread role starts a new network.
body
{
  "radio": "a"
}
thread/settings · edit
POST/api/roleSwitches the role of a radio, or swaps the roles of the two radios.
body
{
  "role": "zigbee_coordinator",
  "radio": "a",
  "skip_backup": false,
  "swap": false
}
role · edit

Thread

PathWhat it doesPermission
POST/api/thread/cliRuns an OpenThread CLI command and returns its output.
body
{
  "cmd": "state",
  "wait_ms": 600
}
thread/diag · edit
GET/api/thread/datasetThe active Thread dataset.thread/settings · edit
POST/api/thread/datasetApplies a Thread dataset (join or replace the network).
body
{
  "tlvs": "0e080000000000010000000300000f35060004001fffe0"
}
thread/settings · edit
GET/api/thread/statusThread network and OpenThread state.thread/info · read
GET/api/thread/topologyDiscovers the Thread mesh: routers, their children and IPv6 addresses.thread/topology · read
POST/api/thread/txpowerSets the transmit power of the Thread radio.
body
{
  "dbm": 8
}
thread/settings · edit

Zigbee

PathWhat it doesPermission
GET/api/c6/zigbee-snapshotDownloads the stored backup (NVRAM snapshot) of the Zigbee network of a radio.zigbee/backups · edit
POST/api/c6/zigbee-snapshotTakes a new backup of the Zigbee network now.zigbee/backups · edit
POST/api/zigbee/commandSends a command to the Zigbee router firmware.
body
{
  "cmd": "permit"
}
zigbee/diag · edit
GET/api/zigbee/netZigbee2MQTT view over MQTT: instances, devices, states and the last network map.zigbee/network · read
POST/api/zigbee/net/baseSets the MQTT base topic of Zigbee2MQTT.
body
{
  "base": "zigbee2mqtt"
}
zigbee/network · edit
POST/api/zigbee/net/mapAsks Zigbee2MQTT for a network map.zigbee/network · edit
POST/api/zigbee/net/requestRuns an operation through Zigbee2MQTT: permit join, rename, remove, interview, identify, firmware update.
body
{
  "action": "permit_join",
  "time": 120,
  "device": "lamp",
  "to": "new-name",
  "force": false
}
zigbee/network · edit
POST/api/zigbee/resetResets the Zigbee radio.zigbee/diag · edit
GET/api/zigbee/statusStatus of the Zigbee role (coordinator bridge or router).zigbee/info · read

ESPHome

PathWhat it doesPermission
GET/api/esphome/wifiWi-Fi network given to the ESPHome proxy radio.ha/esphome · edit
POST/api/esphome/wifiSets the Wi-Fi network for the ESPHome proxy radio.
body
{
  "ssid": "MyWifi",
  "password": "wifi-password"
}
ha/esphome · edit

Sound recognition

PathWhat it doesPermission
GET/api/sound/classesNames of the 521 sound classes.signed in
GET/api/sound/clipDownloads the latest seconds of microphone audio as a WAV file.sound/live · edit
POST/api/sound/configChanges microphone and recognition settings and the noise level calibration; send only the fields to change.
body
{
  "enabled": true,
  "gain_db": 30,
  "gate_db": -60,
  "inference": true,
  "spl_reference": 45.0
}
sound/live · edit
GET/api/sound/eventsConfigured sound events with live counters, plus the list of presets.sound/events · read
PUT/api/sound/eventsReplaces the whole event configuration.
body
{
  "preset": "custom",
  "exclude": [
    0,
    1
  ],
  "events": [
    {
      "id": "doorbell",
      "name": "Doorbell",
      "name_cs": "Zvonek",
      "kind": "impulse",
      "device_class": "sound",
      "profile": "",
      "enabled": true,
      "threshold": 0.5,
      "windows": 1,
      "hold_s": 3,
      "cooldown_s": 0,
      "classes": [
        380
      ],
      "suppress": []
    }
  ]
}
sound/events · edit
POST/api/sound/events/presetReplaces the event configuration with a preset.
body
{
  "preset": "household"
}
sound/events · edit
DELETE/api/sound/learnDeletes one sample slot, or all samples of a profile.sound/learn · edit
GET/api/sound/learnLearned sounds: profiles, samples, background recordings and the recording state.sound/learn · read
POST/api/sound/learn/recordStarts recording a sample of a profile, or background recordings, from the microphone.
body
{
  "profile": "my_bell",
  "kind": "sample",
  "type": "embedding"
}
sound/learn · edit
GET/api/sound/learn/sampleDownloads a stored sample as a WAV file.sound/learn · edit
POST/api/sound/learn/uploadAdds a sample or background from an uploaded WAV, or tests a WAV against the profiles.sound/learn · edit
GET/api/sound/logLog of recent detections (up to 64), newest first.sound/log · read
GET/api/sound/scoresLatest scores of all 521 sound classes.sound/live · read
GET/api/sound/statusState of the microphone, noise level and sound recognition.sound/live · read

Network

PathWhat it doesPermission
GET/api/net/lanEthernet settings and the state of an unconfirmed change.system/lan · read
POST/api/net/lanChanges Ethernet settings (DHCP or static, link speed). Must be confirmed or it is undone.
body
{
  "mode": "static",
  "ip": "192.168.1.50",
  "mask": "255.255.255.0",
  "gw": "192.168.1.1",
  "dns1": "192.168.1.1",
  "dns2": "",
  "link": "auto"
}
system/lan · edit
POST/api/net/lan/confirmConfirms a pending LAN change and stores it.system/lan · edit
POST/api/net/lan/outageSwitches Ethernet off for a while, to test the Wi-Fi uplink taking over.
body
{
  "seconds": 90
}
system/maint · edit
GET/api/net/scanState and result of the last radio environment scan (Wi-Fi, 802.15.4 channels).system/netscan · read
POST/api/net/scanStarts a quick scan (Thread role) or a full scan with the scanner firmware.
body
{
  "mode": "full",
  "radio": "b"
}
system/netscan · edit
GET/api/net/trafficEthernet traffic counters per service, since boot.system/lan · read
GET/api/net/wifiSettings and status of the Wi-Fi uplink.system/lan · read
POST/api/net/wifiSets the Wi-Fi network of the uplink.
body
{
  "ssid": "MyWifi",
  "password": "wifi-password",
  "mode": "static",
  "ip": "192.168.1.60",
  "mask": "255.255.255.0",
  "gw": "192.168.1.1",
  "dns1": "192.168.1.1",
  "dns2": ""
}
system/lan · edit
POST/api/net/wifi/restartRestarts the Wi-Fi uplink radio.
body
{}
system/lan · edit
GET/api/net/wifi/scanWi-Fi networks in range, seen by the uplink radio.system/lan · edit
GET/api/net/wifi/trafficTraffic counters of the Wi-Fi uplink.system/lan · read

MQTT and Home Assistant

PathWhat it doesPermission
GET/api/ha/discoverFinds Home Assistant instances on the LAN (mDNS _home-assistant._tcp).signed in
GET/api/mqttMQTT client settings and connection state.ha/mqtt · read
POST/api/mqttChanges MQTT settings; send only the fields to change. Reconnects the client.
body
{
  "enabled": true,
  "uri": "mqtt://192.168.1.10:1883",
  "user": "p4gw",
  "password": "mqtt-password",
  "prefix": "homeassistant",
  "tls": "bundle",
  "ca": "",
  "skip_cn_check": false,
  "client_id": "p4gw",
  "base": "",
  "keepalive": 60,
  "interval": 60,
  "discovery": true,
  "discovery_groups": [
    "roles",
    "system",
    "sound"
  ]
}
ha/mqtt · edit

I2C sensors

PathWhat it doesPermission
GET/api/sensorsI2C sensors on header JP1: configuration, state, values, the last scan and the supported types.system/hw · read
PUT/api/sensorsSets the read interval and/or replaces the list of sensors.
body
{
  "interval_s": 30,
  "sensors": [
    {
      "addr": 118,
      "type": "bme280",
      "name": "Living room",
      "expose": true,
      "enabled": true
    }
  ]
}
system/hw · edit
POST/api/sensors/scanScans the bus, identifies new chips and adds those recognised without doubt.system/hw · edit

Modbus (RS485 and TCP)

PathWhat it doesPermission
GET/api/modbusRS485 bus settings and the Modbus devices with their state and values.system/rs485 · read
PUT/api/modbusSets the bus and/or replaces the list of devices.
body
{
  "bus": {
    "baud": 9600,
    "parity": "N",
    "stop": 1,
    "timeout_ms": 500
  },
  "devices": [
    {
      "id": "d1",
      "name": "House meter",
      "template": "eastron_sdm630",
      "transport": "rtu",
      "slave": 1,
      "expose": "integration"
    },
    {
      "name": "Inverter",
      "template": "my_inverter",
      "transport": "tcp",
      "host": "192.168.1.60",
      "port": 502,
      "slave": 1,
      "poll_s": 5,
      "expose": "both",
      "enabled": true
    },
    {
      "name": "House meter as ABB B23",
      "template": "abb_b23",
      "transport": "virtual",
      "source": "d1",
      "expose": "none"
    }
  ]
}
system/rs485 · edit
GET/api/modbus/templatesThe device templates, built in and own.system/rs485 · read
GET/api/modbus/templateA whole template (?id=).system/rs485 · read
PUT/api/modbus/templateStores an own template (new, or replacing the own one with the same id).
body
{
  "schema": 1,
  "id": "my_meter",
  "manufacturer": "Acme",
  "model": "M1",
  "serial": {
    "baud": 9600,
    "parity": "E",
    "stop": 1
  },
  "entities": [
    {
      "key": "power",
      "name": "Power",
      "reg": "holding",
      "addr": "0x0010",
      "type": "s32",
      "order": "CDAB",
      "scale": 0.1,
      "unit": "W",
      "class": "power",
      "state": "measurement"
    },
    {
      "key": "mode",
      "name": "Mode",
      "reg": "holding",
      "addr": "0x0020",
      "map": {
        "0": "off",
        "1": "auto"
      },
      "write": {
        "kind": "select"
      }
    }
  ]
}
system/rs485 · edit
DELETE/api/modbus/templateDeletes an own template (?id=).system/rs485 · edit
POST/api/modbus/writeWrites a writable entity of a device.
body
{
  "device": "d2",
  "key": "alarm_threshold",
  "value": 2500
}
system/rs485 · edit
POST/api/modbus/rawManual request: reads or writes registers or coils.
body
{
  "transport": "rtu",
  "slave": 1,
  "fc": 4,
  "addr": 0,
  "count": 2
}
system/rs485 · edit
GET/api/modbus/probeState and result of the address search.system/rs485 · read
POST/api/modbus/probeStarts a search of addresses (and baud rates), or stops it.
body
{
  "transport": "rtu",
  "template": "eastron_sdm120",
  "bauds": [
    2400,
    9600
  ],
  "from": 1,
  "to": 247
}
system/rs485 · edit
GET/api/modbus/scanState and result of the Modbus TCP search in a network.system/rs485 · read
POST/api/modbus/scanStarts a Modbus TCP search in a network, or stops it.
body
{
  "net": "192.168.1.0/24",
  "ports": [
    502
  ],
  "units": [
    1,
    247,
    255
  ],
  "udp": true
}
system/rs485 · edit
GET/api/modbus/serverModbus TCP server: the devices offered in the network, ports, clients and counters.system/rs485 · read
PUT/api/modbus/serverSets the Modbus TCP server: the shared port and the devices offered.
body
{
  "enabled": true,
  "port": 502,
  "devices": [
    {
      "device": "d1",
      "unit": 10,
      "port": 1502,
      "write": false,
      "allow": [],
      "rate": 5,
      "cache_ms": 2000
    },
    {
      "device": "d2",
      "unit": 0,
      "port": 1503,
      "write": true,
      "allow": [
        "192.168.88.20"
      ],
      "rate": 2,
      "cache_ms": 2000
    }
  ]
}
system/rs485 · edit

GPIO of header JP1

PathWhat it doesPermission
GET/api/gpioHeader JP1 with the state of each pin, and the configured GPIO with their values.system/hw · read
PUT/api/gpioReplaces the GPIO configuration; applied at once.
body
{
  "pins": [
    {
      "gpio": 2,
      "mode": "uart",
      "name": "Meter",
      "rx": 3,
      "baud": 9600,
      "data_bits": 8,
      "parity": "none",
      "stop_bits": 1,
      "port": 6639
    },
    {
      "gpio": 1,
      "mode": "ws2812",
      "name": "Strip",
      "leds": 60,
      "order": "grb",
      "restore": "last",
      "expose": "both"
    },
    {
      "gpio": 45,
      "mode": "onewire",
      "name": "Floor",
      "interval_s": 30
    }
  ]
}
system/hw · edit
POST/api/gpio/setSets an output, a pulse, the duty of a PWM pin or clears a counter.
body
{
  "gpio": 1,
  "on": true,
  "color": [
    255,
    80,
    0
  ],
  "brightness": 180,
  "effect": "rainbow"
}
system/hw · edit

Updates and firmware

PathWhat it doesPermission
POST/api/ota/c6fwUploads the radio firmware package (all bundles of one chip type).system/firmware · edit
POST/api/ota/gatewayUploads a gateway firmware image into the inactive slot and boots it.system/firmware · edit
POST/api/ota/modelUploads the sound recognition model into the model partition.system/firmware · edit
POST/api/update/checkTriggers a check of the update manifest.system/firmware · edit
POST/api/update/installInstalls the offered or a chosen release: gateway firmware or a radio package.
body
{
  "target": "gateway",
  "version": "v1.10"
}
system/firmware · edit

Settings and maintenance

PathWhat it doesPermission
POST/api/rebootRestarts the gateway.
body
{
  "full": false
}
system/maint · edit
POST/api/settingsChanges basic gateway settings; send only the fields to change.
body
{
  "hostname": "p4gw-livingroom",
  "matter_url": "ws://192.168.1.10:5580/ws",
  "zigbee_backup_days": 1,
  "update_url": "https://example.com/p4gw/manifest.json"
}
system/settings · edit
GET/api/timeClock of the gateway: time, last SNTP sync, servers and time zone.system/settings · read
POST/api/timeSets the SNTP servers and the time zone of the gateway; send only the fields to change.
body
{
  "servers": [
    "pool.ntp.org",
    "192.168.1.1"
  ],
  "tz": "CET-1CEST,M3.5.0,M10.5.0/3",
  "tz_name": "Europe/Prague"
}
system/settings · edit
GET/api/settings/exportExports the gateway settings as a JSON file.system/settings · edit
POST/api/settings/importImports a settings file made by the export.
body
{
  "format": "p4gw-settings",
  "version": 1,
  "keys": {
    "...": "as exported"
  }
}
system/settings · edit

Logs and diagnostics

PathWhat it doesPermission
DELETE/api/coredumpErases the stored core dump.system/diag · edit
GET/api/coredumpDownloads the stored core dump (ELF) of the last crash.system/diag · read
GET/api/logsGateway log lines since a sequence number.system/diag · read
GET/api/logs/previousLog of the run before the last restart.system/diag · read
POST/api/tools/pingPings a host from the gateway.
body
{
  "host": "192.168.1.1",
  "count": 4
}
system/diag · edit

Notifications and Telegram

PathWhat it doesPermission
GET/api/auth/telegramOwn Telegram notification preferences and pairing state.own account
POST/api/auth/telegramChanges own Telegram notification preferences.
body
{
  "levels": {
    "security": 3,
    "system": 2,
    "network": 1,
    "sound": 0
  },
  "quiet_from": 22,
  "quiet_to": 7,
  "lang": "cs"
}
own account
POST/api/auth/telegram/pairCreates a code to pair the own Telegram chat with the bot.own account
POST/api/auth/telegram/testSends a test message to the own paired Telegram chat.own account
GET/api/auth/telegram/reportsThe own periodic Telegram reports, the devices they may cover and the limits.own account
PUT/api/auth/telegram/reportsReplaces the own periodic Telegram reports.
body
{
  "reports": [
    {
      "id": 1,
      "name": "Daily summary",
      "devices": [
        "modbus:d1",
        "sensors:i2c_76",
        "gpio:2"
      ],
      "period_min": 1440,
      "at": 420,
      "weekday": 0,
      "enabled": true
    }
  ]
}
own account
POST/api/auth/telegram/reports/sendSends an own report now (the period so far), or returns its text.
body
{
  "id": 1,
  "preview": false
}
own account
POST/api/auth/telegram/unpairRemoves the pairing of the own Telegram chat.own account
GET/api/notifyRecent gateway notifications, oldest first.signed in
GET/api/telegramTelegram bot settings and state (admin).administrators
POST/api/telegramChanges Telegram bot settings (admin); send only the fields to change.
body
{
  "token": "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11",
  "enabled": true,
  "tz": "CET-1CEST,M3.5.0,M10.5.0/3"
}
administrators

Troubleshooting

SituationWhat to do
Role does not startThe UI shows maintenance with the reason; choose another role or fix it and restart.
C6 does not answerCheck the JP1 jumpers, Radios › Status and maintenance › Reflash C6 now.
Bad gateway updateAutomatic rollback to the previous slot; otherwise scripts/flash_p4.sh.
CrashesSystem › Diagnostics: core dump and the log before the last restart.
Static address that does not workNot confirmed: back after 120 s by itself. Confirmed: http://<host>.local/ over IPv6, or import a settings backup.
Forgotten passwordForgot password on the sign-in page; an admin sets a temporary one.
Lost phone with the authenticatorA recovery code instead of the app code, or an admin turns off 2FA (Users › Edit).
New boardSystem › Maintenance and backup › Settings backup: export (with passwords) and import on the new board.
Maintenance: "the C6 firmware package is not on the gateway"The C6 needs its large firmwares (first start, C6 update, reflash, ESPHome) and the package is neither in RAM nor downloadable: connect the gateway to the internet, or upload c6fw.bin of the release under System › Firmware and restart.

Screenshots: firmware v1.10, dark theme, English. The board, network names and addresses are those of the test setup.