update navigation links, enhance NFC data display, and improve MQTT connection handling
This commit is contained in:
		@@ -20,7 +20,7 @@
 | 
				
			|||||||
            <a href="/">Start</a>
 | 
					            <a href="/">Start</a>
 | 
				
			||||||
            <a href="/waage">Scale</a>
 | 
					            <a href="/waage">Scale</a>
 | 
				
			||||||
            <a href="/spoolman">Spoolman/Bambu</a>
 | 
					            <a href="/spoolman">Spoolman/Bambu</a>
 | 
				
			||||||
            <a href="/rfid">RFID</a>
 | 
					            <a href="/">About</a>
 | 
				
			||||||
        </nav>
 | 
					        </nav>
 | 
				
			||||||
        <div class="status-container">
 | 
					        <div class="status-container">
 | 
				
			||||||
            <div class="status-item">
 | 
					            <div class="status-item">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -448,7 +448,7 @@ function updateNfcData(data) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // HTML für die Datenanzeige erstellen
 | 
					    // HTML für die Datenanzeige erstellen
 | 
				
			||||||
    let html = `
 | 
					    let html = `
 | 
				
			||||||
        <div style="margin-top: 10px;">
 | 
					        <div class="nfc-card-data" style="margin-top: 10px;">
 | 
				
			||||||
            <p><strong>Brand:</strong> ${data.brand || 'N/A'}</p>
 | 
					            <p><strong>Brand:</strong> ${data.brand || 'N/A'}</p>
 | 
				
			||||||
            <p><strong>Type:</strong> ${data.type || 'N/A'} ${data.color_hex ? `<span style="
 | 
					            <p><strong>Type:</strong> ${data.type || 'N/A'} ${data.color_hex ? `<span style="
 | 
				
			||||||
                background-color: #${data.color_hex}; 
 | 
					                background-color: #${data.color_hex}; 
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -255,7 +255,7 @@ button:hover {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
p {
 | 
					p {
 | 
				
			||||||
    font-size: 1rem;
 | 
					    font-size: 1rem;
 | 
				
			||||||
    color: #555;
 | 
					    color: #ffffff;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
a {
 | 
					a {
 | 
				
			||||||
@@ -325,6 +325,13 @@ a:hover {
 | 
				
			|||||||
    margin-top: 10px;
 | 
					    margin-top: 10px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.nfc-card-data {
 | 
				
			||||||
 | 
					    padding-left: 20px !important;
 | 
				
			||||||
 | 
					    color: white !important;
 | 
				
			||||||
 | 
					    font-weight: bold !important;
 | 
				
			||||||
 | 
					    margin: 0 auto !important;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.nfc-success {
 | 
					.nfc-success {
 | 
				
			||||||
    color: green;
 | 
					    color: green;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -422,9 +422,6 @@ void reconnect() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void mqtt_loop(void * parameter) {
 | 
					void mqtt_loop(void * parameter) {
 | 
				
			||||||
    oledShowMessage("Bambu Connected");
 | 
					 | 
				
			||||||
    bambu_connected = true;
 | 
					 | 
				
			||||||
    oledShowTopRow();
 | 
					 | 
				
			||||||
    for(;;) {
 | 
					    for(;;) {
 | 
				
			||||||
        if (pauseBambuMqttTask) {
 | 
					        if (pauseBambuMqttTask) {
 | 
				
			||||||
            vTaskDelay(10000);
 | 
					            vTaskDelay(10000);
 | 
				
			||||||
@@ -452,13 +449,16 @@ bool setupMqtt() {
 | 
				
			|||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (success && bambu_ip != "" && bambu_accesscode != "" && bambu_serialnr != "") {
 | 
					    if (success && bambu_ip != "" && bambu_accesscode != "" && bambu_serialnr != "") 
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        sslClient.setCACert(root_ca);
 | 
					        sslClient.setCACert(root_ca);
 | 
				
			||||||
        sslClient.setInsecure();
 | 
					        sslClient.setInsecure();
 | 
				
			||||||
        client.setServer(bambu_ip, 8883);
 | 
					        client.setServer(bambu_ip, 8883);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Verbinden mit dem MQTT-Server
 | 
					        // Verbinden mit dem MQTT-Server
 | 
				
			||||||
        if (client.connect(bambu_serialnr, bambu_username, bambu_accesscode)) {
 | 
					        bool connected = true;
 | 
				
			||||||
 | 
					        if (client.connect(bambu_serialnr, bambu_username, bambu_accesscode)) 
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
            client.setCallback(mqtt_callback);
 | 
					            client.setCallback(mqtt_callback);
 | 
				
			||||||
            client.setBufferSize(5120);
 | 
					            client.setBufferSize(5120);
 | 
				
			||||||
            // Optional: Topic abonnieren
 | 
					            // Optional: Topic abonnieren
 | 
				
			||||||
@@ -467,24 +467,31 @@ bool setupMqtt() {
 | 
				
			|||||||
            Serial.println("MQTT-Client initialisiert");
 | 
					            Serial.println("MQTT-Client initialisiert");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            oledShowTopRow();
 | 
					            oledShowTopRow();
 | 
				
			||||||
 | 
					            oledShowMessage("Bambu Connected");
 | 
				
			||||||
            xTaskCreatePinnedToCore(
 | 
					            bambu_connected = true;
 | 
				
			||||||
                mqtt_loop, /* Function to implement the task */
 | 
					        } 
 | 
				
			||||||
                "BambuMqtt", /* Name of the task */
 | 
					        else 
 | 
				
			||||||
                10000,  /* Stack size in words */
 | 
					        {
 | 
				
			||||||
                NULL,  /* Task input parameter */
 | 
					 | 
				
			||||||
                mqttTaskPrio,  /* Priority of the task */
 | 
					 | 
				
			||||||
                &BambuMqttTask,  /* Task handle. */
 | 
					 | 
				
			||||||
                mqttTaskCore); /* Core where the task should run */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            Serial.println("Fehler: Konnte sich nicht beim MQTT-Server anmelden");
 | 
					            Serial.println("Fehler: Konnte sich nicht beim MQTT-Server anmelden");
 | 
				
			||||||
            oledShowMessage("Bambu Connection Failed");
 | 
					            oledShowMessage("Bambu Connection Failed");
 | 
				
			||||||
            oledShowTopRow();
 | 
					            oledShowTopRow();
 | 
				
			||||||
            vTaskDelay(2000 / portTICK_PERIOD_MS);
 | 
					            vTaskDelay(2000 / portTICK_PERIOD_MS);
 | 
				
			||||||
            return false;
 | 
					            connected = false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    } else {
 | 
					
 | 
				
			||||||
 | 
					        xTaskCreatePinnedToCore(
 | 
				
			||||||
 | 
					            mqtt_loop, /* Function to implement the task */
 | 
				
			||||||
 | 
					            "BambuMqtt", /* Name of the task */
 | 
				
			||||||
 | 
					            10000,  /* Stack size in words */
 | 
				
			||||||
 | 
					            NULL,  /* Task input parameter */
 | 
				
			||||||
 | 
					            mqttTaskPrio,  /* Priority of the task */
 | 
				
			||||||
 | 
					            &BambuMqttTask,  /* Task handle. */
 | 
				
			||||||
 | 
					            mqttTaskCore); /* Core where the task should run */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!connected) return false;
 | 
				
			||||||
 | 
					    } 
 | 
				
			||||||
 | 
					    else 
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        Serial.println("Fehler: Keine MQTT-Daten vorhanden");
 | 
					        Serial.println("Fehler: Keine MQTT-Daten vorhanden");
 | 
				
			||||||
        oledShowMessage("Bambu Credentials Missing");
 | 
					        oledShowMessage("Bambu Credentials Missing");
 | 
				
			||||||
        oledShowTopRow();
 | 
					        oledShowTopRow();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -379,6 +379,8 @@ void scanRfidTask(void * parameter) {
 | 
				
			|||||||
    // Wenn geschrieben wird Schleife aussetzen
 | 
					    // Wenn geschrieben wird Schleife aussetzen
 | 
				
			||||||
    if (hasReadRfidTag != 3)
 | 
					    if (hasReadRfidTag != 3)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					      yield();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      uint8_t success;
 | 
					      uint8_t success;
 | 
				
			||||||
      uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
 | 
					      uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
 | 
				
			||||||
      uint8_t uidLength;
 | 
					      uint8_t uidLength;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,7 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
 | 
				
			|||||||
        sendAmsData(client);
 | 
					        sendAmsData(client);
 | 
				
			||||||
        sendNfcData(client);
 | 
					        sendNfcData(client);
 | 
				
			||||||
        foundNfcTag(client, hasReadRfidTag);
 | 
					        foundNfcTag(client, hasReadRfidTag);
 | 
				
			||||||
        sendWriteResult(client, 0);
 | 
					        sendWriteResult(client, 3);
 | 
				
			||||||
    } else if (type == WS_EVT_DISCONNECT) {
 | 
					    } else if (type == WS_EVT_DISCONNECT) {
 | 
				
			||||||
        Serial.println("Client getrennt.");
 | 
					        Serial.println("Client getrennt.");
 | 
				
			||||||
    } else if (type == WS_EVT_DATA) {
 | 
					    } else if (type == WS_EVT_DATA) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user