mirror of
https://github.com/RunLit/Bambu-Run.git
synced 2026-08-22 06:44:19 +01:00
Compare commits
12 Commits
c7ea0dd094
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
184d52a297 | ||
|
|
fcd038c562 | ||
|
|
911905610f | ||
|
|
b2a083fb94 | ||
|
|
1bbeef7a47 | ||
|
|
40ec163134 | ||
|
|
61cfd3f5a9 | ||
|
|
1e35c48be1 | ||
|
|
b16f4b3cac | ||
|
|
58400f16cf | ||
|
|
6f281a0cab | ||
|
|
4db0a7d728 |
13
.github/workflows/bump-version.yml
vendored
13
.github/workflows/bump-version.yml
vendored
@@ -5,6 +5,10 @@ on:
|
||||
branches:
|
||||
- main
|
||||
|
||||
concurrency:
|
||||
group: bump-version-main
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
bump-version:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -49,8 +53,17 @@ jobs:
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git add pyproject.toml
|
||||
git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }} [skip ci]"
|
||||
git pull --rebase origin main
|
||||
git push
|
||||
- name: Tag the release
|
||||
run: |
|
||||
git tag "v${{ steps.bump.outputs.new_version }}"
|
||||
git push origin "v${{ steps.bump.outputs.new_version }}"
|
||||
|
||||
- name: Create GitHub release with auto-generated notes
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
gh release create "v${{ steps.bump.outputs.new_version }}" \
|
||||
--title "v${{ steps.bump.outputs.new_version }}" \
|
||||
--generate-notes
|
||||
|
||||
34
README.md
34
README.md
@@ -20,8 +20,42 @@ It runs quietly in the background 24/7, capturing every print, filament change,
|
||||
|
||||
---
|
||||
|
||||
## What It Looks Like
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td width="50%">
|
||||
<p align="center"><strong>Live Dashboard</strong><br/>Real-time nozzle temps, bed temp, print progress, and chamber light.</p>
|
||||
<img src="https://github.com/user-attachments/assets/169ec3e5-62a9-4e96-afed-dc6ac2647aef" alt="Live Dashboard" width="100%"/>
|
||||
</td>
|
||||
<td width="50%">
|
||||
<p align="center"><strong>Historical Charts</strong><br/>Filament remaining and nozzle temp over time, per printer.</p>
|
||||
<img src="https://github.com/user-attachments/assets/11913c62-254f-4ba6-8d93-d5c27a9406be" alt="Historical Charts" width="100%"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="50%">
|
||||
<p align="center"><strong>Filament Inventory</strong><br/>Every spool you own — brand, type, color, remaining %, current tray.</p>
|
||||
<img src="https://github.com/user-attachments/assets/8e472704-a6d8-45e1-93c4-c6f37d0b55a0" alt="Filament Inventory" width="100%"/>
|
||||
</td>
|
||||
<td width="50%">
|
||||
<p align="center"><strong>AMS / Filament Slots</strong><br/>What's loaded right now, grouped by AMS unit, with humidity/temp.</p>
|
||||
<img src="https://github.com/user-attachments/assets/200ad65f-a716-4a52-98b2-d5f5ce2445b9" alt="AMS / Filament Slots" width="100%"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<p align="center"><strong>Hotend Wear Tracking</strong><br/>Used time and wear per hotend slot — handy for multi-nozzle / AMS-fed toolhead setups.</p>
|
||||
<img src="https://github.com/user-attachments/assets/defee0da-772c-40c2-8dcf-9d3f230cc5ee" alt="Hotend Wear Tracking" width="100%"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [What It Looks Like](#what-it-looks-like)
|
||||
- [Native Setup (Recommended for Raspberry Pi)](#native-setup-recommended-for-raspberry-pi)
|
||||
- [What You'll Need](#what-youll-need)
|
||||
- [Clone and run setup.sh](#clone-and-run-setupsh)
|
||||
|
||||
@@ -81,5 +81,12 @@ class _Settings:
|
||||
def CLOUD_SYNC_DAYS(self):
|
||||
return get_setting("BAMBU_RUN_CLOUD_SYNC_DAYS", 30)
|
||||
|
||||
# Seconds of silence on the MQTT report topic that, once broken by a new
|
||||
# message, is treated as "the printer was probably offline" and triggers
|
||||
# a pushall re-sync instead of trusting the partial delta to fill in stale
|
||||
# fields left over from before the gap.
|
||||
@property
|
||||
def MQTT_RESYNC_GAP_SECONDS(self):
|
||||
return get_setting("BAMBU_RUN_MQTT_RESYNC_GAP_SECONDS", 90)
|
||||
|
||||
app_settings = _Settings()
|
||||
|
||||
@@ -21,6 +21,7 @@ import os
|
||||
import platform
|
||||
import sys
|
||||
import select
|
||||
import time
|
||||
from contextlib import contextmanager
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
@@ -486,15 +487,29 @@ class PrinterState:
|
||||
|
||||
wifi_signal = print_data.get("wifi_signal", "")
|
||||
|
||||
# H2C dual-nozzle decoding. The H2C reports per-extruder temperatures
|
||||
# under `print.device.extruder.info[]` as a 2-element array (index 0 =
|
||||
# right, index 1 = left). The `temp` field is bit-packed:
|
||||
# Dual-nozzle decoding (H2C, X2D). Dual-nozzle printers report per-extruder
|
||||
# temperatures under `print.device.extruder.info[]` as a 2-element array
|
||||
# (index 0 = right, index 1 = left). The `temp` field is bit-packed:
|
||||
# `temp_raw = (target << 16) | current`, both °C as ints.
|
||||
#
|
||||
# The legacy top-level `nozzle_temper`/`nozzle_target_temper` fields track
|
||||
# whichever nozzle is currently *active*, not specifically the right one —
|
||||
# on printers like the X2D they report the left nozzle's temp while it's
|
||||
# printing, even though the dashboard's "Right Nozzle" card reads them.
|
||||
# Prefer the decoded right-side value from extruder.info[0] when present.
|
||||
nozzle_temp_left = None
|
||||
nozzle_target_temp_left = None
|
||||
nozzle_temp_right = None
|
||||
nozzle_target_temp_right = None
|
||||
device = print_data.get("device") or {}
|
||||
extruders = (device.get("extruder") or {}).get("info") or []
|
||||
if len(extruders) >= 2:
|
||||
right = extruders[0]
|
||||
t = right.get("temp")
|
||||
if isinstance(t, int):
|
||||
nozzle_target_temp_right = float((t >> 16) & 0xFFFF)
|
||||
nozzle_temp_right = float(t & 0xFFFF)
|
||||
|
||||
left = extruders[1]
|
||||
t = left.get("temp")
|
||||
if isinstance(t, int):
|
||||
@@ -510,8 +525,14 @@ class PrinterState:
|
||||
return cls(
|
||||
timestamp=timestamp,
|
||||
sequence_id=str(print_data.get("sequence_id", "")),
|
||||
nozzle_temp=float(print_data.get("nozzle_temper", 0.0)),
|
||||
nozzle_target_temp=float(print_data.get("nozzle_target_temper", 0.0)),
|
||||
nozzle_temp=(
|
||||
nozzle_temp_right if nozzle_temp_right is not None
|
||||
else float(print_data.get("nozzle_temper", 0.0))
|
||||
),
|
||||
nozzle_target_temp=(
|
||||
nozzle_target_temp_right if nozzle_target_temp_right is not None
|
||||
else float(print_data.get("nozzle_target_temper", 0.0))
|
||||
),
|
||||
bed_temp=float(print_data.get("bed_temper", 0.0)),
|
||||
bed_target_temp=float(print_data.get("bed_target_temper", 0.0)),
|
||||
chamber_temp=float(print_data.get("chamber_temper", 0.0)),
|
||||
@@ -809,6 +830,7 @@ class BambuPrinter:
|
||||
self._accumulator = PrinterStateAccumulator()
|
||||
self._connected = False
|
||||
self._devices: List[Dict[str, Any]] = []
|
||||
self._last_message_at: Optional[float] = None
|
||||
|
||||
def _get_fresh_token(self, verification_code_timeout: int = 300) -> str:
|
||||
"""Get a fresh token using credentials."""
|
||||
@@ -914,6 +936,30 @@ class BambuPrinter:
|
||||
"""Internal MQTT message handler"""
|
||||
if not data:
|
||||
return
|
||||
|
||||
# The printer publishes partial deltas most of the time; the accumulator
|
||||
# merges them onto whatever it already has. If the printer went offline
|
||||
# (power cycle) and just reconnected, the first delta after the gap would
|
||||
# otherwise be merged onto stale pre-outage state, leaving fields like
|
||||
# nozzle_temp frozen at their last value until some unrelated full report
|
||||
# happens to refresh them. Detect the gap and force a full pushall so the
|
||||
# accumulator gets a clean, complete state instead.
|
||||
now = time.time()
|
||||
if (
|
||||
self._last_message_at is not None
|
||||
and now - self._last_message_at > app_settings.MQTT_RESYNC_GAP_SECONDS
|
||||
and self._mqtt is not None
|
||||
):
|
||||
try:
|
||||
self._mqtt.request_full_status()
|
||||
logger.info(
|
||||
"MQTT report gap of %.0fs detected for %s; requested full status re-sync",
|
||||
now - self._last_message_at, device_id,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning("Full status re-sync request failed (non-fatal): %s", e)
|
||||
self._last_message_at = now
|
||||
|
||||
state = self._accumulator.update(data)
|
||||
if self._on_update:
|
||||
self._on_update(state)
|
||||
|
||||
@@ -28,7 +28,13 @@ _METRICS_API_FIELDS = [
|
||||
'gcode_state', 'print_type', 'subtask_name',
|
||||
'external_spool',
|
||||
]
|
||||
_MAX_CHART_POINTS = 3000
|
||||
# 24h at the collector's 30s cadence is ~2800 readings, and every one of them
|
||||
# also drags in ~9 FilamentSnapshot rows — that snapshot fetch, not the metrics
|
||||
# query, is what dominated the dashboard's load time (measured: 2.09s of context
|
||||
# building and a 410 KB payload at 3000). 1440 caps the series at roughly one
|
||||
# point per minute over a day, which is finer than any chart can resolve on
|
||||
# screen, and cuts both the server time and the payload by ~4x.
|
||||
_MAX_CHART_POINTS = 1440
|
||||
# Fallback window for requests that don't specify a full date range. Without it a
|
||||
# bare API call scans the entire metrics table.
|
||||
_DEFAULT_WINDOW = timedelta(hours=24)
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "bambu-run"
|
||||
version = "0.1.10"
|
||||
version = "0.1.14"
|
||||
description = "Django reusable app for Bambu Lab 3D printer monitoring and filament inventory management"
|
||||
readme = "README.md"
|
||||
license = {text = "MIT"}
|
||||
|
||||
Reference in New Issue
Block a user