added debug for loading config problems
This commit is contained in:
parent
af4355a83f
commit
cdf5f7a356
37
app.py
37
app.py
@ -53,7 +53,7 @@ def load_configs():
|
|||||||
def index():
|
def index():
|
||||||
return render_template('index.html', configs=load_configs())
|
return render_template('index.html', configs=load_configs())
|
||||||
|
|
||||||
|
"""
|
||||||
@app.route('/load_config/<filename>')
|
@app.route('/load_config/<filename>')
|
||||||
def load_config(filename):
|
def load_config(filename):
|
||||||
global current_config
|
global current_config
|
||||||
@ -69,13 +69,48 @@ def load_config(filename):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Config-Ladefehler {filename}: {e}")
|
logger.error(f"Config-Ladefehler {filename}: {e}")
|
||||||
return "Fehler beim Laden", 500
|
return "Fehler beim Laden", 500
|
||||||
|
"""
|
||||||
|
|
||||||
|
@app.route('/load_config/<filename>')
|
||||||
|
def load_config(filename):
|
||||||
|
global current_config
|
||||||
|
path = os.path.join(app.config['CONFIG_DIR'], filename)
|
||||||
|
|
||||||
|
if not os.path.exists(path):
|
||||||
|
logger.error(f"Config nicht gefunden: {path}")
|
||||||
|
return "Konfiguration nicht gefunden", 404
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(path, 'r', encoding='utf-8') as f:
|
||||||
|
current_config = json.load(f)
|
||||||
|
current_config['filename'] = filename
|
||||||
|
logger.info(f"Config erfolgreich geladen: {filename} mit {len(current_config.get('channels', []))} Kanälen")
|
||||||
|
return redirect(url_for('control_page'))
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
logger.error(f"Ungültiges JSON in {filename}: {e}")
|
||||||
|
return "Ungültiges JSON-Format in der Konfigurationsdatei", 500
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Ladefehler {filename}: {e}")
|
||||||
|
return "Fehler beim Laden der Konfiguration", 500
|
||||||
|
|
||||||
|
"""
|
||||||
@app.route('/control')
|
@app.route('/control')
|
||||||
def control_page():
|
def control_page():
|
||||||
if current_config is None:
|
if current_config is None:
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
return render_template('control.html', config=current_config)
|
return render_template('control.html', config=current_config)
|
||||||
|
"""
|
||||||
|
|
||||||
|
@app.route('/control')
|
||||||
|
def control_page():
|
||||||
|
if current_config is None:
|
||||||
|
logger.warning("current_config ist None → Redirect zu index")
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
logger.info(f"Übergebe config an Template: {current_config}")
|
||||||
|
print("DEBUG: config hat channels?", 'channels' in current_config, len(current_config.get('channels', [])))
|
||||||
|
|
||||||
|
return render_template('control.html', config=current_config)
|
||||||
|
|
||||||
|
|
||||||
# ── Admin ────────────────────────────────────────────────────────────────────
|
# ── Admin ────────────────────────────────────────────────────────────────────
|
||||||
|
|||||||
@ -1,12 +1,23 @@
|
|||||||
{
|
{
|
||||||
"name": "Dampflok BR 01",
|
"name": "BR 01 Dampflok",
|
||||||
"image": "dampflok1.jpg",
|
"image": "damkpflok1.jpg",
|
||||||
"hub_id": 0,
|
"hub_id": 0,
|
||||||
"hub_type": "4channel",
|
"hub_type": "4channel",
|
||||||
"channels": [
|
"channels": [
|
||||||
{"port": "A", "type": "motor", "name": "Fahrtrichtung", "invert": false, "negative_only": false},
|
{
|
||||||
{"port": "B", "type": "motor", "name": "Unterstützung", "invert": false, "negative_only": false},
|
"port": "A",
|
||||||
{"port": "C", "type": "light", "name": "Licht vorne", "on_value": 1.0, "off_value": 0.0, "negative_only": false},
|
"type": "motor",
|
||||||
{"port": "D", "type": "fogger", "name": "Dampf", "on_value": -1.0, "off_value": 0.0, "negative_only": true}
|
"name": "Fahrtrichtung"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"port": "B",
|
||||||
|
"type": "motor",
|
||||||
|
"name": "Dampf / Kohle"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"port": "C",
|
||||||
|
"type": "light",
|
||||||
|
"name": "Spitzenlicht"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -69,9 +69,19 @@
|
|||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
<!--
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script>
|
<script>
|
||||||
// Config direkt ins JS übergeben
|
// Config direkt ins JS übergeben
|
||||||
const config = {{ config | tojson | safe }};
|
const config = {{ config | tojson | safe }};
|
||||||
</script>
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
-->
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
const config = {{ config | tojson | safe }};
|
||||||
|
console.log("Config im JS:", config);
|
||||||
|
console.log("Channels:", config?.channels || "KEINE CHANNELS");
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Loading…
x
Reference in New Issue
Block a user