# simat/batterymonitor architecture

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

- Interactive diagram: https://gitdiagram.com/simat/batterymonitor
- Repository: https://github.com/simat/batterymonitor

## Overview

BatteryMonitor collects cell and system measurements from configurable BMS or Linux-based interfaces, derives battery state and demand, raises limit-driven alarms and BeagleBone I/O actions, and logs summaries for browser dashboards and optional MQTT publication. The main loop in `batteries.py` is the runtime orchestrator. Driver-to-reader wiring is configurable; the README documents the supported hardware model, but sampled excerpts do not establish every interface call. The graph omits uncertain driver links and shows documented optional integrations dashed.

Main entry points: [`batteries.py`](https://github.com/simat/batterymonitor/blob/master/batteries.py) (Monitor loop), [`getdata.py`](https://github.com/simat/batterymonitor/blob/master/getdata.py) (Readings), [`bms.py`](https://github.com/simat/batterymonitor/blob/master/bms.py) (Bluetooth BMS), [`alarms.py`](https://github.com/simat/batterymonitor/blob/master/alarms.py) (Limit alarms)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_acquisition["Measurement acquisition"]
  node_readings["Readings<br/>[getdata.py]"]
  node_bms["Bluetooth BMS<br/>[bms.py]"]
  node_pylon["Pylontech driver<br/>[pylon.py]"]
  node_inverter["PIP inverter<br/>[pip.py]"]
  node_ads["ADS1115 driver<br/>[ads1115.py]"]
end

subgraph group_processing["Monitoring and control"]
  node_main["Monitor loop<br/>[batteries.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
  node_demand["Solar demand manager<br/>[demandmanager.py]"]
  node_alarms["Limit alarms<br/>[alarms.py]"]
end

subgraph group_persistence["Logging and display"]
  node_summary["Summary and aggregation<br/>[summary.py]"]
  node_logstore[("Summary and log files")]
  node_web["Battery web pages<br/>[batday.php]"]
  node_htmlsummary["Summary page<br/>[battery.php]"]
  node_excess["Excess power page<br/>[excesspwr.php]"]
end

subgraph group_integrations["External interfaces"]
  node_gpio["BeagleBone I/O<br/>[beagle.py]"]
  node_mqtt["MQTT publisher<br/>[mqtt.py]"]
  node_broker(("MQTT broker"))
  node_bmsboard(("Bluetooth BMS board"))
end

node_operator(("Battery operator"))
node_browser(("Web browser"))
node_batterybank(("Battery bank"))

node_operator -->|"starts monitor"| node_main
node_main -->|"creates readings"| node_readings
node_readings -.->|"configured acquisition"| node_bms
node_readings -.->|"configured acquisition"| node_pylon
node_readings -.->|"configured acquisition"| node_inverter
node_readings -.->|"configured acquisition"| node_ads
node_main -->|"loads settings"| node_config
node_readings -->|"measures cells"| node_batterybank
node_bms -->|"reads serial data"| node_bmsboard
node_readings -->|"returns measurements"| node_main
node_main -->|"calculates availability"| node_demand
node_main -->|"checks limits"| node_alarms
node_alarms -.->|"sets I/O"| node_gpio
node_main -->|"updates summaries"| node_summary
node_summary -->|"writes records"| node_logstore
node_main -.->|"publishes payload"| node_mqtt
node_mqtt -.->|"sends messages"| node_broker
node_browser -->|"requests display"| node_web
node_web -->|"reads summary data"| node_logstore
node_browser -->|"requests summary"| node_htmlsummary
node_htmlsummary -->|"reads summary file"| node_logstore
node_browser -->|"requests power view"| node_excess
node_excess -->|"reads demand data"| node_logstore

click node_main "https://github.com/simat/batterymonitor/blob/master/batteries.py"
click node_readings "https://github.com/simat/batterymonitor/blob/master/getdata.py"
click node_bms "https://github.com/simat/batterymonitor/blob/master/bms.py"
click node_pylon "https://github.com/simat/batterymonitor/blob/master/pylon.py"
click node_inverter "https://github.com/simat/batterymonitor/blob/master/pip.py"
click node_ads "https://github.com/simat/batterymonitor/blob/master/ads1115.py"
click node_config "https://github.com/simat/batterymonitor/blob/master/config.py"
click node_demand "https://github.com/simat/batterymonitor/blob/master/demandmanager.py"
click node_alarms "https://github.com/simat/batterymonitor/blob/master/alarms.py"
click node_gpio "https://github.com/simat/batterymonitor/blob/master/beagle.py"
click node_summary "https://github.com/simat/batterymonitor/blob/master/summary.py"
click node_mqtt "https://github.com/simat/batterymonitor/blob/master/mqtt.py"
click node_web "https://github.com/simat/batterymonitor/blob/master/html/batday.php"
click node_htmlsummary "https://github.com/simat/batterymonitor/blob/master/html/battery.php"
click node_excess "https://github.com/simat/batterymonitor/blob/master/html/excesspwr.php"

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_readings,node_bms,node_pylon,node_inverter,node_ads,node_browser toneBlue
class node_main,node_config,node_demand,node_alarms toneAmber
class node_summary,node_logstore,node_web,node_htmlsummary,node_excess toneMint
class node_gpio,node_mqtt,node_broker,node_bmsboard toneRose
class node_operator,node_batterybank toneIndigo
```

## Components

### Measurement acquisition

- [Readings](https://github.com/simat/batterymonitor/blob/master/getdata.py): `getdata.py`
- [Bluetooth BMS](https://github.com/simat/batterymonitor/blob/master/bms.py): `bms.py`
- [Pylontech driver](https://github.com/simat/batterymonitor/blob/master/pylon.py): `pylon.py`
- [PIP inverter](https://github.com/simat/batterymonitor/blob/master/pip.py): `pip.py`
- [ADS1115 driver](https://github.com/simat/batterymonitor/blob/master/ads1115.py): `ads1115.py`

### Monitoring and control

- [Monitor loop](https://github.com/simat/batterymonitor/blob/master/batteries.py): `batteries.py`
- [Runtime configuration](https://github.com/simat/batterymonitor/blob/master/config.py): `config.py`
- [Solar demand manager](https://github.com/simat/batterymonitor/blob/master/demandmanager.py): `demandmanager.py`
- [Limit alarms](https://github.com/simat/batterymonitor/blob/master/alarms.py): `alarms.py`

### Logging and display

- [Summary and aggregation](https://github.com/simat/batterymonitor/blob/master/summary.py): `summary.py`
- **Summary and log files**
- [Battery web pages](https://github.com/simat/batterymonitor/blob/master/html/batday.php): `html/batday.php`
- [Summary page](https://github.com/simat/batterymonitor/blob/master/html/battery.php): `html/battery.php`
- [Excess power page](https://github.com/simat/batterymonitor/blob/master/html/excesspwr.php): `html/excesspwr.php`

### External interfaces

- [BeagleBone I/O](https://github.com/simat/batterymonitor/blob/master/beagle.py): `beagle.py`
- [MQTT publisher](https://github.com/simat/batterymonitor/blob/master/mqtt.py): `mqtt.py`
- **MQTT broker**
- **Bluetooth BMS board**

### Other components

- **Battery operator**
- **Web browser**
- **Battery bank**

## Connections

- Battery operator → Monitor loop: starts monitor
- Monitor loop → Readings: creates readings
- Readings → Bluetooth BMS: configured acquisition
- Readings → Pylontech driver: configured acquisition
- Readings → PIP inverter: configured acquisition
- Readings → ADS1115 driver: configured acquisition
- Monitor loop → Runtime configuration: loads settings
- Readings → Battery bank: measures cells
- Bluetooth BMS → Bluetooth BMS board: reads serial data
- Readings → Monitor loop: returns measurements
- Monitor loop → Solar demand manager: calculates availability
- Monitor loop → Limit alarms: checks limits
- Limit alarms → BeagleBone I/O: sets I/O
- Monitor loop → Summary and aggregation: updates summaries
- Summary and aggregation → Summary and log files: writes records
- Monitor loop → MQTT publisher: publishes payload
- MQTT publisher → MQTT broker: sends messages
- Web browser → Battery web pages: requests display
- Battery web pages → Summary and log files: reads summary data
- Web browser → Summary page: requests summary
- Summary page → Summary and log files: reads summary file
- Web browser → Excess power page: requests power view
- Excess power page → Summary and log files: reads demand data
