Add setup page for device registration and configuration
- Created a new HTML file for device setup with a form for API URL and registration code. - Implemented JavaScript for handling registration and displaying status messages. - Updated upgrade and WiFi pages to include navigation to the new setup page. - Refactored display functions to improve readability and consistency. - Replaced occurrences of `oledShowMessage` with `oledDisplayText` for uniformity. - Updated WebSocket handling in the upgrade and WiFi pages for better connection management. - Adjusted delays in various functions to use `pdMS_TO_TICKS` for better timing accuracy. - Removed unused routes and cleaned up the website code for improved maintainability.
This commit is contained in:
1 parent
1d0b01ba6e
commit
823d1f8c7e
15 files changed
+163
-447
No files matched your search
+1
-2
@@ -30,8 +30,7 @@
|
||||
<nav style="display: flex; gap: 1rem;">
|
||||
<a href="/">Start</a>
|
||||
<a href="/waage">Scale</a>
|
||||
<a href="/config">Config</a>
|
||||
<a href="/about">About</a>
|
||||
<a href="/setup">Setup</a>
|
||||
<a href="/upgrade">Upgrade</a>
|
||||
</nav>
|
||||
<div class="status-container">
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>FilaMan - Status</title>
|
||||
<link rel="icon" type="image/png" href="/favicon.ico">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<script>
|
||||
fetch('/api/version')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const versionSpan = document.querySelector('.version');
|
||||
if (versionSpan) {
|
||||
versionSpan.textContent = 'v' + data.version;
|
||||
}
|
||||
})
|
||||
.catch(error => console.error('Error fetching version:', error));
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="navbar">
|
||||
<div style="display: flex; align-items: center; gap: 2rem;">
|
||||
<img src="/logo.png" alt="FilaMan Logo" class="logo">
|
||||
<div class="logo-text">
|
||||
<h1>FilaMan<span class="version"></span></h1>
|
||||
<h4>Filament Management Tool</h4>
|
||||
</div>
|
||||
</div>
|
||||
<nav style="display: flex; gap: 1rem;">
|
||||
<a href="/">Start</a>
|
||||
<a href="/waage">Scale</a>
|
||||
<a href="/config">Config</a>
|
||||
<a href="/about">About</a>
|
||||
<a href="/upgrade">Upgrade</a>
|
||||
</nav>
|
||||
<div class="status-container">
|
||||
<div class="status-item">
|
||||
<span class="status-dot" id="filamanDot"></span>F
|
||||
</div>
|
||||
<div class="ram-status" id="ramStatus"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<h1>Device Status</h1>
|
||||
|
||||
<div class="three-column-layout">
|
||||
<div class="column">
|
||||
<div class="feature-box">
|
||||
<h2>Weight</h2>
|
||||
<div id="weightDisplay" style="font-size: 3rem; text-align: center; margin: 20px 0;">0g</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="feature-box">
|
||||
<h2>NFC Tag</h2>
|
||||
<div id="nfcDisplay" style="text-align: center; margin: 20px 0;">
|
||||
<p id="nfcInfo">No tag detected</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="rfid.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,80 +0,0 @@
|
||||
let socket;
|
||||
let isConnected = false;
|
||||
const RECONNECT_INTERVAL = 5000;
|
||||
|
||||
function initWebSocket() {
|
||||
if (socket) {
|
||||
socket.close();
|
||||
socket = null;
|
||||
}
|
||||
|
||||
try {
|
||||
socket = new WebSocket('ws://' + window.location.host + '/ws');
|
||||
|
||||
socket.onopen = function() {
|
||||
isConnected = true;
|
||||
console.log("WebSocket connected");
|
||||
};
|
||||
|
||||
socket.onclose = function() {
|
||||
isConnected = false;
|
||||
setTimeout(initWebSocket, RECONNECT_INTERVAL);
|
||||
};
|
||||
|
||||
socket.onmessage = function(event) {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.type === 'nfcData') {
|
||||
updateNfcDisplay(data.payload);
|
||||
} else if (data.type === 'heartbeat') {
|
||||
updateStatusDots(data);
|
||||
} else if (data.type === 'weight') {
|
||||
document.getElementById('weightDisplay').textContent = data.value + 'g';
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
isConnected = false;
|
||||
setTimeout(initWebSocket, RECONNECT_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
function updateStatusDots(data) {
|
||||
const filamanDot = document.getElementById('filamanDot');
|
||||
const ramStatus = document.getElementById('ramStatus');
|
||||
|
||||
if (filamanDot) {
|
||||
filamanDot.style.backgroundColor = data.filaman_connected ? '#4caf50' : '#f44336';
|
||||
}
|
||||
if (ramStatus) {
|
||||
ramStatus.textContent = `${data.freeHeap}k free`;
|
||||
}
|
||||
}
|
||||
|
||||
function updateNfcDisplay(data) {
|
||||
const nfcInfo = document.getElementById('nfcInfo');
|
||||
if (data.error || data.info || !data || Object.keys(data).length === 0) {
|
||||
nfcInfo.textContent = data.info || data.error || "No tag detected";
|
||||
return;
|
||||
}
|
||||
|
||||
let html = "<strong>Tag detected:</strong><br>";
|
||||
if (data.sm_id) {
|
||||
html += `Spool ID: ${data.sm_id}<br>`;
|
||||
if (data.brand) html += `Brand: ${data.brand}<br>`;
|
||||
if (data.type) html += `Material: ${data.type}<br>`;
|
||||
} else if (data.location_id) {
|
||||
html += `Location ID: ${data.location_id}<br>`;
|
||||
} else {
|
||||
html += "Unknown Tag Format";
|
||||
}
|
||||
nfcInfo.innerHTML = html;
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
initWebSocket();
|
||||
// Heartbeat loop
|
||||
setInterval(() => {
|
||||
if (socket && socket.readyState === WebSocket.OPEN) {
|
||||
socket.send(JSON.stringify({ type: 'heartbeat' }));
|
||||
}
|
||||
}, 5000);
|
||||
});
|
||||
@@ -3,41 +3,29 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>FilaMan - Configuration</title>
|
||||
<title>FilaMan - Setup</title>
|
||||
<link rel="icon" type="image/png" href="/favicon.ico">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<script>
|
||||
fetch('/api/version')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const versionSpan = document.querySelector('.version');
|
||||
if (versionSpan) {
|
||||
versionSpan.textContent = 'v' + data.version;
|
||||
}
|
||||
})
|
||||
.catch(error => console.error('Error fetching version:', error));
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="navbar">
|
||||
<div style="display: flex; align-items: center; gap: 2rem;">
|
||||
<img src="/logo.png" alt="FilaMan Logo" class="logo">
|
||||
<div class="logo-text">
|
||||
<h1>FilaMan<span class="version"></span></h1>
|
||||
<h1>FilaMan</h1>
|
||||
<h4>Filament Management Tool</h4>
|
||||
</div>
|
||||
</div>
|
||||
<nav style="display: flex; gap: 1rem;">
|
||||
<a href="/">Start</a>
|
||||
<a href="/waage">Scale</a>
|
||||
<a href="/config">Config</a>
|
||||
<a href="/about">About</a>
|
||||
<a href="/setup">Setup</a>
|
||||
<a href="/upgrade">Upgrade</a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<h1>Device Configuration</h1>
|
||||
<h1>Device Setup</h1>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
+23
-124
@@ -1,4 +1,4 @@
|
||||
<!-- head --><!DOCTYPE html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
@@ -30,8 +30,7 @@
|
||||
<nav style="display: flex; gap: 1rem;">
|
||||
<a href="/">Start</a>
|
||||
<a href="/waage">Scale</a>
|
||||
<a href="/config">Config</a>
|
||||
<a href="/about">About</a>
|
||||
<a href="/setup">Setup</a>
|
||||
<a href="/upgrade">Upgrade</a>
|
||||
</nav>
|
||||
<div class="status-container">
|
||||
@@ -42,8 +41,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- head -->
|
||||
|
||||
<div class="content">
|
||||
<h1>Firmware Upgrade</h1>
|
||||
|
||||
@@ -58,7 +55,7 @@
|
||||
<div class="update-form">
|
||||
<form id="firmwareForm" enctype='multipart/form-data' data-type="firmware">
|
||||
<input type='file' name='update' accept='.bin' required>
|
||||
<input type='submit' value='Start Firmware Update'>
|
||||
<input type='submit' value='Start Firmware Update' class="btn btn-primary">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -69,7 +66,7 @@
|
||||
<div class="update-form">
|
||||
<form id="webpageForm" enctype='multipart/form-data' data-type="webpage">
|
||||
<input type='file' name='update' accept='.bin' required>
|
||||
<input type='submit' value='Start Webpage Update'>
|
||||
<input type='submit' value='Start Webpage Update' class="btn btn-primary">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -82,12 +79,6 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Hide status indicators during update
|
||||
const statusContainer = document.querySelector('.status-container');
|
||||
if (statusContainer) {
|
||||
statusContainer.style.display = 'none';
|
||||
}
|
||||
|
||||
const progress = document.querySelector('.progress-bar');
|
||||
const progressContainer = document.querySelector('.progress-container');
|
||||
const status = document.querySelector('.status');
|
||||
@@ -96,150 +87,58 @@
|
||||
|
||||
// WebSocket Handling
|
||||
let ws = null;
|
||||
let wsReconnectTimer = null;
|
||||
|
||||
function connectWebSocket() {
|
||||
ws = new WebSocket('ws://' + window.location.host + '/ws');
|
||||
|
||||
ws.onmessage = function(event) {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.type === "updateProgress" && updateInProgress) {
|
||||
// Zeige Fortschrittsbalken
|
||||
progressContainer.style.display = 'block';
|
||||
|
||||
// Aktualisiere den Fortschritt nur wenn er größer ist
|
||||
const newProgress = parseInt(data.progress);
|
||||
if (!isNaN(newProgress) && newProgress >= lastReceivedProgress) {
|
||||
progress.style.width = newProgress + '%';
|
||||
progress.textContent = newProgress + '%';
|
||||
lastReceivedProgress = newProgress;
|
||||
}
|
||||
|
||||
// Zeige Status-Nachricht
|
||||
if (data.message || data.status) {
|
||||
status.textContent = data.message || getStatusMessage(data.status);
|
||||
status.className = 'status success';
|
||||
status.style.display = 'block';
|
||||
|
||||
// Starte Reload wenn Update erfolgreich
|
||||
if (data.status === 'success' || lastReceivedProgress >= 98) {
|
||||
clearTimeout(wsReconnectTimer);
|
||||
setTimeout(() => {
|
||||
window.location.reload(true);
|
||||
window.location.href = '/';
|
||||
}, 30000);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('WebSocket message error:', e);
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.type === "heartbeat") {
|
||||
document.getElementById('filamanDot').style.backgroundColor = data.filaman_connected ? '#4caf50' : '#f44336';
|
||||
document.getElementById('ramStatus').textContent = data.freeHeap + ' KB free';
|
||||
}
|
||||
};
|
||||
|
||||
ws.onclose = function() {
|
||||
if (updateInProgress) {
|
||||
// Wenn der Fortschritt hoch genug ist, gehen wir von einem erfolgreichen Update aus
|
||||
if (lastReceivedProgress >= 85) {
|
||||
status.textContent = "Update appears successful! Device is restarting... Page will reload in 30 seconds.";
|
||||
status.className = 'status success';
|
||||
if (data.type === "updateProgress" && updateInProgress) {
|
||||
progressContainer.style.display = 'block';
|
||||
const newProgress = parseInt(data.progress);
|
||||
if (!isNaN(newProgress) && newProgress >= lastReceivedProgress) {
|
||||
progress.style.width = newProgress + '%';
|
||||
progress.textContent = newProgress + '%';
|
||||
lastReceivedProgress = newProgress;
|
||||
}
|
||||
if (data.message) {
|
||||
status.textContent = data.message;
|
||||
status.style.display = 'block';
|
||||
clearTimeout(wsReconnectTimer);
|
||||
setTimeout(() => {
|
||||
window.location.reload(true);
|
||||
window.location.href = '/';
|
||||
}, 30000);
|
||||
} else {
|
||||
// Versuche Reconnect bei niedrigem Fortschritt
|
||||
wsReconnectTimer = setTimeout(connectWebSocket, 1000);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ws.onerror = function(err) {
|
||||
console.error('WebSocket error:', err);
|
||||
if (updateInProgress && lastReceivedProgress >= 85) {
|
||||
status.textContent = "Update appears successful! Device is restarting... Page will reload in 30 seconds.";
|
||||
status.className = 'status success';
|
||||
status.style.display = 'block';
|
||||
setTimeout(() => {
|
||||
window.location.href = '/';
|
||||
}, 30000);
|
||||
}
|
||||
};
|
||||
ws.onclose = () => setTimeout(connectWebSocket, 2000);
|
||||
}
|
||||
|
||||
// Initial WebSocket connection
|
||||
connectWebSocket();
|
||||
|
||||
function getStatusMessage(status) {
|
||||
switch(status) {
|
||||
case 'starting': return 'Starting update...';
|
||||
case 'uploading': return 'Uploading...';
|
||||
case 'finalizing': return 'Finalizing update...';
|
||||
case 'restoring': return 'Restoring configurations...';
|
||||
case 'preparing': return 'Preparing for restart...';
|
||||
case 'success': return 'Update successful! Device is restarting... Page will reload in 30 seconds.';
|
||||
default: return 'Updating...';
|
||||
}
|
||||
}
|
||||
|
||||
function handleUpdate(e) {
|
||||
e.preventDefault();
|
||||
const form = e.target;
|
||||
const file = form.update.files[0];
|
||||
const updateType = form.dataset.type;
|
||||
|
||||
if (!file) {
|
||||
alert('Please select a file.');
|
||||
return;
|
||||
}
|
||||
if (!file) return;
|
||||
|
||||
// Validate file name pattern
|
||||
if (updateType === 'firmware' && !file.name.startsWith('upgrade_filaman_firmware_')) {
|
||||
alert('Please select a valid firmware file (upgrade_filaman_firmware_*.bin)');
|
||||
return;
|
||||
}
|
||||
if (updateType === 'webpage' && !file.name.startsWith('upgrade_filaman_website_')) {
|
||||
alert('Please select a valid webpage file (upgrade_filaman_website_*.bin)');
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset UI
|
||||
updateInProgress = true;
|
||||
progressContainer.style.display = 'block';
|
||||
status.style.display = 'none';
|
||||
status.className = 'status';
|
||||
progress.style.width = '0%';
|
||||
progress.textContent = '0%';
|
||||
|
||||
// Disable submit buttons
|
||||
document.querySelectorAll('form input[type=submit]').forEach(btn => btn.disabled = true);
|
||||
|
||||
// Send update
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/update', true);
|
||||
|
||||
xhr.onload = function() {
|
||||
if (xhr.status !== 200 && !progress.textContent.startsWith('100')) {
|
||||
status.textContent = "Update failed: " + (xhr.responseText || "Unknown error");
|
||||
status.className = 'status error';
|
||||
if (xhr.status !== 200) {
|
||||
status.textContent = "Update failed: " + xhr.responseText;
|
||||
status.style.display = 'block';
|
||||
updateInProgress = false;
|
||||
document.querySelectorAll('form input[type=submit]').forEach(btn => btn.disabled = false);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function() {
|
||||
if (!progress.textContent.startsWith('100')) {
|
||||
status.textContent = "Network error during update";
|
||||
status.className = 'status error';
|
||||
status.style.display = 'block';
|
||||
updateInProgress = false;
|
||||
document.querySelectorAll('form input[type=submit]').forEach(btn => btn.disabled = false);
|
||||
}
|
||||
};
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('update', file);
|
||||
xhr.send(formData);
|
||||
@@ -249,4 +148,4 @@
|
||||
document.getElementById('webpageForm').addEventListener('submit', handleUpdate);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
+22
-12
@@ -1,4 +1,4 @@
|
||||
<!-- head --><!DOCTYPE html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
@@ -30,8 +30,7 @@
|
||||
<nav style="display: flex; gap: 1rem;">
|
||||
<a href="/">Start</a>
|
||||
<a href="/waage">Scale</a>
|
||||
<a href="/config">Config</a>
|
||||
<a href="/about">About</a>
|
||||
<a href="/setup">Setup</a>
|
||||
<a href="/upgrade">Upgrade</a>
|
||||
</nav>
|
||||
<div class="status-container">
|
||||
@@ -42,16 +41,27 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- head -->
|
||||
|
||||
<div class="content">
|
||||
<h1>WiFi Configuration Page</h1>
|
||||
<form action="/setToken" method="post">
|
||||
<label for="deviceToken">Device Token:</label><br>
|
||||
<input type="text" id="deviceToken" name="deviceToken"><br>
|
||||
<input type="submit" value="Set Token">
|
||||
</form>
|
||||
<p>Configure your WiFi settings here.</p>
|
||||
<h1>WiFi Configuration</h1>
|
||||
<p>Your device is connected to WiFi.</p>
|
||||
<p>To change WiFi settings, you can reset the WiFi configuration by holding the hardware button (if available) or using the WiFi manager portal.</p>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let ws = null;
|
||||
function connectWebSocket() {
|
||||
ws = new WebSocket(`ws://${window.location.hostname}/ws`);
|
||||
ws.onmessage = (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.type === 'heartbeat') {
|
||||
document.getElementById('filamanDot').style.backgroundColor = data.filaman_connected ? '#4caf50' : '#f44336';
|
||||
document.getElementById('ramStatus').textContent = data.freeHeap + ' KB free';
|
||||
}
|
||||
};
|
||||
ws.onclose = () => setTimeout(connectWebSocket, 2000);
|
||||
}
|
||||
connectWebSocket();
|
||||
setInterval(() => { if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({type:'heartbeat'})); }, 5000);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+2
-14
@@ -145,7 +145,7 @@ void oledShowMultilineMessage(const String &message, uint8_t size) {
|
||||
display.display();
|
||||
}
|
||||
|
||||
void oledShowMessage(const String &message, uint8_t size) {
|
||||
void oledDisplayText(const String &message, uint8_t size) {
|
||||
oledcleardata();
|
||||
display.setTextSize(size);
|
||||
display.setTextWrap(false);
|
||||
@@ -177,19 +177,7 @@ void oledShowTopRow() {
|
||||
|
||||
// Do not show status indicators during boot
|
||||
if(!booting){
|
||||
if(bambuDisabled == false) {
|
||||
if (bambu_connected == 1) {
|
||||
display.drawBitmap(50, 0, bitmap_bambu_on , 16, 16, WHITE);
|
||||
} else {
|
||||
if(iconToggle){
|
||||
display.drawBitmap(50, 0, bitmap_bambu_on , 16, 16, WHITE);
|
||||
display.drawLine(50, 15, 66, 0, WHITE);
|
||||
display.drawLine(51, 15, 67, 0, WHITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (spoolmanConnected) {
|
||||
if (filamanConnected) {
|
||||
display.drawBitmap(80, 0, bitmap_spoolman_on , 16, 16, WHITE);
|
||||
} else {
|
||||
if(iconToggle){
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ int oled_center_v(const String &text);
|
||||
void oledShowProgressBar(const uint8_t step, const uint8_t numSteps, const char* largeText, const char* statusMessage);
|
||||
|
||||
void oledShowWeight(uint16_t weight);
|
||||
void oledShowMessage(const String &message, uint8_t size = 2);
|
||||
void oledDisplayText(const String &message, uint8_t size = 2);
|
||||
void oledShowTopRow();
|
||||
void oledShowIcon(const char* icon);
|
||||
|
||||
|
||||
+10
-3
@@ -1,6 +1,8 @@
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <WiFi.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
#include "wlan.h"
|
||||
#include "config.h"
|
||||
@@ -86,6 +88,11 @@ unsigned long lastWeightReadTime = 0;
|
||||
const unsigned long weightReadInterval = 1000; // 1 second
|
||||
|
||||
unsigned long lastFilamanHeartbeatTime = 0;
|
||||
unsigned long lastWifiCheckTime = 0;
|
||||
unsigned long lastTopRowUpdateTime = 0;
|
||||
|
||||
uint8_t weightSend = 0;
|
||||
int16_t lastWeight = 0;
|
||||
|
||||
// Button debounce variables
|
||||
unsigned long lastButtonPress = 0;
|
||||
@@ -125,8 +132,8 @@ void loop() {
|
||||
{
|
||||
// Do not show the warning if the calibratin process is onging
|
||||
if(!scaleCalibrationActive){
|
||||
oledShowMessage("Scale not calibrated");
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
oledDisplayText("Scale not calibrated");
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -139,7 +146,7 @@ void loop() {
|
||||
int16_t displayWeight = getFilteredDisplayWeight();
|
||||
if (mainTaskWasPaused || (weight != lastWeight && nfcReaderState == NFC_IDLE))
|
||||
{
|
||||
(displayWeight < 2) ? ((displayWeight < -2) ? oledShowMessage("!! -0") : oledShowWeight(0)) : oledShowWeight(displayWeight);
|
||||
(displayWeight < 2) ? ((displayWeight < -2) ? oledDisplayText("!! -0") : oledShowWeight(0)) : oledShowWeight(displayWeight);
|
||||
}
|
||||
mainTaskWasPaused = false;
|
||||
}
|
||||
|
||||
+76
-91
@@ -386,7 +386,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
}
|
||||
|
||||
// Small delay to prevent interface overload
|
||||
vTaskDelay(5 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(5));
|
||||
yield();
|
||||
}
|
||||
|
||||
@@ -464,8 +464,9 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
Serial.println();
|
||||
|
||||
oledShowMessage("Tag zu klein für Payload");
|
||||
vTaskDelay(3000 / portTICK_PERIOD_MS);
|
||||
oledDisplayText("Tag zu klein für Payload");
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -495,7 +496,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
|
||||
// Reinitialize the PN532
|
||||
nfc.begin();
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS); // Give it time to initialize
|
||||
vTaskDelay(pdMS_TO_TICKS(500)); // Give it time to initialize
|
||||
|
||||
// Check firmware version to ensure communication is working
|
||||
uint32_t versiondata = nfc.getFirmwareVersion();
|
||||
@@ -505,15 +506,16 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
Serial.println("✓ PN532 Kommunikation wiederhergestellt");
|
||||
} else {
|
||||
Serial.println("❌ PN532 Kommunikation fehlgeschlagen");
|
||||
oledShowMessage("NFC Reset failed");
|
||||
vTaskDelay(3000 / portTICK_PERIOD_MS);
|
||||
oledDisplayText("NFC Reset failed");
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Step 2: Reconfigure SAM
|
||||
Serial.println("2. SAM-Konfiguration...");
|
||||
nfc.SAMConfig();
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
|
||||
// Step 3: Re-detect the tag
|
||||
Serial.println("3. Tag-Wiedererkennung...");
|
||||
@@ -532,14 +534,15 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
break;
|
||||
} else {
|
||||
Serial.println("❌");
|
||||
vTaskDelay(300 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(300));
|
||||
}
|
||||
}
|
||||
|
||||
if (!tagRedetected) {
|
||||
Serial.println("❌ Tag konnte nach Reset nicht wiedererkannt werden");
|
||||
oledShowMessage("Tag lost after reset");
|
||||
vTaskDelay(3000 / portTICK_PERIOD_MS);
|
||||
oledDisplayText("Tag lost after reset");
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -547,7 +550,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
|
||||
// Step 4: Test basic page reading
|
||||
Serial.println("4. Test der Grundfunktionalität...");
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS); // Give interface time to stabilize
|
||||
vTaskDelay(pdMS_TO_TICKS(200)); // Give interface time to stabilize
|
||||
|
||||
ccReadable = nfc.ntag2xx_ReadPage(3, ccTest);
|
||||
Serial.print("Capability Container nach Reset lesbar: ");
|
||||
@@ -555,8 +558,9 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
|
||||
if (!ccReadable) {
|
||||
Serial.println("❌ NFC-Interface funktioniert nach Reset immer noch nicht");
|
||||
oledShowMessage("NFC still broken");
|
||||
vTaskDelay(3000 / portTICK_PERIOD_MS);
|
||||
oledDisplayText("NFC still broken");
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -601,14 +605,15 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
basicPagesReadable = false;
|
||||
}
|
||||
}
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS); // Small delay between reads
|
||||
vTaskDelay(pdMS_TO_TICKS(10)); // Small delay between reads
|
||||
}
|
||||
|
||||
if (!basicPagesReadable) {
|
||||
Serial.println("❌ KRITISCHER FEHLER: Grundlegende NDEF-Seiten nicht lesbar!");
|
||||
Serial.println("Tag oder Interface ist defekt");
|
||||
oledShowMessage("Tag/Interface defect");
|
||||
vTaskDelay(3000 / portTICK_PERIOD_MS);
|
||||
oledDisplayText("Tag/Interface defect");
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -627,8 +632,9 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
// First, read original content of test page
|
||||
if (!nfc.ntag2xx_ReadPage(10, originalPage)) {
|
||||
Serial.println("FEHLER: Kann Testseite nicht lesen für Backup");
|
||||
oledShowMessage("Test page read error");
|
||||
vTaskDelay(3000 / portTICK_PERIOD_MS);
|
||||
oledDisplayText("Test page read error");
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -657,26 +663,28 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
|
||||
if (!tagStillPresent) {
|
||||
Serial.println("URSACHE: Tag wurde während Schreibtest entfernt!");
|
||||
oledShowMessage("Tag removed");
|
||||
oledDisplayText("Tag removed");
|
||||
} else {
|
||||
Serial.println("URSACHE: Tag ist vorhanden aber nicht beschreibbar");
|
||||
Serial.println("Möglicherweise: Schreibschutz, Defekt, oder Interface-Problem");
|
||||
oledShowMessage("Tag write protected?");
|
||||
oledDisplayText("Tag write protected?");
|
||||
}
|
||||
Serial.println("==========================================");
|
||||
|
||||
vTaskDelay(3000 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Verify test write
|
||||
uint8_t readBack[4];
|
||||
vTaskDelay(20 / portTICK_PERIOD_MS); // Wait for write to complete
|
||||
vTaskDelay(pdMS_TO_TICKS(20)); // Wait for write to complete
|
||||
|
||||
if (!nfc.ntag2xx_ReadPage(10, readBack)) {
|
||||
Serial.println("FEHLER: Kann Testdaten nicht zurücklesen!");
|
||||
oledShowMessage("Test verify failed");
|
||||
vTaskDelay(3000 / portTICK_PERIOD_MS);
|
||||
oledDisplayText("Test verify failed");
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -719,8 +727,8 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
Serial.println("=== SCHRITT 4: NDEF-INITIALISIERUNG ===");
|
||||
if (!initializeNdefStructure()) {
|
||||
Serial.println("FEHLER: Konnte NDEF-Struktur nicht initialisieren!");
|
||||
oledShowMessage("NDEF init failed");
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
oledDisplayText("NDEF init failed");
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -753,7 +761,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
Serial.println("Stabilisiere NFC-Interface vor Hauptschreibvorgang...");
|
||||
|
||||
// Give the interface time to fully settle after NDEF initialization
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
|
||||
// Test interface stability with a simple read
|
||||
uint8_t stabilityTest[4];
|
||||
@@ -769,14 +777,15 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
Serial.print("Interface stability test ");
|
||||
Serial.print(attempts + 1);
|
||||
Serial.println("/3: ❌");
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
}
|
||||
}
|
||||
|
||||
if (!interfaceStable) {
|
||||
Serial.println("FEHLER: NFC-Interface ist nicht stabil genug für Schreibvorgang");
|
||||
oledShowMessage("NFC Interface unstable");
|
||||
vTaskDelay(3000 / portTICK_PERIOD_MS);
|
||||
oledDisplayText("NFC Interface unstable");
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -787,8 +796,8 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
uint8_t* tlvData = (uint8_t*) malloc(totalTlvSize);
|
||||
if (tlvData == NULL) {
|
||||
Serial.println("Fehler: Nicht genug Speicher für TLV-Daten vorhanden.");
|
||||
oledShowMessage("Memory error");
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
oledDisplayText("Memory error");
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -881,7 +890,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
Serial.println(" fehlgeschlagen");
|
||||
|
||||
if (writeAttempt < 2) {
|
||||
vTaskDelay(50 / portTICK_PERIOD_MS); // Wait before retry
|
||||
vTaskDelay(pdMS_TO_TICKS(50)); // Wait before retry
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -911,7 +920,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
Serial.print("... ");
|
||||
|
||||
uint8_t verifyBuffer[4];
|
||||
vTaskDelay(20 / portTICK_PERIOD_MS); // Increased delay before verification
|
||||
vTaskDelay(pdMS_TO_TICKS(20)); // Increased delay before verification
|
||||
|
||||
// Verification with retry mechanism
|
||||
bool verifySuccess = false;
|
||||
@@ -939,14 +948,14 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
Serial.print("Verifikationsversuch ");
|
||||
Serial.print(verifyAttempt + 1);
|
||||
Serial.println("/3 fehlgeschlagen, wiederhole...");
|
||||
vTaskDelay(30 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(30));
|
||||
}
|
||||
} else {
|
||||
Serial.print("Verifikations-Read-Versuch ");
|
||||
Serial.print(verifyAttempt + 1);
|
||||
Serial.println("/3 fehlgeschlagen");
|
||||
if (verifyAttempt < 2) {
|
||||
vTaskDelay(30 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(30));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -973,7 +982,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
pageNumber++;
|
||||
|
||||
yield();
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS); // Slightly increased delay between page writes
|
||||
vTaskDelay(pdMS_TO_TICKS(10)); // Slightly increased delay between page writes
|
||||
}
|
||||
|
||||
free(tlvData);
|
||||
@@ -1006,7 +1015,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
Serial.println("Stabilisiere NFC-Interface nach Schreibvorgang...");
|
||||
|
||||
// Give the tag and interface time to settle after write operation
|
||||
vTaskDelay(300 / portTICK_PERIOD_MS); // Increased stabilization time
|
||||
vTaskDelay(pdMS_TO_TICKS(300)); // Increased stabilization time
|
||||
|
||||
// Test if the interface is still responsive
|
||||
uint8_t postWriteTest[4];
|
||||
@@ -1026,7 +1035,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
|
||||
if (stabilityAttempt < 4) {
|
||||
Serial.println("Warte und versuche Interface zu stabilisieren...");
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
|
||||
// Try to re-establish communication with a simple tag presence check
|
||||
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
|
||||
@@ -1056,7 +1065,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) {
|
||||
}
|
||||
|
||||
bool decodeNdefAndReturnJson(const byte* encodedMessage, String uidString) {
|
||||
oledShowProgressBar(1, octoEnabled?5:4, "Reading", "Decoding data");
|
||||
oledShowProgressBar(1, 4, "Reading", "Decoding data");
|
||||
|
||||
// Debug: Print first 32 bytes of the raw data
|
||||
Serial.println("Raw NDEF data (first 32 bytes):");
|
||||
@@ -1253,6 +1262,7 @@ bool decodeNdefAndReturnJson(const byte* encodedMessage, String uidString) {
|
||||
activeSpoolId = doc["sm_id"].as<String>();
|
||||
lastSpoolId = activeSpoolId;
|
||||
}
|
||||
|
||||
else if(doc["location_id"].is<int>())
|
||||
{
|
||||
Serial.println("Location Tag found!");
|
||||
@@ -1573,10 +1583,9 @@ void writeJsonToTag(void *parameter) {
|
||||
// Just use nfcWriteInProgress to prevent scanning and fast-path operations
|
||||
Serial.println("NFC Write Task starting - High-level operations blocked, low-level NFC available");
|
||||
|
||||
//pauseBambuMqttTask = true;
|
||||
// aktualisieren der Website wenn sich der Status ändert
|
||||
sendNfcData();
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
|
||||
// Show waiting message for tag detection
|
||||
oledShowProgressBar(0, 1, "Write Tag", "Warte auf Tag");
|
||||
@@ -1617,43 +1626,13 @@ void writeJsonToTag(void *parameter) {
|
||||
if (success)
|
||||
{
|
||||
Serial.println("NDEF-Message erfolgreich auf den Tag geschrieben");
|
||||
//oledShowMessage("NFC-Tag written");
|
||||
//vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
//oledDisplayText("NFC-Tag written");
|
||||
//vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
nfcReaderState = NFC_WRITE_SUCCESS;
|
||||
// aktualisieren der Website wenn sich der Status ändert
|
||||
sendNfcData();
|
||||
pauseBambuMqttTask = false;
|
||||
|
||||
if(params->tagType){
|
||||
// TBD: should this be simplified?
|
||||
if (updateSpoolTagId(uidString, params->payload) && params->tagType) {
|
||||
// Check if weight is over 20g and send to Spoolman
|
||||
if (weight > 20) {
|
||||
Serial.println("Tag successfully written and weight > 20g - sending weight to Spoolman");
|
||||
|
||||
// Extract spool ID from payload for weight update
|
||||
JsonDocument payloadDoc;
|
||||
DeserializationError error = deserializeJson(payloadDoc, params->payload);
|
||||
|
||||
if (!error && payloadDoc["sm_id"].is<String>()) {
|
||||
String spoolId = payloadDoc["sm_id"].as<String>();
|
||||
if (spoolId != "") {
|
||||
Serial.printf("Updating spool %s with weight %dg\n", spoolId.c_str(), weight);
|
||||
updateSpoolWeight(spoolId, weight);
|
||||
} else {
|
||||
Serial.println("No valid spool ID found for weight update");
|
||||
}
|
||||
} else {
|
||||
Serial.println("Error parsing payload for spool ID extraction");
|
||||
}
|
||||
|
||||
payloadDoc.clear();
|
||||
} else {
|
||||
Serial.printf("Weight %dg is not above 20g threshold - skipping weight update\n", weight);
|
||||
}
|
||||
}else{
|
||||
// Potentially handle errors
|
||||
}
|
||||
oledShowProgressBar(1, 1, "Write Tag", "Done!");
|
||||
}else{
|
||||
oledShowProgressBar(1, 1, "Write Tag", "Done!");
|
||||
}
|
||||
@@ -1663,7 +1642,7 @@ void writeJsonToTag(void *parameter) {
|
||||
Serial.println("=== POST-WRITE NFC STABILIZATION ===");
|
||||
|
||||
// Wait for tag operations to complete
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
|
||||
// Test tag presence and remove detection
|
||||
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
|
||||
@@ -1689,7 +1668,7 @@ void writeJsonToTag(void *parameter) {
|
||||
Serial.print(tagRemovalChecks);
|
||||
Serial.println("/10)");
|
||||
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
}
|
||||
|
||||
if (tagRemovalChecks >= 10) {
|
||||
@@ -1698,7 +1677,7 @@ void writeJsonToTag(void *parameter) {
|
||||
|
||||
// Additional interface stabilization before resuming normal operations
|
||||
Serial.println("Stabilisiere NFC-Interface für normale Operationen...");
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
|
||||
// Test if interface is ready for normal scanning
|
||||
uint8_t interfaceTestBuffer[4];
|
||||
@@ -1719,7 +1698,7 @@ void writeJsonToTag(void *parameter) {
|
||||
break;
|
||||
} else {
|
||||
Serial.println("❌");
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1732,13 +1711,13 @@ void writeJsonToTag(void *parameter) {
|
||||
Serial.println("=========================================");
|
||||
|
||||
vTaskResume(RfidReaderTask);
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Fehler beim Schreiben der NDEF-Message auf den Tag");
|
||||
oledShowIcon("failed");
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
nfcReaderState = NFC_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -1746,7 +1725,7 @@ void writeJsonToTag(void *parameter) {
|
||||
{
|
||||
Serial.println("Fehler: Kein Tag zu schreiben gefunden.");
|
||||
oledShowProgressBar(1, 1, "Failure!", "No tag found");
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
nfcReaderState = NFC_IDLE;
|
||||
}
|
||||
|
||||
@@ -1892,7 +1871,10 @@ void scanRfidTask(void * parameter) {
|
||||
if (!success) {
|
||||
activeSpoolId = "";
|
||||
activeTagUuid = "";
|
||||
Serial.println("Tag entfernt");
|
||||
oledShowWeight(weight);
|
||||
}
|
||||
|
||||
|
||||
// As long as there is still a tag on the reader, do not try to read it again
|
||||
if (success && nfcReaderState == NFC_IDLE)
|
||||
@@ -1909,7 +1891,7 @@ void scanRfidTask(void * parameter) {
|
||||
|
||||
// Reduced stabilization time for better responsiveness
|
||||
Serial.println("Tag detected, minimal stabilization...");
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS); // Reduced from 1000ms to 200ms
|
||||
vTaskDelay(pdMS_TO_TICKS(200)); // Reduced from 1000ms to 200ms
|
||||
|
||||
// create Tag UID string
|
||||
String uidString = "";
|
||||
@@ -1927,7 +1909,6 @@ void scanRfidTask(void * parameter) {
|
||||
// Try fast-path detection first for known spools
|
||||
if (quickSpoolIdCheck(uidString)) {
|
||||
Serial.println("✓ FAST-PATH: Tag processed quickly, skipping full read");
|
||||
pauseBambuMqttTask = false;
|
||||
// Set reader back to idle for next scan
|
||||
nfcReaderState = NFC_READ_SUCCESS;
|
||||
delay(500); // Small delay before next scan
|
||||
@@ -2012,9 +1993,11 @@ void scanRfidTask(void * parameter) {
|
||||
//uidString = "";
|
||||
nfcJsonData = "";
|
||||
activeSpoolId = "";
|
||||
activeTagUuid = "";
|
||||
Serial.println("Tag entfernt");
|
||||
if (!bambuCredentials.autosend_enable) oledShowWeight(weight);
|
||||
oledShowWeight(weight);
|
||||
}
|
||||
|
||||
// Reset state after successful read when tag is removed
|
||||
else if (!success && nfcReaderState == NFC_READ_SUCCESS)
|
||||
{
|
||||
@@ -2025,10 +2008,12 @@ void scanRfidTask(void * parameter) {
|
||||
// Add a pause after successful reading to prevent immediate re-reading
|
||||
if (nfcReaderState == NFC_READ_SUCCESS) {
|
||||
Serial.println("Tag erfolgreich gelesen - warte 3 Sekunden vor nächstem Scan");
|
||||
vTaskDelay(3000 / portTICK_PERIOD_MS); // Reduced from 5 seconds to 3 seconds
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
// Reduced from 5 seconds to 3 seconds
|
||||
} else {
|
||||
// Faster scanning when no tag or idle state
|
||||
vTaskDelay(150 / portTICK_PERIOD_MS); // Faster scan interval
|
||||
vTaskDelay(pdMS_TO_TICKS(150));
|
||||
// Faster scan interval
|
||||
}
|
||||
|
||||
// aktualisieren der Website wenn sich der Status ändert
|
||||
@@ -2042,11 +2027,11 @@ void scanRfidTask(void * parameter) {
|
||||
if (nfcWriteInProgress) {
|
||||
// During write: Just pause scanning, don't disable NFC interface
|
||||
// Serial.println("NFC Scanning paused during write operation");
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS); // Shorter delay during write
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Shorter delay during write
|
||||
} else {
|
||||
// Full suspension requested
|
||||
Serial.println("NFC Reading disabled");
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
yield();
|
||||
@@ -2061,8 +2046,8 @@ void startNfc() {
|
||||
unsigned long versiondata = nfc.getFirmwareVersion(); // Lese Versionsnummer der Firmware aus
|
||||
if (! versiondata) { // Wenn keine Antwort kommt
|
||||
Serial.println("Kann kein RFID Board finden !"); // Sende Text "Kann kein..." an seriellen Monitor
|
||||
oledShowMessage("No RFID Board found");
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
oledDisplayText("No RFID Board found");
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
}
|
||||
else {
|
||||
Serial.print("Chip PN5 gefunden"); Serial.println((versiondata >> 24) & 0xFF, HEX); // Sende Text und Versionsinfos an seriellen
|
||||
|
||||
+8
-9
@@ -6,8 +6,7 @@
|
||||
|
||||
|
||||
// Globale Variablen für Config Backups hinzufügen
|
||||
String bambuCredentialsBackup;
|
||||
String spoolmanUrlBackup;
|
||||
String filamanConfigBackup;
|
||||
|
||||
// Globale Variable für den Update-Typ
|
||||
static int currentUpdateCommand = 0;
|
||||
@@ -56,7 +55,7 @@ void restoreJsonConfigs() {
|
||||
|
||||
void espRestart() {
|
||||
yield();
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
|
||||
ESP.restart();
|
||||
}
|
||||
@@ -137,9 +136,9 @@ void handleUpdate(AsyncWebServer &server) {
|
||||
if (isSpiffsUpdate) {
|
||||
// Backup vor dem Update
|
||||
sendUpdateProgress(0, "backup", "Backing up configurations...");
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
backupJsonConfigs();
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
|
||||
const esp_partition_t *partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL);
|
||||
if (!partition || !Update.begin(partition->size, U_SPIFFS)) {
|
||||
@@ -147,14 +146,14 @@ void handleUpdate(AsyncWebServer &server) {
|
||||
return;
|
||||
}
|
||||
sendUpdateProgress(5, "starting", "Starting SPIFFS update...");
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
} else {
|
||||
if (!Update.begin(updateTotalSize)) {
|
||||
request->send(400, "application/json", "{\"success\":false,\"message\":\"Update initialization failed\"}");
|
||||
return;
|
||||
}
|
||||
sendUpdateProgress(0, "starting", "Starting firmware update...");
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +179,7 @@ void handleUpdate(AsyncWebServer &server) {
|
||||
if (currentProgress != lastProgress && (currentProgress % 10 == 0 || final)) {
|
||||
sendUpdateProgress(currentProgress, "uploading");
|
||||
oledShowProgressBar(currentProgress, 100, "Update", "Download");
|
||||
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(50));
|
||||
lastProgress = currentProgress;
|
||||
}
|
||||
}
|
||||
@@ -204,7 +203,7 @@ void handleUpdate(AsyncWebServer &server) {
|
||||
|
||||
// Erste 100% Nachricht
|
||||
ws.textAll("{\"type\":\"updateProgress\",\"progress\":100,\"status\":\"success\",\"message\":\"Update successful! Restarting device...\"}");
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
|
||||
AsyncWebServerResponse *response = request->beginResponse(200, "application/json",
|
||||
"{\"success\":true,\"message\":\"Update successful! Restarting device...\"}");
|
||||
|
||||
+2
-2
@@ -167,7 +167,7 @@ void scale_loop(void * parameter) {
|
||||
if (scaleTareRequest == true || (autoTare && scale_tare_counter >= 20))
|
||||
{
|
||||
Serial.println("Re-Tare scale");
|
||||
oledShowMessage("TARE Scale");
|
||||
oledDisplayText("TARE Scale");
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
scale.tare();
|
||||
resetWeightFilter(); // Reset filter after manual tare
|
||||
@@ -382,7 +382,7 @@ uint8_t calibrate_scale() {
|
||||
{
|
||||
Serial.println("HX711 not found.");
|
||||
|
||||
oledShowMessage("HX711 not found");
|
||||
oledDisplayText("HX711 not found");
|
||||
|
||||
for (uint16_t i = 0; i < 30000; i++) {
|
||||
yield();
|
||||
|
||||
+8
-18
@@ -171,12 +171,10 @@ void setupWebserver(AsyncWebServer &server) {
|
||||
|
||||
loadFilamanConfig();
|
||||
|
||||
// Route für about
|
||||
server.on("/about", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
AsyncWebServerResponse *response = request->beginResponse(LittleFS, "/index.html.gz", "text/html");
|
||||
response->addHeader("Content-Encoding", "gzip");
|
||||
response->addHeader("Cache-Control", CACHE_CONTROL);
|
||||
request->send(response);
|
||||
// Route für Start (Index)
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
String html = loadHtmlWithHeader("/index.html");
|
||||
request->send(200, "text/html", html);
|
||||
});
|
||||
|
||||
// Route für Waage
|
||||
@@ -186,17 +184,9 @@ void setupWebserver(AsyncWebServer &server) {
|
||||
request->send(200, "text/html", html);
|
||||
});
|
||||
|
||||
// Route für RFID
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
AsyncWebServerResponse *response = request->beginResponse(LittleFS, "/rfid.html.gz", "text/html");
|
||||
response->addHeader("Content-Encoding", "gzip");
|
||||
response->addHeader("Cache-Control", CACHE_CONTROL);
|
||||
request->send(response);
|
||||
});
|
||||
|
||||
// Route für Config & Registration
|
||||
server.on("/config", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
String html = loadHtmlWithHeader("/config.html");
|
||||
// Route für Setup & Registration
|
||||
server.on("/setup", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
String html = loadHtmlWithHeader("/setup.html");
|
||||
html.replace("{{filamanUrl}}", filamanUrl);
|
||||
html.replace("{{registered}}", filamanRegistered ? "Yes" : "No");
|
||||
request->send(200, "text/html", html);
|
||||
@@ -227,7 +217,7 @@ void setupWebserver(AsyncWebServer &server) {
|
||||
String payloadString;
|
||||
serializeJson(doc, payloadString);
|
||||
|
||||
bool isSpool = doc.containsKey("spool_id");
|
||||
bool isSpool = !doc["spool_id"].isNull();
|
||||
startWriteJsonToTag(isSpool, payloadString.c_str());
|
||||
|
||||
request->send(200, "application/json", "{\"status\": \"writing\"}");
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <Update.h>
|
||||
#include <AsyncTCP.h>
|
||||
#include "bambu.h"
|
||||
#include "nfc.h"
|
||||
#include "scale.h"
|
||||
#include "esp_task_wdt.h"
|
||||
|
||||
+6
-6
@@ -33,7 +33,7 @@ void startMDNS() {
|
||||
if (!MDNS.begin("filaman")) {
|
||||
Serial.println("Error setting up MDNS responder!");
|
||||
while(1) {
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
@@ -43,7 +43,7 @@ void startMDNS() {
|
||||
void configModeCallback (WiFiManager *myWiFiManager) {
|
||||
Serial.println("Entered config mode");
|
||||
oledShowTopRow();
|
||||
oledShowMessage("WiFi Config Mode");
|
||||
oledDisplayText("WiFi Config Mode");
|
||||
}
|
||||
|
||||
void initWiFi() {
|
||||
@@ -69,7 +69,7 @@ void initWiFi() {
|
||||
Serial.println("Failed to connect or hit timeout");
|
||||
// ESP.restart();
|
||||
oledShowTopRow();
|
||||
oledShowMessage("WiFi not connected Check Portal");
|
||||
oledDisplayText("WiFi not connected Check Portal");
|
||||
}
|
||||
else {
|
||||
wifiOn = true;
|
||||
@@ -92,15 +92,15 @@ void checkWiFiConnection() {
|
||||
Serial.println("WiFi connection lost. Reconnecting...");
|
||||
wifiOn = false;
|
||||
oledShowTopRow();
|
||||
oledShowMessage("WiFi reconnecting");
|
||||
oledDisplayText("WiFi reconnecting");
|
||||
WiFi.reconnect(); // Versuche, die Verbindung wiederherzustellen
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS); // Warte 5 Sekunden, bevor erneut geprüft wird
|
||||
vTaskDelay(pdMS_TO_TICKS(5000)); // Warte 5 Sekunden, bevor erneut geprüft wird
|
||||
if (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
Serial.println("Failed to reconnect. Restarting WiFi...");
|
||||
WiFi.disconnect();
|
||||
Serial.println("WiFi disconnected.");
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
wifiErrorCounter++;
|
||||
|
||||
//wifiSettings();
|
||||
|
||||
Reference in new issue
Block a user