ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
ZWaveGateway - a Z-Wave mesh bridged to the gateway

Layer: Foundation ยท Build flags: PROTOCORE_ENABLE_ZWAVE, PROTOCORE_ENABLE_GATEWAY

What this example teaches

A Z-Wave mesh plugged into the gateway through a Silicon Labs 500 / 700-series controller speaking its Serial API over UART. When a node reports, we pull the source node id + payload and publish it northbound.

Z-Wave mesh --UART--> protocore_zwave_parse_frame() --> node + payload -> protocore_gateway_uplink()
|
envelope + topic zwave/0/<node>
|
northbound publish (MQTT/HTTP/WS)

A Serial API data frame is SOF | LEN | Type | Command | Data | Checksum, and each is acknowledged by a single ACK byte (or NAK / CAN). services/zwave frames + verifies them:

uint8_t type, cmd, pdlen; const uint8_t *pd;
int n = protocore_zwave_parse_frame(buf, len, &type, &cmd, &pd, &pdlen); // >0 / need-more / -1
if (n > 0) {
Serial2.write((uint8_t)ZWAVE_ACK); // acknowledge the frame
if (cmd == 0x04 /* ApplicationCommandHandler */)
protocore_gateway_uplink(0, pd[1] /* node */, &pd[3], pdlen - 3, 0);
}
proto_bool protocore_gateway_uplink(uint8_t *work, uint8_t port_id, uint16_t src_addr, const uint8_t *payload, uint16_t len, int16_t rssi)
Bridge a received southbound frame northbound: envelope it and .
int protocore_zwave_parse_frame(uint8_t *work, const uint8_t *raw, uint16_t len, uint8_t *type, uint8_t *cmd, const uint8_t **pdata, uint8_t *pdata_len)
Frame one data frame from the front of raw and verify the checksum.
#define ZWAVE_ACK
frame acknowledged
Definition zwave.h:46

protocore_zwave_build_frame() assembles a command the same way (this sketch sends GetVersion at boot). The checksum is 0xFF XOR-folded over LEN..last-data. The codec is host-tested against the documented GetVersion frame (01 03 00 15 E9) in test/test_zwave.

Wiring (ESP32 <-> Z-Wave controller)

Controller ESP32
TX GPIO 16 (RX)
RX GPIO 17 (TX)
VCC 3V3
GND GND

115200 8N1 (a ZM5304 / EFR32 module or a UZB stick's UART).

Build-flag note

The flags must reach the library build, so pass them as build flags:

pio ci --board=esp32dev --project-option="framework=arduino" \
--project-option="build_flags=-DPROTOCORE_ENABLE_ZWAVE=1 -DPROTOCORE_ENABLE_GATEWAY=1" \
--lib="." examples/Drivers/ZWaveGateway/ZWaveGateway.ino