# sroemer/scale-communication architecture

> Architecture diagram of the GitHub repository sroemer/scale-communication, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sroemer/scale-communication
- Repository: https://github.com/sroemer/scale-communication

## Overview

This repository is a Python BLE client for reverse-engineering the Crénot Gofit S2 scale protocol. The main workflow discovers and connects to the scale, subscribes to its measurement characteristics, waits for a stable weight and BIA message, then checks that the reported weights match. Optional device/service diagnostics are included. The Rust and Zig files are not mapped: the README describes the Python implementation, and their runtime behavior was not sampled.

Main entry points: [`python/src/crenot-gofit-s2.py`](https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py) (Workflow runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Python client"]
  node_cli["CLI entry<br/>[crenot-gofit-s2.py]"]
  node_runner["Workflow runner<br/>[crenot-gofit-s2.py]"]
  node_discovery["BLE discovery<br/>[crenot-gofit-s2.py]"]
  node_connection["BLE connection<br/>[crenot-gofit-s2.py]"]
  node_diagnostics["Device diagnostics<br/>[crenot-gofit-s2.py]"]
  node_subscriptions["Characteristic subscriptions<br/>[crenot-gofit-s2.py]"]
end

subgraph group_protocol["Measurement protocol"]
  node_stable["Stable-weight wait<br/>[crenot-gofit-s2.py]"]
  node_ffb2["FFB2 weight parser<br/>[crenot-gofit-s2.py]"]
  node_bia["BIA wait<br/>[crenot-gofit-s2.py]"]
  node_ffb3["FFB3 weight parser<br/>[crenot-gofit-s2.py]"]
  node_verify["Weight comparison<br/>[crenot-gofit-s2.py]"]
end

subgraph group_external["External devices"]
  node_bleak["Bleak BLE library"]
  node_scale["Gofit S2 scale"]
end

node_user(("CLI user"))

node_user -->|"runs"| node_cli
node_cli -->|"starts"| node_runner
node_runner -->|"discovers via"| node_discovery
node_discovery -->|"scans with"| node_bleak
node_runner -->|"connects via"| node_connection
node_connection -->|"connects with"| node_bleak
node_bleak -->|"connects to"| node_scale
node_runner -->|"optionally calls"| node_diagnostics
node_diagnostics -->|"reads GATT"| node_bleak
node_runner -->|"starts"| node_subscriptions
node_subscriptions -->|"enables notifications"| node_bleak
node_bleak -->|"receives messages"| node_scale
node_runner -->|"waits for"| node_stable
node_subscriptions -->|"dispatches FFB2"| node_ffb2
node_ffb2 -->|"updates weight"| node_stable
node_runner -->|"waits for"| node_bia
node_subscriptions -->|"dispatches FFB3"| node_ffb3
node_ffb3 -->|"sets BIA weight"| node_bia
node_runner -->|"compares weights"| node_verify
node_stable -->|"provides stable weight"| node_verify
node_bia -->|"provides BIA weight"| node_verify

click node_cli "https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py"
click node_runner "https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py"
click node_discovery "https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py"
click node_connection "https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py"
click node_diagnostics "https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py"
click node_subscriptions "https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py"
click node_stable "https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py"
click node_ffb2 "https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py"
click node_bia "https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py"
click node_ffb3 "https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py"
click node_verify "https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_runner,node_discovery,node_connection,node_diagnostics,node_subscriptions,node_user toneBlue
class node_stable,node_ffb2,node_bia,node_ffb3,node_verify toneAmber
class node_bleak,node_scale toneMint
```

## Components

### Python client

- [CLI entry](https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py): `python/src/crenot-gofit-s2.py`
- [Workflow runner](https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py): `python/src/crenot-gofit-s2.py`
- [BLE discovery](https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py): `python/src/crenot-gofit-s2.py`
- [BLE connection](https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py): `python/src/crenot-gofit-s2.py`
- [Device diagnostics](https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py): `python/src/crenot-gofit-s2.py`
- [Characteristic subscriptions](https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py): `python/src/crenot-gofit-s2.py`

### Measurement protocol

- [Stable-weight wait](https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py): `python/src/crenot-gofit-s2.py`
- [FFB2 weight parser](https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py): `python/src/crenot-gofit-s2.py`
- [BIA wait](https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py): `python/src/crenot-gofit-s2.py`
- [FFB3 weight parser](https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py): `python/src/crenot-gofit-s2.py`
- [Weight comparison](https://github.com/sroemer/scale-communication/blob/main/python/src/crenot-gofit-s2.py): `python/src/crenot-gofit-s2.py`

### External devices

- **Bleak BLE library**
- **Gofit S2 scale**

### Other components

- **CLI user**

## Connections

- CLI user → CLI entry: runs (evidence: `python/src/crenot-gofit-s2.py`)
- CLI entry → Workflow runner: starts (evidence: `python/src/crenot-gofit-s2.py`)
- Workflow runner → BLE discovery: discovers via (evidence: `python/src/crenot-gofit-s2.py`)
- BLE discovery → Bleak BLE library: scans with (evidence: `python/src/crenot-gofit-s2.py`)
- Workflow runner → BLE connection: connects via (evidence: `python/src/crenot-gofit-s2.py`)
- BLE connection → Bleak BLE library: connects with (evidence: `python/src/crenot-gofit-s2.py`)
- Bleak BLE library → Gofit S2 scale: connects to (evidence: `README.md`)
- Workflow runner → Device diagnostics: optionally calls (evidence: `python/src/crenot-gofit-s2.py`)
- Device diagnostics → Bleak BLE library: reads GATT (evidence: `python/src/crenot-gofit-s2.py`)
- Workflow runner → Characteristic subscriptions: starts (evidence: `python/src/crenot-gofit-s2.py`)
- Characteristic subscriptions → Bleak BLE library: enables notifications (evidence: `python/src/crenot-gofit-s2.py`)
- Bleak BLE library → Gofit S2 scale: receives messages (evidence: `README.md`)
- Workflow runner → Stable-weight wait: waits for (evidence: `python/src/crenot-gofit-s2.py`)
- Characteristic subscriptions → FFB2 weight parser: dispatches FFB2 (evidence: `python/src/crenot-gofit-s2.py`)
- FFB2 weight parser → Stable-weight wait: updates weight (evidence: `python/src/crenot-gofit-s2.py`)
- Workflow runner → BIA wait: waits for (evidence: `python/src/crenot-gofit-s2.py`)
- Characteristic subscriptions → FFB3 weight parser: dispatches FFB3 (evidence: `python/src/crenot-gofit-s2.py`)
- FFB3 weight parser → BIA wait: sets BIA weight (evidence: `python/src/crenot-gofit-s2.py`)
- Workflow runner → Weight comparison: compares weights (evidence: `python/src/crenot-gofit-s2.py`)
- Stable-weight wait → Weight comparison: provides stable weight (evidence: `python/src/crenot-gofit-s2.py`)
- BIA wait → Weight comparison: provides BIA weight (evidence: `python/src/crenot-gofit-s2.py`)
