Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89f176b188 | ||
|
|
b78f34c1d3 | ||
|
|
f9d8fc7a61 | ||
|
|
c77b9c8503 | ||
|
|
1096585b56 | ||
|
|
17ba353f17 | ||
|
|
01e36bd39e | ||
|
|
01b8ced7e9 | ||
|
|
5f9ad13ea9 | ||
|
|
29e8b09c5a | ||
|
|
2593d048c2 | ||
|
|
d916d06127 | ||
|
|
0a4b3f1e1b |
No files matched your search
@@ -6,6 +6,18 @@ on:
|
|||||||
GITEA_TOKEN:
|
GITEA_TOKEN:
|
||||||
description: 'Token für Gitea API-Zugriff'
|
description: 'Token für Gitea API-Zugriff'
|
||||||
required: true
|
required: true
|
||||||
|
FILAMAN_SSH_PRIVATE_KEY:
|
||||||
|
description: 'SSH Private Key für Deployment'
|
||||||
|
required: true
|
||||||
|
FILAMAN_SSH_HOST:
|
||||||
|
description: 'SSH Host für Deployment'
|
||||||
|
required: true
|
||||||
|
FILAMAN_SSH_USER:
|
||||||
|
description: 'SSH User für Deployment'
|
||||||
|
required: true
|
||||||
|
FILAMAN_SSH_FIRMWARE_PATH:
|
||||||
|
description: 'SSH Pfad für Firmware Upload'
|
||||||
|
required: true
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
version:
|
version:
|
||||||
@@ -212,3 +224,31 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
- name: SSH-Deploy Firmware
|
||||||
|
if: success()
|
||||||
|
env:
|
||||||
|
SSH_PRIVATE_KEY: ${{ secrets.FILAMAN_SSH_PRIVATE_KEY }}
|
||||||
|
SSH_HOST: ${{ secrets.FILAMAN_SSH_HOST }}
|
||||||
|
SSH_USER: ${{ secrets.FILAMAN_SSH_USER }}
|
||||||
|
SSH_PATH: ${{ secrets.FILAMAN_SSH_FIRMWARE_PATH }}
|
||||||
|
VERSION: ${{ steps.get_version.outputs.VERSION }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# SSH-Key einrichten
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
||||||
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
ssh-keyscan -H "$SSH_HOST" >> ~/.ssh/known_hosts 2>/dev/null
|
||||||
|
|
||||||
|
cd .pio/build/esp32dev
|
||||||
|
|
||||||
|
# Full-Binary per SCP hochladen
|
||||||
|
echo "📤 Upload filaman_full_${VERSION}.bin per SCP ..."
|
||||||
|
scp -o StrictHostKeyChecking=no "filaman_full_${VERSION}.bin" "${SSH_USER}@${SSH_HOST}:${SSH_PATH}/filaman_full.bin"
|
||||||
|
|
||||||
|
echo "✅ filaman_full.bin auf ${SSH_HOST}:${SSH_PATH}/ hochgeladen."
|
||||||
|
|
||||||
|
# Aufräumen
|
||||||
|
rm -f ~/.ssh/id_rsa
|
||||||
@@ -6,15 +6,6 @@ on:
|
|||||||
RELEASE_TOKEN:
|
RELEASE_TOKEN:
|
||||||
description: 'GitHub token for release creation'
|
description: 'GitHub token for release creation'
|
||||||
required: true
|
required: true
|
||||||
FTP_PASSWORD:
|
|
||||||
description: 'FTP Password'
|
|
||||||
required: false
|
|
||||||
FTP_USER:
|
|
||||||
description: 'FTP User'
|
|
||||||
required: false
|
|
||||||
FTP_HOST:
|
|
||||||
description: 'FTP Host'
|
|
||||||
required: false
|
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
@@ -160,29 +151,3 @@ jobs:
|
|||||||
echo "Error: No files found to upload"
|
echo "Error: No files found to upload"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Install lftp
|
|
||||||
run: sudo apt-get install -y lftp
|
|
||||||
|
|
||||||
- name: Upload Firmware via FTP
|
|
||||||
if: success()
|
|
||||||
env:
|
|
||||||
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
|
|
||||||
FTP_USER: ${{ secrets.FTP_USER }}
|
|
||||||
FTP_HOST: ${{ secrets.FTP_HOST }}
|
|
||||||
VERSION: ${{ steps.get_version.outputs.VERSION }}
|
|
||||||
run: |
|
|
||||||
cd .pio/build/esp32dev
|
|
||||||
if [ -n "$FTP_USER" ] && [ -n "$FTP_PASSWORD" ] && [ -n "$FTP_HOST" ]; then
|
|
||||||
echo "All FTP credentials are present, attempting upload..."
|
|
||||||
lftp -c "set ssl:verify-certificate no; \
|
|
||||||
set ftp:ssl-protect-data true; \
|
|
||||||
set ftp:ssl-force true; \
|
|
||||||
set ssl:check-hostname false; \
|
|
||||||
set ftp:ssl-auth TLS; \
|
|
||||||
open -u $FTP_USER,$FTP_PASSWORD $FTP_HOST; \
|
|
||||||
put -O / filaman_full_${VERSION}.bin -o filaman_full.bin"
|
|
||||||
else
|
|
||||||
echo "Error: Some FTP credentials are missing"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
@@ -32,13 +32,14 @@ jobs:
|
|||||||
uses: ./.github/workflows/github-release.yml
|
uses: ./.github/workflows/github-release.yml
|
||||||
secrets:
|
secrets:
|
||||||
RELEASE_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
RELEASE_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
|
|
||||||
FTP_USER: ${{ secrets.FTP_USER }}
|
|
||||||
FTP_HOST: ${{ secrets.FTP_HOST }}
|
|
||||||
|
|
||||||
gitea-release:
|
gitea-release:
|
||||||
needs: detect-provider
|
needs: detect-provider
|
||||||
if: needs.detect-provider.outputs.provider == 'gitea'
|
if: needs.detect-provider.outputs.provider == 'gitea'
|
||||||
uses: ./.github/workflows/gitea-release.yml
|
uses: ./.github/workflows/gitea-release.yml
|
||||||
secrets:
|
secrets:
|
||||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
FILAMAN_SSH_PRIVATE_KEY: ${{ secrets.FILAMAN_SSH_PRIVATE_KEY }}
|
||||||
|
FILAMAN_SSH_HOST: ${{ secrets.FILAMAN_SSH_HOST }}
|
||||||
|
FILAMAN_SSH_USER: ${{ secrets.FILAMAN_SSH_USER }}
|
||||||
|
FILAMAN_SSH_FIRMWARE_PATH: ${{ secrets.FILAMAN_SSH_FIRMWARE_PATH }}
|
||||||
+1
-2
@@ -27,8 +27,7 @@ test/README
|
|||||||
# important
|
# important
|
||||||
html/bambu_credentials.json
|
html/bambu_credentials.json
|
||||||
html/spoolman_url.json
|
html/spoolman_url.json
|
||||||
_local/*
|
|
||||||
website/*
|
website/*
|
||||||
release.sh
|
release.sh
|
||||||
wiki
|
wiki
|
||||||
_layout
|
_*
|
||||||
+33
-8
@@ -57,12 +57,12 @@ Geräte sollten regelmäßig einen Heartbeat senden, um ihren Status auf "Online
|
|||||||
- **Request Body:**
|
- **Request Body:**
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"spool_id": 123, // Optional: Interne ID der Spule
|
"tag_uuid": "sf:25:s5:...", // Optional: RFID Tag UID (bevorzugt)
|
||||||
"tag_uuid": "E280...", // Optional: RFID Tag UID
|
"spool_id": 123, // Optional: Interne ID der Spule (Fallback)
|
||||||
"measured_weight_g": 850.5 // Aktuelles Gesamtgewicht in Gramm
|
"measured_weight_g": 850.5 // Aktuelles Gesamtgewicht in Gramm
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
*Hinweis: Mindestens `spool_id` oder `tag_uuid` muss angegeben werden.*
|
*Hinweis: Mindestens `tag_uuid` oder `spool_id` muss angegeben werden. `tag_uuid` hat Vorrang vor `spool_id`.*
|
||||||
|
|
||||||
- **Response:**
|
- **Response:**
|
||||||
```json
|
```json
|
||||||
@@ -80,12 +80,14 @@ Verknüpft eine Spule mit einem Lagerort.
|
|||||||
- **Request Body:**
|
- **Request Body:**
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"spool_id": 123, // Optional: ID der Spule
|
"spool_tag_uuid": "sf:25:s5:...", // Optional: RFID UID der Spule (bevorzugt)
|
||||||
"spool_tag_uuid": "E280...", // Optional: RFID UID der Spule
|
"spool_id": 123, // Optional: ID der Spule (Fallback)
|
||||||
"location_id": 1, // Optional: ID des Ortes
|
"location_tag_uuid": "LOC-1" // Optional: RFID UID des Ortes (bevorzugt)
|
||||||
"location_tag_uuid": "LOC-1" // Optional: RFID UID des Ortes
|
"location_id": 1 // Optional: ID des Ortes (Fallback)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
*Hinweis: RFID UUIDs haben Vorrang vor IDs. Mindestens Spule und Standort müssen durch UUID oder ID identifiziert werden.*
|
||||||
|
|
||||||
- **Response:**
|
- **Response:**
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@@ -115,10 +117,33 @@ Das System sendet eine Anfrage an die IP des Geräts.
|
|||||||
- **Erwartete Response vom Gerät:**
|
- **Erwartete Response vom Gerät:**
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"tag_uuid": "E2801234..." // Die UID des beschriebenen Tags
|
"tag_uuid": "sf:25:s5:..." // Die UID des beschriebenen Tags
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### RFID Ergebnis zurückmelden
|
||||||
|
Das Device meldet das Ergebnis des Schreibvorgangs an das System zurück.
|
||||||
|
|
||||||
|
- **Endpunkt:** `POST /api/v1/devices/rfid-result`
|
||||||
|
- **Request Body:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"tag_uuid": "sf:25:s5:a1:00",
|
||||||
|
"spool_id": 123,
|
||||||
|
"remaining_weight_g": 850.5
|
||||||
|
}
|
||||||
|
```
|
||||||
|
*Hinweis: `remaining_weight_g` ist optional und wird beim erstmaligen Beschreiben einer neuen Spule benötigt.*
|
||||||
|
|
||||||
|
- **Felder:**
|
||||||
|
- `success` (boolean): War der Schreibvorgang erfolgreich?
|
||||||
|
- `tag_uuid` (string): Die UID des geschriebenen Tags
|
||||||
|
- `spool_id` (int, optional): DB-ID der Spule falls vorhanden
|
||||||
|
- `remaining_weight_g` (float, optional): Aktuelles Gewicht der Spule beim Schreibvorgang
|
||||||
|
|
||||||
|
- **Response:** `{"status": "ok", "message": "Processed successfully"}`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 6. Fehlercodes
|
## 6. Fehlercodes
|
||||||
|
|||||||
+2
-2
@@ -9,8 +9,8 @@
|
|||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[common]
|
[common]
|
||||||
version = "3.0.9"
|
version = "3.2.3"
|
||||||
to_old_version = "2.0.10"
|
to_old_version = "3.0.9"
|
||||||
|
|
||||||
##
|
##
|
||||||
[env:esp32dev]
|
[env:esp32dev]
|
||||||
|
|||||||
+27
-6
@@ -21,6 +21,7 @@ struct ApiRequest {
|
|||||||
float val;
|
float val;
|
||||||
bool bool1; // success
|
bool bool1; // success
|
||||||
String str3; // error message
|
String str3; // error message
|
||||||
|
float remainingWeight; // remaining weight from rfid-result
|
||||||
bool active = false;
|
bool active = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -92,19 +93,28 @@ bool sendHeartbeat() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool sendWeight(int spoolId, String tagUuid, float measuredWeight) {
|
bool sendWeight(int spoolId, String tagUuid, float measuredWeight) {
|
||||||
if (!checkFilamanRegistration() || WiFi.status() != WL_CONNECTED) return false;
|
Serial.printf("sendWeight: sending to API - spoolId=%d, tagUuid=%s, weight=%.1f\n", spoolId, tagUuid.c_str(), measuredWeight);
|
||||||
|
if (!checkFilamanRegistration() || WiFi.status() != WL_CONNECTED) {
|
||||||
|
Serial.println("ERROR: Not registered or WiFi not connected");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
http.setTimeout(3000);
|
http.setTimeout(3000);
|
||||||
http.begin(filamanUrl + "/api/v1/devices/scale/weight");
|
http.begin(filamanUrl + "/api/v1/devices/scale/weight");
|
||||||
http.addHeader("Content-Type", "application/json");
|
http.addHeader("Content-Type", "application/json");
|
||||||
http.addHeader("Authorization", "Device " + filamanToken);
|
http.addHeader("Authorization", "Device " + filamanToken);
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
|
// Only add spool_id if it's > 0 (for NTAG tags with spool ID)
|
||||||
|
// For Bambu tags (spoolId == 0), only send tag_uuid
|
||||||
if (spoolId > 0) doc["spool_id"] = spoolId;
|
if (spoolId > 0) doc["spool_id"] = spoolId;
|
||||||
|
// Always add tag_uuid if available (this is what we want for Bambu tags)
|
||||||
if (tagUuid.length() > 0) doc["tag_uuid"] = tagUuid;
|
if (tagUuid.length() > 0) doc["tag_uuid"] = tagUuid;
|
||||||
doc["measured_weight_g"] = measuredWeight;
|
doc["measured_weight_g"] = measuredWeight;
|
||||||
String payload;
|
String payload;
|
||||||
serializeJson(doc, payload);
|
serializeJson(doc, payload);
|
||||||
|
Serial.printf("API payload: %s\n", payload.c_str());
|
||||||
int httpCode = http.POST(payload);
|
int httpCode = http.POST(payload);
|
||||||
|
Serial.printf("API response code: %d\n", httpCode);
|
||||||
|
|
||||||
if (httpCode == 200) {
|
if (httpCode == 200) {
|
||||||
String response = http.getString();
|
String response = http.getString();
|
||||||
@@ -150,7 +160,7 @@ bool sendLocation(int spoolId, String spoolTagUuid, int locationId, String locat
|
|||||||
return (httpCode == 200);
|
return (httpCode == 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sendRfidResult(String tagUuid, int spoolId, int locationId, bool success, String errorMessage) {
|
bool sendRfidResult(String tagUuid, int spoolId, int locationId, bool success, String errorMessage, float remainingWeight) {
|
||||||
if (!checkFilamanRegistration() || WiFi.status() != WL_CONNECTED) return false;
|
if (!checkFilamanRegistration() || WiFi.status() != WL_CONNECTED) return false;
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
http.setTimeout(5000);
|
http.setTimeout(5000);
|
||||||
@@ -164,6 +174,7 @@ bool sendRfidResult(String tagUuid, int spoolId, int locationId, bool success, S
|
|||||||
if (spoolId > 0) doc["spool_id"] = spoolId;
|
if (spoolId > 0) doc["spool_id"] = spoolId;
|
||||||
if (locationId > 0) doc["location_id"] = locationId;
|
if (locationId > 0) doc["location_id"] = locationId;
|
||||||
if (errorMessage.length() > 0) doc["error_message"] = errorMessage;
|
if (errorMessage.length() > 0) doc["error_message"] = errorMessage;
|
||||||
|
if (remainingWeight > 0) doc["remaining_weight_g"] = remainingWeight;
|
||||||
|
|
||||||
String payload;
|
String payload;
|
||||||
serializeJson(doc, payload);
|
serializeJson(doc, payload);
|
||||||
@@ -195,12 +206,12 @@ void filamanApiTask(void* pvParameters) {
|
|||||||
case API_REQUEST_HEARTBEAT: sendHeartbeat(); break;
|
case API_REQUEST_HEARTBEAT: sendHeartbeat(); break;
|
||||||
case API_REQUEST_WEIGHT: sendWeight(req.id1, req.str1, req.val); break;
|
case API_REQUEST_WEIGHT: sendWeight(req.id1, req.str1, req.val); break;
|
||||||
case API_REQUEST_LOCATE: sendLocation(req.id1, req.str1, req.id2, req.str2); break;
|
case API_REQUEST_LOCATE: sendLocation(req.id1, req.str1, req.id2, req.str2); break;
|
||||||
case API_REQUEST_RFID_RESULT: sendRfidResult(req.str1, req.id1, req.id2, req.bool1, req.str3); break;
|
case API_REQUEST_RFID_RESULT: sendRfidResult(req.str1, req.id1, req.id2, req.bool1, req.str3, req.remainingWeight); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
filamanApiState = API_IDLE;
|
filamanApiState = API_IDLE;
|
||||||
}
|
}
|
||||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,7 +238,15 @@ void sendHeartbeatAsync() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sendWeightAsync(int spoolId, String tagUuid, float weight) {
|
void sendWeightAsync(int spoolId, String tagUuid, float weight) {
|
||||||
if (!checkFilamanRegistration()) return;
|
Serial.printf("sendWeightAsync: spoolId=%d, tagUuid=%s, weight=%.1f\n", spoolId, tagUuid.c_str(), weight);
|
||||||
|
if (!checkFilamanRegistration()) {
|
||||||
|
Serial.println("ERROR: Not registered with FilaMan, cannot send weight");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (weight <= 0) {
|
||||||
|
Serial.println("ERROR: Weight is 0 or negative, cannot send");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (xSemaphoreTake(queueMutex, pdMS_TO_TICKS(50)) == pdTRUE) {
|
if (xSemaphoreTake(queueMutex, pdMS_TO_TICKS(50)) == pdTRUE) {
|
||||||
for(int i=0; i<MAX_API_QUEUE; i++) if(!apiQueue[i].active) {
|
for(int i=0; i<MAX_API_QUEUE; i++) if(!apiQueue[i].active) {
|
||||||
apiQueue[i].type = API_REQUEST_WEIGHT;
|
apiQueue[i].type = API_REQUEST_WEIGHT;
|
||||||
@@ -237,6 +256,7 @@ void sendWeightAsync(int spoolId, String tagUuid, float weight) {
|
|||||||
apiQueue[i].str2 = "";
|
apiQueue[i].str2 = "";
|
||||||
apiQueue[i].val = weight;
|
apiQueue[i].val = weight;
|
||||||
apiQueue[i].active = true;
|
apiQueue[i].active = true;
|
||||||
|
Serial.printf("Weight queued for API (slot %d)\n", i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
xSemaphoreGive(queueMutex);
|
xSemaphoreGive(queueMutex);
|
||||||
@@ -260,7 +280,7 @@ void sendLocationAsync(int spoolId, String spoolTagUuid, int locationId, String
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendRfidResultAsync(String tagUuid, int spoolId, int locationId, bool success, String errorMessage) {
|
void sendRfidResultAsync(String tagUuid, int spoolId, int locationId, bool success, String errorMessage, float remainingWeight) {
|
||||||
if (!checkFilamanRegistration()) return;
|
if (!checkFilamanRegistration()) return;
|
||||||
if (xSemaphoreTake(queueMutex, pdMS_TO_TICKS(50)) == pdTRUE) {
|
if (xSemaphoreTake(queueMutex, pdMS_TO_TICKS(50)) == pdTRUE) {
|
||||||
for(int i=0; i<MAX_API_QUEUE; i++) if(!apiQueue[i].active) {
|
for(int i=0; i<MAX_API_QUEUE; i++) if(!apiQueue[i].active) {
|
||||||
@@ -270,6 +290,7 @@ void sendRfidResultAsync(String tagUuid, int spoolId, int locationId, bool succe
|
|||||||
apiQueue[i].id2 = locationId;
|
apiQueue[i].id2 = locationId;
|
||||||
apiQueue[i].bool1 = success;
|
apiQueue[i].bool1 = success;
|
||||||
apiQueue[i].str3 = errorMessage;
|
apiQueue[i].str3 = errorMessage;
|
||||||
|
apiQueue[i].remainingWeight = remainingWeight;
|
||||||
apiQueue[i].active = true;
|
apiQueue[i].active = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ bool registerDevice(const String& deviceCode);
|
|||||||
void sendHeartbeatAsync();
|
void sendHeartbeatAsync();
|
||||||
void sendWeightAsync(int spoolId, String tagUuid, float weight);
|
void sendWeightAsync(int spoolId, String tagUuid, float weight);
|
||||||
void sendLocationAsync(int spoolId, String spoolTagUuid, int locationId, String locationTagUuid);
|
void sendLocationAsync(int spoolId, String spoolTagUuid, int locationId, String locationTagUuid);
|
||||||
void sendRfidResultAsync(String tagUuid, int spoolId, int locationId, bool success, String errorMessage);
|
void sendRfidResultAsync(String tagUuid, int spoolId, int locationId, bool success, String errorMessage, float remainingWeight = 0);
|
||||||
|
|
||||||
// Internal blocking functions (used by async task)
|
// Internal blocking functions (used by async task)
|
||||||
bool sendHeartbeat();
|
bool sendHeartbeat();
|
||||||
bool sendWeight(int spoolId, String tagUuid, float weight);
|
bool sendWeight(int spoolId, String tagUuid, float weight);
|
||||||
bool sendLocation(int spoolId, String spoolTagUuid, int locationId, String locationTagUuid);
|
bool sendLocation(int spoolId, String spoolTagUuid, int locationId, String locationTagUuid);
|
||||||
bool sendRfidResult(String tagUuid, int spoolId, int locationId, bool success, String errorMessage);
|
bool sendRfidResult(String tagUuid, int spoolId, int locationId, bool success, String errorMessage, float remainingWeight = 0);
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
void saveFilamanConfig();
|
void saveFilamanConfig();
|
||||||
|
|||||||
+46
-17
@@ -100,24 +100,42 @@ const unsigned long debounceDelay = 500; // 500 ms debounce delay
|
|||||||
|
|
||||||
unsigned long lastConnErrorShowTime = 0;
|
unsigned long lastConnErrorShowTime = 0;
|
||||||
const unsigned long connErrorShowInterval = 10000; // Show connection error every 10 seconds if exists
|
const unsigned long connErrorShowInterval = 10000; // Show connection error every 10 seconds if exists
|
||||||
|
bool showingConnError = false;
|
||||||
|
unsigned long connErrorStartTime = 0;
|
||||||
|
const unsigned long connErrorDisplayDuration = 3000;
|
||||||
|
|
||||||
// ##### PROGRAM START #####
|
// ##### PROGRAM START #####
|
||||||
void loop() {
|
void loop() {
|
||||||
unsigned long currentMillis = millis();
|
unsigned long currentMillis = millis();
|
||||||
|
|
||||||
// Handle connection errors (not registered or not connected)
|
// Handle connection errors (not registered or not connected)
|
||||||
if (intervalElapsed(currentMillis, lastConnErrorShowTime, connErrorShowInterval)) {
|
if (!showingConnError && intervalElapsed(currentMillis, lastConnErrorShowTime, connErrorShowInterval)) {
|
||||||
if (!filamanRegistered) {
|
if (!filamanRegistered) {
|
||||||
oledShowConnectionError("Not Registered", WiFi.localIP().toString());
|
oledShowConnectionError("Not Registered", WiFi.localIP().toString());
|
||||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
showingConnError = true;
|
||||||
|
connErrorStartTime = currentMillis;
|
||||||
mainTaskWasPaused = true;
|
mainTaskWasPaused = true;
|
||||||
} else if (!filamanConnected) {
|
} else if (!filamanConnected) {
|
||||||
oledShowConnectionError("API Connection Lost", WiFi.localIP().toString());
|
oledShowConnectionError("API Connection Lost", WiFi.localIP().toString());
|
||||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
showingConnError = true;
|
||||||
|
connErrorStartTime = currentMillis;
|
||||||
mainTaskWasPaused = true;
|
mainTaskWasPaused = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear connection error after duration
|
||||||
|
if (showingConnError && currentMillis - connErrorStartTime >= connErrorDisplayDuration) {
|
||||||
|
showingConnError = false;
|
||||||
|
// Force UI refresh next cycle
|
||||||
|
lastTopRowUpdateTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip the rest of the loop while showing error to avoid UI overwriting
|
||||||
|
if (showingConnError) {
|
||||||
|
esp_task_wdt_reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Überprüfe den Status des Touch Sensors
|
// Überprüfe den Status des Touch Sensors
|
||||||
if (touchSensorConnected && digitalRead(TTP223_PIN) == HIGH && currentMillis - lastButtonPress > debounceDelay)
|
if (touchSensorConnected && digitalRead(TTP223_PIN) == HIGH && currentMillis - lastButtonPress > debounceDelay)
|
||||||
{
|
{
|
||||||
@@ -194,17 +212,21 @@ void loop() {
|
|||||||
lastWeight = weight;
|
lastWeight = weight;
|
||||||
|
|
||||||
// Wenn ein Tag erkannt wurde und das Gewicht stabil ist, an FilaMan senden
|
// Wenn ein Tag erkannt wurde und das Gewicht stabil ist, an FilaMan senden
|
||||||
if (weightCounterToApi > 3 && weightSend == 0 && nfcReaderState == NFC_READ_SUCCESS && tagProcessed == false)
|
if (weightCounterToApi > 1 && weightSend == 0 && nfcReaderState == NFC_READ_SUCCESS && tagProcessed == false)
|
||||||
{
|
{
|
||||||
// set the current tag as processed to prevent it beeing processed again
|
|
||||||
tagProcessed = true;
|
tagProcessed = true;
|
||||||
|
|
||||||
// Get UID from nfcJsonData or similar (nfc.cpp should set it)
|
// Check if it's a Bambu tag - if so, send only UUID without spoolId
|
||||||
// For now, use activeSpoolId if available
|
if (isBambuTag) {
|
||||||
int sId = activeSpoolId.toInt();
|
sendWeightAsync(0, activeTagUuid, weight);
|
||||||
sendWeightAsync(sId, activeTagUuid, weight);
|
Serial.println("Bambu weight queued for FilaMan (UUID only)");
|
||||||
|
} else {
|
||||||
|
// Normal NTAG: send spoolId + UUID
|
||||||
|
int sId = activeSpoolId.toInt();
|
||||||
|
sendWeightAsync(sId, activeTagUuid, weight);
|
||||||
|
Serial.println("Weight queued for FilaMan");
|
||||||
|
}
|
||||||
weightSend = 1;
|
weightSend = 1;
|
||||||
Serial.println("Weight queued for FilaMan");
|
|
||||||
|
|
||||||
// Feedback to user
|
// Feedback to user
|
||||||
pauseMainTask = 1;
|
pauseMainTask = 1;
|
||||||
@@ -215,14 +237,21 @@ void loop() {
|
|||||||
if (nfcReaderState == NFC_WRITE_SUCCESS && tagProcessed == false)
|
if (nfcReaderState == NFC_WRITE_SUCCESS && tagProcessed == false)
|
||||||
{
|
{
|
||||||
tagProcessed = true;
|
tagProcessed = true;
|
||||||
int sId = activeSpoolId.toInt();
|
|
||||||
sendWeightAsync(sId, activeTagUuid, weight);
|
|
||||||
weightSend = 1;
|
|
||||||
Serial.println("Weight queued for FilaMan after tag write");
|
|
||||||
|
|
||||||
// Feedback to user
|
// Only send weight if a valid spoolId exists (spool tag, not location tag)
|
||||||
pauseMainTask = 1;
|
if (activeSpoolId.length() > 0 && activeSpoolId != "0") {
|
||||||
oledShowProgressBar(3, 4, "Tag written", "Sending...");
|
int sId = activeSpoolId.toInt();
|
||||||
|
sendWeightAsync(sId, activeTagUuid, weight);
|
||||||
|
weightSend = 1;
|
||||||
|
Serial.println("Weight queued for FilaMan after spool tag write");
|
||||||
|
|
||||||
|
// Feedback to user
|
||||||
|
pauseMainTask = 1;
|
||||||
|
oledShowProgressBar(3, 4, "Tag written", "Sending...");
|
||||||
|
} else {
|
||||||
|
// Location tag written - no weight to send
|
||||||
|
Serial.println("Location tag written successfully - no weight send needed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+85
-23
@@ -22,6 +22,7 @@ String activeTagUuid = "";
|
|||||||
String lastSpoolId = "";
|
String lastSpoolId = "";
|
||||||
String nfcJsonData = "";
|
String nfcJsonData = "";
|
||||||
bool tagProcessed = false;
|
bool tagProcessed = false;
|
||||||
|
bool isBambuTag = false;
|
||||||
volatile bool nfcReadingTaskSuspendRequest = false;
|
volatile bool nfcReadingTaskSuspendRequest = false;
|
||||||
volatile bool nfcReadingTaskSuspendState = false;
|
volatile bool nfcReadingTaskSuspendState = false;
|
||||||
volatile bool nfcWriteInProgress = false; // Prevent any tag operations during write
|
volatile bool nfcWriteInProgress = false; // Prevent any tag operations during write
|
||||||
@@ -36,6 +37,42 @@ volatile nfcReaderStateType nfcReaderState = NFC_IDLE;
|
|||||||
// 6 = reading
|
// 6 = reading
|
||||||
// ***** PN532
|
// ***** PN532
|
||||||
|
|
||||||
|
// ##### Bambu Tag Helper Functions #####
|
||||||
|
// Simplified: only read UID, no decryption needed (UID is always visible)
|
||||||
|
bool detectBambuTag(const uint8_t* uid, uint8_t uidLength) {
|
||||||
|
Serial.println("Detected Bambu Lab tag (Mifare Classic) - reading UID only");
|
||||||
|
|
||||||
|
// Create UID string with separators (same format as NTAG)
|
||||||
|
String uidString = "";
|
||||||
|
for (uint8_t i = 0; i < uidLength; i++) {
|
||||||
|
if (uid[i] < 0x10) uidString += "0";
|
||||||
|
uidString += String(uid[i], HEX);
|
||||||
|
if (i < uidLength - 1) {
|
||||||
|
uidString += ":";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uidString.toUpperCase();
|
||||||
|
|
||||||
|
Serial.print(" UID: ");
|
||||||
|
Serial.println(uidString);
|
||||||
|
|
||||||
|
isBambuTag = true;
|
||||||
|
activeTagUuid = uidString;
|
||||||
|
activeSpoolId = ""; // Will be resolved by FilaMan API based on tag UID
|
||||||
|
|
||||||
|
// Create minimal JSON for compatibility
|
||||||
|
JsonDocument doc;
|
||||||
|
doc["vendor"] = "Bambu Lab";
|
||||||
|
doc["type"] = "Bambu";
|
||||||
|
nfcJsonData = "";
|
||||||
|
serializeJson(doc, nfcJsonData);
|
||||||
|
|
||||||
|
// Set normal read success state - isBambuTag flag is set for later use
|
||||||
|
nfcReaderState = NFC_READ_SUCCESS;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// ##### Funktionen für RFID #####
|
// ##### Funktionen für RFID #####
|
||||||
void payloadToJson(uint8_t *data) {
|
void payloadToJson(uint8_t *data) {
|
||||||
const char* startJson = strchr((char*)data, '{');
|
const char* startJson = strchr((char*)data, '{');
|
||||||
@@ -1590,11 +1627,11 @@ void writeJsonToTag(void *parameter) {
|
|||||||
// Wait up to 30 seconds for tag
|
// Wait up to 30 seconds for tag
|
||||||
uint8_t success = 0;
|
uint8_t success = 0;
|
||||||
String uidString = "";
|
String uidString = "";
|
||||||
|
uint8_t uidLength = 0;
|
||||||
unsigned long startTime = millis();
|
unsigned long startTime = millis();
|
||||||
|
|
||||||
while (millis() - startTime < 30000) {
|
while (millis() - startTime < 30000) {
|
||||||
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;
|
|
||||||
// yield before potentially waiting for 400ms
|
// yield before potentially waiting for 400ms
|
||||||
yield();
|
yield();
|
||||||
esp_task_wdt_reset();
|
esp_task_wdt_reset();
|
||||||
@@ -1603,12 +1640,13 @@ void writeJsonToTag(void *parameter) {
|
|||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
for (uint8_t i = 0; i < uidLength; i++) {
|
for (uint8_t i = 0; i < uidLength; i++) {
|
||||||
|
if (uid[i] < 0x10) uidString += "0";
|
||||||
uidString += String(uid[i], HEX);
|
uidString += String(uid[i], HEX);
|
||||||
if (i < uidLength - 1) {
|
if (i < uidLength - 1) {
|
||||||
uidString += ":"; // Trennzeichen hinzufügen
|
uidString += ":"; // Trennzeichen hinzufügen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foundNfcTag(nullptr, success);
|
uidString.toUpperCase();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1619,6 +1657,25 @@ void writeJsonToTag(void *parameter) {
|
|||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
|
// Check if this is a Bambu tag (Mifare Classic has 4 byte UID, NTAG has 7 byte)
|
||||||
|
// If so, skip writing and just send success with weight to API
|
||||||
|
if (uidLength != 7) {
|
||||||
|
Serial.println("Bambu Lab tag detected during write - skipping write, sending result with weight");
|
||||||
|
oledShowProgressBar(1, 1, "Write Tag", "Done!");
|
||||||
|
|
||||||
|
// Send success to API with tag_uuid and current weight
|
||||||
|
sendRfidResultAsync(uidString, params->spoolId, params->locationId, true, "", weight);
|
||||||
|
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(500));
|
||||||
|
|
||||||
|
// Clean up and exit
|
||||||
|
nfcWriteInProgress = false;
|
||||||
|
nfcReaderState = NFC_IDLE;
|
||||||
|
free(params->payload);
|
||||||
|
delete params;
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
oledShowProgressBar(1, 3, "Write Tag", "Writing");
|
oledShowProgressBar(1, 3, "Write Tag", "Writing");
|
||||||
|
|
||||||
// Schreibe die NDEF-Message auf den Tag
|
// Schreibe die NDEF-Message auf den Tag
|
||||||
@@ -1710,9 +1767,9 @@ void writeJsonToTag(void *parameter) {
|
|||||||
|
|
||||||
Serial.println("=========================================");
|
Serial.println("=========================================");
|
||||||
|
|
||||||
// Send success response to API with tag_uuid (with separators)
|
// Send success response to API with tag_uuid and current weight
|
||||||
Serial.println("Sending result to API via fire-and-forget...");
|
Serial.println("Sending result to API via fire-and-forget...");
|
||||||
sendRfidResultAsync(uidString, params->spoolId, params->locationId, true, "");
|
sendRfidResultAsync(uidString, params->spoolId, params->locationId, true, "", weight);
|
||||||
|
|
||||||
// vTaskResume(RfidReaderTask); // Don't resume as it was not suspended
|
// vTaskResume(RfidReaderTask); // Don't resume as it was not suspended
|
||||||
vTaskDelay(pdMS_TO_TICKS(500));
|
vTaskDelay(pdMS_TO_TICKS(500));
|
||||||
@@ -1740,9 +1797,6 @@ void writeJsonToTag(void *parameter) {
|
|||||||
Serial.println("Sending timeout result to API via fire-and-forget...");
|
Serial.println("Sending timeout result to API via fire-and-forget...");
|
||||||
sendRfidResultAsync("", params->spoolId, params->locationId, false, "Timeout - no tag found");
|
sendRfidResultAsync("", params->spoolId, params->locationId, false, "Timeout - no tag found");
|
||||||
}
|
}
|
||||||
|
|
||||||
sendWriteResult(nullptr, success);
|
|
||||||
sendNfcData();
|
|
||||||
|
|
||||||
// Reset write protection and cleanup
|
// Reset write protection and cleanup
|
||||||
nfcWriteInProgress = false; // Re-enable high-level tag operations
|
nfcWriteInProgress = false; // Re-enable high-level tag operations
|
||||||
@@ -1928,6 +1982,7 @@ void scanRfidTask(void * parameter) {
|
|||||||
String uidString = "";
|
String uidString = "";
|
||||||
for (uint8_t i = 0; i < uidLength; i++) {
|
for (uint8_t i = 0; i < uidLength; i++) {
|
||||||
//TBD: Rework to remove all the string operations
|
//TBD: Rework to remove all the string operations
|
||||||
|
if (uid[i] < 0x10) uidString += "0";
|
||||||
uidString += String(uid[i], HEX);
|
uidString += String(uid[i], HEX);
|
||||||
if (i < uidLength - 1) {
|
if (i < uidLength - 1) {
|
||||||
uidString += ":"; // Optional: Trennzeichen hinzufügen
|
uidString += ":"; // Optional: Trennzeichen hinzufügen
|
||||||
@@ -2000,21 +2055,28 @@ void scanRfidTask(void * parameter) {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
oledShowProgressBar(1, 1, "Failure", "Tag read error");
|
// NTAG reading failed, try reading as Bambu Lab tag
|
||||||
nfcReaderState = NFC_READ_ERROR;
|
Serial.println("NTAG read failed, trying Bambu Lab tag...");
|
||||||
// Reset activeSpoolId when tag reading fails to prevent autoSet
|
if (!detectBambuTag(uid, uidLength)) {
|
||||||
activeSpoolId = "";
|
oledShowProgressBar(1, 1, "Failure", "Tag read error");
|
||||||
Serial.println("Tag read failed - activeSpoolId reset to prevent autoSet");
|
nfcReaderState = NFC_READ_ERROR;
|
||||||
|
activeSpoolId = "";
|
||||||
|
Serial.println("Tag read failed - activeSpoolId reset to prevent autoSet");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//TBD: Show error here?!
|
// UID length != 7, might be a Mifare Classic (Bambu tags)
|
||||||
oledShowProgressBar(1, 1, "Failure", "Unkown tag type");
|
Serial.println("Not a standard NTAG (UID length != 7), trying Bambu Lab tag...");
|
||||||
Serial.println("This doesn't seem to be an NTAG2xx tag (UUID length != 7 bytes)!");
|
if (!detectBambuTag(uid, uidLength)) {
|
||||||
// Reset activeSpoolId when tag type is unknown to prevent autoSet
|
//TBD: Show error here?!
|
||||||
activeSpoolId = "";
|
oledShowProgressBar(1, 1, "Failure", "Unkown tag type");
|
||||||
Serial.println("Unknown tag type - activeSpoolId reset to prevent autoSet");
|
Serial.println("This doesn't seem to be an NTAG2xx tag (UUID length != 7 bytes)!");
|
||||||
|
// Reset activeSpoolId when tag type is unknown to prevent autoSet
|
||||||
|
activeSpoolId = "";
|
||||||
|
Serial.println("Unknown tag type - activeSpoolId reset to prevent autoSet");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2034,18 +2096,18 @@ void scanRfidTask(void * parameter) {
|
|||||||
{
|
{
|
||||||
nfcReaderState = NFC_IDLE;
|
nfcReaderState = NFC_IDLE;
|
||||||
tagProcessed = false;
|
tagProcessed = false;
|
||||||
|
isBambuTag = false;
|
||||||
Serial.println("Tag nach erfolgreichem Lesen entfernt - bereit für nächsten Tag");
|
Serial.println("Tag nach erfolgreichem Lesen entfernt - bereit für nächsten Tag");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a pause after successful reading to prevent immediate re-reading
|
// Add a pause after successful reading to prevent immediate re-reading
|
||||||
if (nfcReaderState == NFC_READ_SUCCESS) {
|
if (nfcReaderState == NFC_READ_SUCCESS) {
|
||||||
Serial.println("Tag erfolgreich gelesen - warte 3 Sekunden vor nächstem Scan");
|
// After tag is processed, slow down scanning to give API time
|
||||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
Serial.println("Tag processed - slowing scan to 2 seconds");
|
||||||
// Reduced from 5 seconds to 3 seconds
|
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||||
} else {
|
} else {
|
||||||
// Faster scanning when no tag or idle state
|
// Faster scanning when no tag or idle state
|
||||||
vTaskDelay(pdMS_TO_TICKS(250));
|
vTaskDelay(pdMS_TO_TICKS(500));
|
||||||
// Faster scan interval
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// aktualisieren der Website wenn sich der Status ändert
|
// aktualisieren der Website wenn sich der Status ändert
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ typedef enum{
|
|||||||
NFC_READ_ERROR,
|
NFC_READ_ERROR,
|
||||||
NFC_WRITING,
|
NFC_WRITING,
|
||||||
NFC_WRITE_SUCCESS,
|
NFC_WRITE_SUCCESS,
|
||||||
NFC_WRITE_ERROR
|
NFC_WRITE_ERROR,
|
||||||
|
NFC_BAMBU_DETECTED,
|
||||||
|
NFC_BAMBU_ERROR
|
||||||
} nfcReaderStateType;
|
} nfcReaderStateType;
|
||||||
|
|
||||||
struct NfcWriteParameterType {
|
struct NfcWriteParameterType {
|
||||||
@@ -35,7 +37,6 @@ extern String lastSpoolId;
|
|||||||
extern volatile nfcReaderStateType nfcReaderState;
|
extern volatile nfcReaderStateType nfcReaderState;
|
||||||
extern volatile bool nfcWriteInProgress;
|
extern volatile bool nfcWriteInProgress;
|
||||||
extern bool tagProcessed;
|
extern bool tagProcessed;
|
||||||
|
extern bool isBambuTag;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
|
||||||
+31
-35
@@ -12,17 +12,17 @@ bool wm_nonblocking = false;
|
|||||||
uint8_t wifiErrorCounter = 0;
|
uint8_t wifiErrorCounter = 0;
|
||||||
|
|
||||||
void wifiSettings() {
|
void wifiSettings() {
|
||||||
// Optimierte WiFi-Einstellungen
|
// Standard WiFi-Einstellungen für höchste Stabilität mit ESPAsyncWebServer
|
||||||
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.setSleep(false); // disable sleep mode
|
|
||||||
WiFi.setHostname("FilaMan");
|
WiFi.setHostname("FilaMan");
|
||||||
esp_wifi_set_ps(WIFI_PS_NONE);
|
|
||||||
|
|
||||||
// Maximale Sendeleistung
|
// Wir lassen das Power Management (Sleep) auf dem ESP-Standard.
|
||||||
WiFi.setTxPower(WIFI_POWER_19_5dBm); // Set maximum transmit power
|
// Ein erzwungenes Ausschalten führt zu RF-Abstürzen bei vielen asynchronen HTTP-Requests.
|
||||||
|
|
||||||
|
// Angemessene Sendeleistung (reduziert Hitzeprobleme)
|
||||||
|
WiFi.setTxPower(WIFI_POWER_17dBm); // Set stable transmit power (default is 19.5 which gets hot)
|
||||||
|
|
||||||
// Optimiere TCP/IP Stack
|
// Wir überlassen die Protokoll-Aushandlung (b/g/n) dem Treiber. Harte Vorgaben crashen unter Last.
|
||||||
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N);
|
|
||||||
|
|
||||||
// Aktiviere WiFi-Roaming für bessere Stabilität
|
// Aktiviere WiFi-Roaming für bessere Stabilität
|
||||||
esp_wifi_set_rssi_threshold(-80);
|
esp_wifi_set_rssi_threshold(-80);
|
||||||
@@ -74,37 +74,33 @@ void initWiFi() {
|
|||||||
void checkWiFiConnection() {
|
void checkWiFiConnection() {
|
||||||
if (WiFi.status() != WL_CONNECTED)
|
if (WiFi.status() != WL_CONNECTED)
|
||||||
{
|
{
|
||||||
Serial.println("WiFi connection lost. Reconnecting...");
|
if (wifiOn) {
|
||||||
wifiOn = false;
|
Serial.println("WiFi connection lost. LwIP is auto-reconnecting...");
|
||||||
oledShowTopRow();
|
wifiOn = false;
|
||||||
oledDisplayText("WiFi reconnecting");
|
oledShowTopRow();
|
||||||
WiFi.reconnect(); // Versuche, die Verbindung wiederherzustellen
|
oledDisplayText("WiFi reconnecting");
|
||||||
vTaskDelay(pdMS_TO_TICKS(5000)); // Warte 5 Sekunden, bevor erneut geprüft wird
|
}
|
||||||
if (WiFi.status() != WL_CONNECTED)
|
|
||||||
{
|
wifiErrorCounter++;
|
||||||
Serial.println("Failed to reconnect. Restarting WiFi...");
|
|
||||||
WiFi.disconnect();
|
|
||||||
Serial.println("WiFi disconnected.");
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
|
||||||
wifiErrorCounter++;
|
|
||||||
|
|
||||||
//wifiSettings();
|
// Only restart after a significant time of no connection (e.g. 5 minutes)
|
||||||
WiFi.reconnect();
|
// Assuming WIFI_CHECK_INTERVAL is 60000ms (1 minute), 5 errors = 5 minutes
|
||||||
Serial.println("WiFi reconnecting...");
|
if (wifiErrorCounter >= 5)
|
||||||
WiFi.waitForConnectResult();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
Serial.println("WiFi reconnected.");
|
Serial.println("WiFi unable to reconnect for 5 minutes. Restarting...");
|
||||||
wifiErrorCounter = 0;
|
ESP.restart();
|
||||||
wifiOn = true;
|
|
||||||
oledShowTopRow();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (wifiErrorCounter >= 5)
|
|
||||||
{
|
{
|
||||||
Serial.println("Too many WiFi errors. Restarting...");
|
if (!wifiOn) {
|
||||||
ESP.restart();
|
Serial.println("WiFi reconnected.");
|
||||||
|
wifiErrorCounter = 0;
|
||||||
|
wifiOn = true;
|
||||||
|
oledShowTopRow();
|
||||||
|
} else {
|
||||||
|
// Reset error counter if we are connected (just to be safe)
|
||||||
|
wifiErrorCounter = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user