Improvement: Better communication with user while using NFC
Improvement: Skip updating SpoolMan when there is no change in active tray
This commit is contained in:
parent
3a6ecf8e9f
commit
6d7eada993
11
app.py
11
app.py
@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import traceback
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from flask import Flask, request, render_template_string
|
from flask import Flask, request, render_template_string
|
||||||
@ -120,6 +121,7 @@ def tray_load():
|
|||||||
<p>Updated Spool ID {spool_id} with TAG id {tag_id} to AMS {ams_id}, Tray {tray_id}.</p>
|
<p>Updated Spool ID {spool_id} with TAG id {tag_id} to AMS {ams_id}, Tray {tray_id}.</p>
|
||||||
"""
|
"""
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
traceback.print_exc()
|
||||||
return f"<h1>Error</h1><p>{str(e)}</p>"
|
return f"<h1>Error</h1><p>{str(e)}</p>"
|
||||||
|
|
||||||
|
|
||||||
@ -162,11 +164,12 @@ def home():
|
|||||||
<ul>
|
<ul>
|
||||||
"""
|
"""
|
||||||
for spool in spools:
|
for spool in spools:
|
||||||
if not spool.get("extra", {}).get("tag"):
|
if not spool.get("extra", {}).get("tag") or spool.get("extra", {}).get("tag") == json.dumps(""):
|
||||||
html += f"<li><a href='/assign_tag?spool_id={spool.get('id')}'>Spool {spool.get('filament').get('vendor').get('name')} - {spool.get('filament').get('name')}</a></li>"
|
html += f"<li><a href='/assign_tag?spool_id={spool.get('id')}'>Spool {spool.get('filament').get('vendor').get('name')} - {spool.get('filament').get('name')}</a></li>"
|
||||||
html += "</ul>"
|
html += "</ul>"
|
||||||
return html
|
return html
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
traceback.print_exc()
|
||||||
return f"<h1>Error</h1><p>{str(e)}</p>"
|
return f"<h1>Error</h1><p>{str(e)}</p>"
|
||||||
|
|
||||||
|
|
||||||
@ -189,12 +192,13 @@ def assign_tag():
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function writeNFC(){{
|
function writeNFC(){{
|
||||||
const ndef = new NDEFReader();
|
const ndef = new NDEFReader();
|
||||||
|
document.getElementById("message").textContent="Bring NFC Tag closer to the phone.";
|
||||||
ndef.write({{
|
ndef.write({{
|
||||||
records: [{{ recordType: "url", data: "{BASE_URL}/spool_info?tag_id={myuuid}" }}],
|
records: [{{ recordType: "url", data: "{BASE_URL}/spool_info?tag_id={myuuid}" }}],
|
||||||
}}).then(() => {{
|
}}).then(() => {{
|
||||||
alert("Message written.");
|
document.getElementById("message").textContent="Message written.";
|
||||||
}}).catch(error => {{
|
}}).catch(error => {{
|
||||||
alert(`Write failed :-( try again: ${{error}}.`);
|
document.getElementById("message").textContent="Write failed :-( try again: " + error + ".";
|
||||||
}});
|
}});
|
||||||
}};
|
}};
|
||||||
</script>
|
</script>
|
||||||
@ -202,6 +206,7 @@ def assign_tag():
|
|||||||
<body>
|
<body>
|
||||||
NFC Write
|
NFC Write
|
||||||
<button id="write" onclick="writeNFC()">Write</button>
|
<button id="write" onclick="writeNFC()">Write</button>
|
||||||
|
<h1 id="message"></h1>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
|
@ -31,7 +31,7 @@ def on_message(client, userdata, msg):
|
|||||||
# TODO: Consume spool
|
# TODO: Consume spool
|
||||||
try:
|
try:
|
||||||
data = json.loads(msg.payload.decode())
|
data = json.loads(msg.payload.decode())
|
||||||
print(data)
|
#print(data)
|
||||||
if "print" in data and "vt_tray" in data["print"]:
|
if "print" in data and "vt_tray" in data["print"]:
|
||||||
print(data)
|
print(data)
|
||||||
LAST_AMS_CONFIG["vt_tray"] = data["print"]["vt_tray"]
|
LAST_AMS_CONFIG["vt_tray"] = data["print"]["vt_tray"]
|
||||||
@ -79,15 +79,21 @@ def on_connect(client, userdata, flags, rc):
|
|||||||
|
|
||||||
|
|
||||||
def setActiveTray(spool_id, spool_extra, ams_id, tray_id):
|
def setActiveTray(spool_id, spool_extra, ams_id, tray_id):
|
||||||
patchExtraTags(spool_id, spool_extra, {
|
if spool_extra == None:
|
||||||
"active_tray": json.dumps(f"{PRINTER_ID}_{ams_id}_{tray_id}"),
|
spool_extra = {}
|
||||||
})
|
|
||||||
|
|
||||||
# Remove active tray from inactive spools
|
if not spool_extra.get("active_tray") or spool_extra.get("active_tray") != json.dumps(f"{PRINTER_ID}_{ams_id}_{tray_id}"):
|
||||||
for old_spool in SPOOLS:
|
patchExtraTags(spool_id, spool_extra, {
|
||||||
if spool_id != old_spool["id"] and old_spool["extra"]["active_tray"] == json.dumps(
|
"active_tray": json.dumps(f"{PRINTER_ID}_{ams_id}_{tray_id}"),
|
||||||
f"{PRINTER_ID}_{ams_id}_{tray_id}"):
|
})
|
||||||
patchExtraTags(old_spool["id"], old_spool["extra"], {"active_tray": json.dumps("")})
|
|
||||||
|
# Remove active tray from inactive spools
|
||||||
|
for old_spool in SPOOLS:
|
||||||
|
if spool_id != old_spool["id"] and old_spool["extra"]["active_tray"] == json.dumps(
|
||||||
|
f"{PRINTER_ID}_{ams_id}_{tray_id}"):
|
||||||
|
patchExtraTags(old_spool["id"], old_spool["extra"], {"active_tray": json.dumps("")})
|
||||||
|
else:
|
||||||
|
print("Skipping set active tray")
|
||||||
|
|
||||||
|
|
||||||
# Fetch spools from spoolman
|
# Fetch spools from spoolman
|
||||||
|
Loading…
x
Reference in New Issue
Block a user