Skip to content
EN

Discovery & targeting

By default the library broadcasts to every Hapbeat on the LAN. Use discovery and targeting to narrow to one device or to make streaming smoother.

hb.begin(7700, "MyDevice"); // open the UDP socket; app name (<=16 chars) shows on the OLED

When the app name appears on the Hapbeat OLED you are connected. On exit, call hb.end() to announce leaving (clears the OLED app name).

hb.begin(7700, "MyDevice");
hb.discover(1500); // broadcast PING -> PONG to learn the device IP

On success, streaming unicasts to that device. Wi-Fi unicast has MAC-layer ACK + retry, so it is far smoother than broadcast (a good fix for dropouts). If no device replies, it falls back to broadcast.

  • hb.deviceIp() — the discovered IP
  • hb.setDeviceIp(ip) — set the IP manually (force unicast without discovery)

The target argument of play / playSine / etc. selects the destination.

targetmeaning
""broadcast to all devices
"player_1/chest"a specific position / role
"*/chest"wildcard match
"group_<N>"filter by group id
hb.play("sample-kit.sine_100hz", 0.6f, "player_1/chest");
hb.stopAll("group_2");

Set the group id with hb.setGroup(n); it is announced in CONNECT_STATUS (level-1 default 0).

The target string (application-level addressing) and discover() IP unicast (a transport reliability optimization) are separate. The simple model: broadcast + target by default; unicast when you need it smooth.