
Secure, customizable communication layer between wearables and companion apps: structured message envelopes, transport‑agnostic routing, battery‑aware connection lifecycle, retries/ACKs, and reactive incoming streams.
Secure, customisable communication between wearable devices and mobile devices
Built for Kotlin Multiplatform (KMP) and Flutter
WearGuard provides a reliable, structured, and battery-aware communication layer between wearables (Wear OS, watchOS) and companion mobile apps.
It abstracts transport, connection lifecycle, retries, acknowledgements, and message routing — so you focus on data, not plumbing.
WearGuard can also be used for low-level device configuration and control, making it suitable for advanced, research, and custom firmware environments, including unlocked or modified wearable devices.
Targets: Android · iOS · Wear OS · watchOS
WearGuard is a library for secure and customisable communication between wearable devices and mobile devices.
Wearable ↔ mobile communication is deceptively hard:
WearGuard solves this once — properly.
WearMessage
Flow
A logical connection between:
A strongly-typed message envelope:
idtypepayloadcorrelationIdexpectsAcktimestampMsManages active connections, lifecycle, and default resolution.
implementation("io.github.thearchitect123:wear-guard:+")1️⃣ Initialise WearGuard Context
Registration & Setup.
On Android (Same concept applies to all other platforms):
WearConnectionFactory.initContext(this)
val wearConnection = WearConnectionFactory.create(
WearConnectionConfig(
id = WearConnectionId("testClientApp"),
appId = "testClientApp",
namespace = "/testClient"
)
)
// to register the wearConnection as a default connection (there can only be a single default)
WearConnectionRegistry.register(
wearConnection,
asDefault = true
)📥 Receiving Messages (Host / Listener Side)
WearConnectionRegistry
.default()
.connect(ConnectionPolicy())
wearConnection.incoming.collect { message ->
println(
"Results Captured - ${
message.payload.decodeToString()
}"
)
// Handle incoming data here
}📤 Sending Messages (Client / Initiator Side)
val connection = WearConnectionRegistry.default() // connect to the remote device first
when (val result = connection.connect()) {
is ConnectionResult.Success -> { // on success, send a simple string
val peer = result.peer
val transport = result.transport
println("Connected to ${peer.name} via $transport")
val message = WearMessage(
id = "msg-001",
type = "ping",
correlationId = null,
payload = "hello from watch".encodeToByteArray(),
expectsAck = false,
timestampMs = System.currentTimeMillis()
)
connection.send(message)
}
is ConnectionResult.Failure -> {
println("Failed to connect: ${result.error}")
if (result.retryable) {
println("Retry is allowed")
}
}
ConnectionResult.Cancelled -> {
println("Connection was cancelled by user/system")
}
}
Secure, customisable communication between wearable devices and mobile devices
Built for Kotlin Multiplatform (KMP) and Flutter
WearGuard provides a reliable, structured, and battery-aware communication layer between wearables (Wear OS, watchOS) and companion mobile apps.
It abstracts transport, connection lifecycle, retries, acknowledgements, and message routing — so you focus on data, not plumbing.
WearGuard can also be used for low-level device configuration and control, making it suitable for advanced, research, and custom firmware environments, including unlocked or modified wearable devices.
Targets: Android · iOS · Wear OS · watchOS
WearGuard is a library for secure and customisable communication between wearable devices and mobile devices.
Wearable ↔ mobile communication is deceptively hard:
WearGuard solves this once — properly.
WearMessage
Flow
A logical connection between:
A strongly-typed message envelope:
idtypepayloadcorrelationIdexpectsAcktimestampMsManages active connections, lifecycle, and default resolution.
implementation("io.github.thearchitect123:wear-guard:+")1️⃣ Initialise WearGuard Context
Registration & Setup.
On Android (Same concept applies to all other platforms):
WearConnectionFactory.initContext(this)
val wearConnection = WearConnectionFactory.create(
WearConnectionConfig(
id = WearConnectionId("testClientApp"),
appId = "testClientApp",
namespace = "/testClient"
)
)
// to register the wearConnection as a default connection (there can only be a single default)
WearConnectionRegistry.register(
wearConnection,
asDefault = true
)📥 Receiving Messages (Host / Listener Side)
WearConnectionRegistry
.default()
.connect(ConnectionPolicy())
wearConnection.incoming.collect { message ->
println(
"Results Captured - ${
message.payload.decodeToString()
}"
)
// Handle incoming data here
}📤 Sending Messages (Client / Initiator Side)
val connection = WearConnectionRegistry.default() // connect to the remote device first
when (val result = connection.connect()) {
is ConnectionResult.Success -> { // on success, send a simple string
val peer = result.peer
val transport = result.transport
println("Connected to ${peer.name} via $transport")
val message = WearMessage(
id = "msg-001",
type = "ping",
correlationId = null,
payload = "hello from watch".encodeToByteArray(),
expectsAck = false,
timestampMs = System.currentTimeMillis()
)
connection.send(message)
}
is ConnectionResult.Failure -> {
println("Failed to connect: ${result.error}")
if (result.retryable) {
println("Retry is allowed")
}
}
ConnectionResult.Cancelled -> {
println("Connection was cancelled by user/system")
}
}