New Code for Arduino
This commit is contained in:
parent
f987ab6638
commit
365d4afdfa
@ -2,7 +2,6 @@
|
|||||||
// Erstellungsdatum: 22.01.2025
|
// Erstellungsdatum: 22.01.2025
|
||||||
// Hardware: Vision AI V2 Kit
|
// Hardware: Vision AI V2 Kit
|
||||||
|
|
||||||
|
|
||||||
#include <Seeed_Arduino_SSCMA.h>
|
#include <Seeed_Arduino_SSCMA.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
@ -14,7 +13,6 @@ const char* password = "DEIN_WIFI_PASSWORT";
|
|||||||
// MQTT-Broker-Zugangsdaten
|
// MQTT-Broker-Zugangsdaten
|
||||||
const char* mqtt_server = "DEINE_MQTT_BROKER_ADRESSE";
|
const char* mqtt_server = "DEINE_MQTT_BROKER_ADRESSE";
|
||||||
const char* mqtt_topic = "/vision_ai/data";
|
const char* mqtt_topic = "/vision_ai/data";
|
||||||
|
|
||||||
WiFiClient espClient;
|
WiFiClient espClient;
|
||||||
PubSubClient client(espClient);
|
PubSubClient client(espClient);
|
||||||
SSCMA AI;
|
SSCMA AI;
|
||||||
@ -77,7 +75,27 @@ void loop() {
|
|||||||
mqttMessage += ",\"postprocess\":" + String(AI.perf().postprocess) + "},";
|
mqttMessage += ",\"postprocess\":" + String(AI.perf().postprocess) + "},";
|
||||||
|
|
||||||
mqttMessage += "\"boxes\": [";
|
mqttMessage += "\"boxes\": [";
|
||||||
|
bool validBoxFound = false; // Prüfen, ob mindestens ein gültiger Box-Eintrag existiert
|
||||||
|
|
||||||
for (int i = 0; i < AI.boxes().size(); i++) {
|
for (int i = 0; i < AI.boxes().size(); i++) {
|
||||||
|
if (AI.boxes()[i].score > 50) { // Bedingung: Nur bei Score > 50 verarbeiten
|
||||||
|
validBoxFound = true;
|
||||||
|
Serial.print("Box[");
|
||||||
|
Serial.print(i);
|
||||||
|
Serial.print("] target=");
|
||||||
|
Serial.print(AI.boxes()[i].target);
|
||||||
|
Serial.print(", score=");
|
||||||
|
Serial.print(AI.boxes()[i].score);
|
||||||
|
Serial.print(", x=");
|
||||||
|
Serial.print(AI.boxes()[i].x);
|
||||||
|
Serial.print(", y=");
|
||||||
|
Serial.print(AI.boxes()[i].y);
|
||||||
|
Serial.print(", w=");
|
||||||
|
Serial.print(AI.boxes()[i].w);
|
||||||
|
Serial.print(", h=");
|
||||||
|
Serial.println(AI.boxes()[i].h);
|
||||||
|
|
||||||
|
// Box-Daten zur MQTT-Nachricht hinzufügen
|
||||||
mqttMessage += "{\"target\":\"" + String(AI.boxes()[i].target) + "\",";
|
mqttMessage += "{\"target\":\"" + String(AI.boxes()[i].target) + "\",";
|
||||||
mqttMessage += "\"score\":" + String(AI.boxes()[i].score) + ",";
|
mqttMessage += "\"score\":" + String(AI.boxes()[i].score) + ",";
|
||||||
mqttMessage += "\"x\":" + String(AI.boxes()[i].x) + ",";
|
mqttMessage += "\"x\":" + String(AI.boxes()[i].x) + ",";
|
||||||
@ -85,11 +103,15 @@ void loop() {
|
|||||||
mqttMessage += "\"w\":" + String(AI.boxes()[i].w) + ",";
|
mqttMessage += "\"w\":" + String(AI.boxes()[i].w) + ",";
|
||||||
mqttMessage += "\"h\":" + String(AI.boxes()[i].h) + "},";
|
mqttMessage += "\"h\":" + String(AI.boxes()[i].h) + "},";
|
||||||
}
|
}
|
||||||
if (AI.boxes().size() > 0) {
|
}
|
||||||
|
|
||||||
|
if (validBoxFound) {
|
||||||
mqttMessage.remove(mqttMessage.length() - 1); // Letztes Komma entfernen
|
mqttMessage.remove(mqttMessage.length() - 1); // Letztes Komma entfernen
|
||||||
}
|
}
|
||||||
mqttMessage += "]}";
|
mqttMessage += "]}";
|
||||||
|
|
||||||
|
// Nur senden, wenn mindestens eine Box mit Score > 50 gefunden wurde
|
||||||
|
if (validBoxFound) {
|
||||||
Serial.println("MQTT-Nachricht: " + mqttMessage);
|
Serial.println("MQTT-Nachricht: " + mqttMessage);
|
||||||
|
|
||||||
// MQTT-Nachricht senden
|
// MQTT-Nachricht senden
|
||||||
@ -98,6 +120,8 @@ void loop() {
|
|||||||
} else {
|
} else {
|
||||||
Serial.println("Fehler beim Senden der MQTT-Daten.");
|
Serial.println("Fehler beim Senden der MQTT-Daten.");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Serial.println("Keine Boxen mit Score > 50 gefunden. Keine Daten gesendet.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user