Espnow and softap and send/recive data

Hi currently I try to send data to a esp32-c3 (later on to 3 of them) and my server is a esp8622.

My code is here:
Scanner:

Server:

Currenlty my problem ist, that I will send to the scanner the information that it should start scanning.
But on the Server I have the problem, that I get a error -3 on this line:
int result = esp_now_send((uint8_t*)senderIDs[currentSenderIndex], (uint8_t *)message, sizeof(message) - 1);
for each loop.
But I don´t get any error on void initESPNow() funktion.
What I understand is -3 that the espnow is not init.

Can you help me I work with WiFi.mode(WIFI_AP_STA); and a soft ap on the sender.

br
druckgott

Post your complete sketch as a code-section
here it is

// scanner
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <Arduino.h>
#include <WiFi.h>
#include <esp_now.h>
#include <string>  // In Arduino wird dies meist automatisch eingebunden

//#define DEBUG // Kommentiere diese Zeile aus, um Debugging-Ausgaben zu deaktivieren

std::string deviceSuffix = "_01";  // Definiere das Suffix, z.B. "_01", "_02", etc.
const char* ssid = "LED_GATE_SERVER_01";           // SSID des Access Points (ESP8266)
const char* password = "12345678";                  // Passwort des Access Points (ESP8266)

// Empfänger MAC-Adresse eintragen (Beispiel MAC-Adresse, anpassen!)
//nodemuc testboard
//4A:3F:DA:7E:58:9F
//uint8_t broadcastAddress[] = {0x4A, 0x3F, 0xDA, 0x7E, 0x58, 0x9F};
//ESP8266 von Leadgate mit 18650
//EE:FA:BC:12:C7:4F
uint8_t broadcastAddress[] = {0xEE, 0xFA, 0xBC, 0x12, 0xC7, 0x4F};

typedef struct {
  char deviceName[32];
  int rssi;
  int count; // Zähler hinzufügen
} DroneData;

DroneData droneData;
int count = 0; // Zählervariable

bool canSend = false;

void onDataRecv(const uint8_t *mac, const uint8_t *incomingData, int len) {
      // Print the MAC address of the sender
    Serial.print("Daten empfangen von: ");
    for (int i = 0; i < 6; i++) {
        Serial.printf("%02X", mac[i]);
        if (i < 5) Serial.print(":");
    }
    Serial.print(", Länge: ");
    Serial.println(len);

    // Check if the incoming data matches the expected length and content
    if (len == 4 && memcmp(incomingData, "SEND", 4) == 0) {
        canSend = true;
        Serial.println("Befehl 'SEND' empfangen. canSend auf true gesetzt.");
    } else {
        Serial.println("Unerwartete Daten empfangen.");
    }
}

// Callback-Funktion für ESP-NOW-Sendebestätigung
void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  #ifdef DEBUG
  Serial.print("Sende-Status: ");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Erfolgreich" : "Fehlgeschlagen");
  #endif
}

// ESP-NOW initialisieren
void initESPNow() {
  if (esp_now_init() != ESP_OK) {
    Serial.println("Fehler bei der Initialisierung von ESP-NOW");
    return;
  }
  esp_now_register_recv_cb(onDataRecv);           // Callback für den Empfang registrieren
  esp_now_register_send_cb(onDataSent);           // Callback für den Versand registrieren
}

class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
  void onResult(BLEAdvertisedDevice advertisedDevice) {
    std::string deviceName = advertisedDevice.getName();
    if (!deviceName.empty() && deviceName.find("Drone_") != std::string::npos) {
      int rssi = advertisedDevice.getRSSI();

      // Kombiniere den Gerätenamen mit dem Suffix
      std::string fullDeviceName = deviceName + deviceSuffix;

      // DeviceName und RSSI in struct kopieren
      strncpy(droneData.deviceName, fullDeviceName.c_str(), sizeof(droneData.deviceName));
      droneData.rssi = rssi;
      droneData.count = count; // Zählerstand in die Struktur kopieren
      //memcpy(droneData.macAddress, esp32MacAddress, 6); // MAC-Adresse kopieren

      // Daten per ESP-NOW senden
      esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &droneData, sizeof(droneData));

      #ifdef DEBUG
        Serial.println("Scan-Ergebnis gefunden:");
        Serial.print("Gerätename: ");
        Serial.println(fullDeviceName.c_str());
        Serial.print("Signalstärke (RSSI): ");
        Serial.println(rssi);
        Serial.print("Zählerstand: ");
        Serial.println(count);
        Serial.print("Nachricht gesendet: ");
        Serial.print("ESP_satellit_01: ");
        Serial.print(fullDeviceName.c_str());
        Serial.print(" RSSI: ");
        Serial.println(rssi);
        Serial.println(result == ESP_OK ? "Erfolgreich gesendet" : "Senden fehlgeschlagen");
      #endif
    }

    BLEDevice::getScan()->stop();
  }
};

void connectToWiFi() {
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Verbinde mit dem Access Point...");
  }
  Serial.println("Verbunden mit dem Access Point");
}


void setup() {
  Serial.begin(115200);
  delay(6000);

  connectToWiFi(); // WiFi-Verbindung aufbauen
  
  // Gebe die MAC-Adresse des ESP32 aus
  Serial.print("MAC-Adresse des ESP32: ");
  Serial.println(WiFi.macAddress());

    // Speichere die MAC-Adresse des ESP32
  //WiFi.macAddress(esp32MacAddress);

  // ESP-NOW initialisieren
  WiFi.mode(WIFI_STA);
  initESPNow();

  // Empfänger hinzufügen
  esp_now_peer_info_t peerInfo;
  memcpy(peerInfo.peer_addr, broadcastAddress, 0);
  peerInfo.channel = 0;  
  peerInfo.encrypt = NULL;

  if (esp_now_add_peer(&peerInfo) != ESP_OK) {
    Serial.println("Fehler beim Hinzufügen des Peers");
    return;
  }

  Serial.println("Startet kontinuierlichen BLE-Scan...");

  // BLE initialisieren
  BLEDevice::init("");

  // BLE-Scan konfigurieren
  BLEScan* pBLEScan = BLEDevice::getScan();
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  pBLEScan->setActiveScan(true); // Aktives Scannen für genauere RSSI-Werte
  pBLEScan->setInterval(32);      // Scan-Intervall in 0.625ms-Einheiten
  pBLEScan->setWindow(32);        // Scan-Fenster in 0.625ms-Einheiten
}

// Beispiel-Funktion zum Senden der Daten
void sendESPNowData() {
  // Implementieren Sie hier, welche Daten gesendet werden sollen
    // Zähler hochzählen
  count++;
  if (count > 10000) {
    count = 0; // Zähler zurücksetzen
  }
  Serial.println("Darf senden... " + String(count));
  // Starte den Scan ohne zeitliche Begrenzung und bereinige die Ergebnisse direkt danach
  BLEDevice::getScan()->start(0.1, true); // kurzer Scan, um wiederholte Ergebnisse zu ermöglichen

  BLEDevice::getScan()->clearResults();    // Bereinige die Ergebnisse sofort für den nächsten Scan
  //Serial.println("Daten werden gesendet...");
}

void loop() {

  // Überprüfe die WiFi-Verbindung
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Verbindung verloren. Versuche, erneut zu verbinden...");
    connectToWiFi(); // WiFi erneut verbinden
  }
  if (canSend) {
    Serial.println("Darf senden... ");
    // Daten senden
    sendESPNowData();
    // Senden deaktivieren, bis der Server wieder ein „SEND“-Signal sendet
    
    canSend = false;
  }
}
//ESP8266-server
#include <ESP8266WiFi.h>
#include <espnow.h>
#include <ESP8266WebServer.h>
#include <ArduinoJson.h>
#include <Adafruit_NeoPixel.h> // NeoPixel Bibliothek
#include <EEPROM.h> // EEPROM für Speichern von Werten

//info: https://www.digikey.at/en/maker/tutorials/2024/how-to-implement-two-way-communication-in-esp-now
//#define DEBUG // Kommentiere diese Zeile aus, um Debugging-Ausgaben zu deaktivieren

const char* ssid = "LED_GATE_SERVER_01";           // SSID des Access Points
const char* password = "12345678";                  // Passwort des Access Points
int CHANNEL;

const uint8_t senderIDs[][6] = {
  {0x3C, 0x84, 0x27, 0xAF, 0x19, 0x48}, // 3C:84:27:AF:19:48 von Sender 1
  {0xD8, 0x3B, 0xDA, 0x34, 0xAE, 0x20}, // D8:3B:DA:34:AE:20 von Sender 2
  {0xD8, 0x3B, 0xDA, 0x32, 0x0C, 0xC0}, // D8:3B:DA:32:0C:C0 von Sender 3
  // Fügen Sie weitere Sender-MAC-Adressen hinzu
};

int currentSenderIndex = 0;  // Aktueller Sender
unsigned long interval = 200; // Zeitintervall für jeden Sender
unsigned long lastSwitchTime = 0;

#define MAX_DRONES 10  // Maximalanzahl an Drohnen, die gespeichert werden können
#define MAX_VALUES 3   // Maximalanzahl der RSSI und Counter-Werte pro Drohne

//#define THRESHOLD_RSSI -85 // Definierbarer RSSI-Grenzwert für "innerhalb des Bereichs"
int THRESHOLD_RSSI = -85;
int RESETINTERVAL = 50; // Intervall zwischen den Scans in Millisekunden

// NeoPixel Konfiguration
#define NUM_LEDS 150
#define LED_PIN 2          // Pin für die NeoPixel-LEDs (GPIO2, D4)
int BRIGHTNESS = 60; // Helligkeit als Konstante definieren
#define ENABLE_COLOR_PICKER true // Kann auf false gesetzt werden, um den Farbpicker zu deaktivieren

// Struktur zum Speichern von Drohnendaten
typedef struct {
  char deviceName[32];
  int rssi[MAX_VALUES];  // Array für bis zu 3 RSSI-Werte
  int count[MAX_VALUES];  // Array für bis zu 3 Counter-Werte
  int failed_value[MAX_VALUES];  // Array für bis zu 3 Counter-Werte
  int currentIndex;      // Aktueller Index für den nächsten Wert
  bool isInside;
} DroneData;

// Struktur zum Empfangen von Drohnendaten
typedef struct {
  char deviceName[32];
  int rssi;             // RSSI-Wert
  int count;            // Counter für Drohnen
} ReceivedDroneData;

int closest_drone_index = -1;
int closest_RSSI = 31;
bool ledWhenNoDrone = false; // Standardmäßig auf 'false' setzen
unsigned long previousMillis = 0; // speichert die Zeit des letzten Scans
unsigned long elapsedMillis = 0;  // speichert die verstrichene Zeit zwischen Scans
int current_drone_color = 0;

// EEPROM Adressen festlegen
#define EEPROM_SIZE 512                     // Gesamtgröße des EEPROM
#define EEPROM_BRIGHTNESS_ADDR 0
#define EEPROM_THRESHOLD_RSSI_ADDR (EEPROM_BRIGHTNESS_ADDR + sizeof(int))
#define EEPROM_RESET_INTERVAL_ADDR (EEPROM_THRESHOLD_RSSI_ADDR + sizeof(int))
#define EEPROM_COLOR_START_ADDR (EEPROM_RESET_INTERVAL_ADDR + sizeof(int))
#define EEPROM_LED_WHEN_NO_DRONE_ADDR (EEPROM_COLOR_START_ADDR + (10 * sizeof(uint32_t))) // +10 Farben

// Farben für jede Drone
uint32_t droneColors[10] = {
    0xFF0000, // Drone_01: Rot
    0xFFFF00, // Drone_02: Gelb
    0x00FF00, // Drone_03: Grün
    0x0000FF, // Drone_04: Blau
    0xFF00FF, // Drone_05: Magenta
    0x00FFFF, // Drone_06: Cyan
    0xFFA500, // Drone_07: Orange
    0x800080, // Drone_08: Lila
    0x4bb7d6, // Drone_09: Türkis
    0x808080  // Drone_10: Grau
};

DroneData drones[MAX_DRONES];  // Array zum Speichern von Drohnendaten
int droneCount = 0;             // Zähler für die Anzahl der gespeicherten Drohnen
int rssiThreshold = THRESHOLD_RSSI; // Speichere den Wert in einer int-Variable
int currentIndex = 0; // Starte mit dem ersten ESP der Daten sendet
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
ESP8266WebServer server(80);

void loadConfigFromEEPROM() {
  EEPROM.begin(EEPROM_SIZE); // Initialisiere EEPROM mit 512 Byte
  EEPROM.get(EEPROM_BRIGHTNESS_ADDR, BRIGHTNESS); // weil negative Werte deswegen get
  EEPROM.get(EEPROM_THRESHOLD_RSSI_ADDR, THRESHOLD_RSSI); // weil negative Werte deswegen get
  
  //Serial.print("Loaded THRESHOLD_RSSI: ");
  //Serial.println(THRESHOLD_RSSI);
  EEPROM.get(EEPROM_RESET_INTERVAL_ADDR, RESETINTERVAL); // Entfernung aus EEPROM laden

  // Lade die Farben aus dem EEPROM
  for (int i = 0; i < 10; i++) {
    int colorAddr = EEPROM_COLOR_START_ADDR + (i * sizeof(uint32_t));
    EEPROM.get(colorAddr, droneColors[i]);
  }

  // Boolean-Wert für LED-Umschaltung laden
  ledWhenNoDrone = EEPROM.read(EEPROM_LED_WHEN_NO_DRONE_ADDR) == 1;
}


void debugEEPROMValues() {
  // Debug-Ausgabe der gewünschten Variablen
  Serial.println("save eprom Debug:");
  Serial.print("LED When No Drone: ");
  Serial.println(ledWhenNoDrone ? "ON" : "OFF");

  Serial.print("Threshold RSSI: ");
  Serial.println(THRESHOLD_RSSI);
  
  Serial.print("Brightness: ");
  Serial.println(BRIGHTNESS);

  Serial.print("ResetInterval: ");
  Serial.println(RESETINTERVAL);
  
  // Farben aus dem EEPROM lesen und ausgeben
  Serial.println("Drone Colors:");
  for (int i = 0; i < 10; i++) {
    Serial.print("Color ");
    Serial.print(i);
    Serial.print(": ");
    Serial.println(droneColors[i], HEX); // Ausgabe im Hex-Format
  }
}

void saveConfigToEEPROM() {
  EEPROM.begin(EEPROM_SIZE); // Initialisiere EEPROM mit 512 Byte
  EEPROM.put(EEPROM_BRIGHTNESS_ADDR, BRIGHTNESS); // Helligkeit speichern
  EEPROM.put(EEPROM_THRESHOLD_RSSI_ADDR, THRESHOLD_RSSI); // THRESHOLD speichern (put weil auch negative Werte)
  EEPROM.put(EEPROM_RESET_INTERVAL_ADDR, RESETINTERVAL); // Entfernung speichern

  // Speichere die Farben in EEPROM
  for (int i = 0; i < 10; i++) {
    int colorAddr = EEPROM_COLOR_START_ADDR + (i * sizeof(uint32_t));
    EEPROM.put(colorAddr, droneColors[i]);
  }

  // Boolean-Wert für LED-Umschaltung speichern
  EEPROM.put(EEPROM_LED_WHEN_NO_DRONE_ADDR, ledWhenNoDrone ? 1 : 0);

  EEPROM.commit(); // Änderungen im EEPROM speichern

   // Debug-Ausgabe
  debugEEPROMValues(); 

}

void printElapsedTime(const String& name) {
  Serial.print("Time Output (");
  Serial.print(name);
  Serial.print("): ");
  Serial.print(elapsedMillis);
  Serial.println(" ms");
}

void setAllLEDs(uint32_t color, uint8_t brightness) {
    strip.setBrightness(brightness); // Setzt die Helligkeit für alle LEDs
    
    for (int i = 0; i < NUM_LEDS; i++) {
        strip.setPixelColor(i, color); // Setzt jede LED auf die gleiche Farbe
    }
    
    strip.show(); // Aktualisiert die LEDs, damit die Farbe und Helligkeit angezeigt werden
}

// Funktion zur Berechnung des Mittelwerts der RSSI-Werte einer Drohne
float calculateAverageRSSI(int rssi[MAX_VALUES]) {
  int validCount = 0;
  float sum = 0;

  for (int i = 0; i < MAX_VALUES; i++) {
    if (rssi[i] != 0) { // Nur gültige Werte einbeziehen
      sum += rssi[i];
      validCount++;
    }
  }

  return (validCount > 0) ? sum / validCount : 0;
}

void updateLEDBasedOnRSSI(int closestDroneID, int closestRSSI) {
  if (closestDroneID >= 0 && closestDroneID < 10) {
    // Anzahl der leuchtenden LEDs bestimmen
    int ledCount = 0;
    
    if (closestRSSI >= -30) {
      ledCount = NUM_LEDS; // Alle LEDs leuchten
    } else if (closestRSSI <= -90) {
      ledCount = NUM_LEDS / 2; // 50% der LEDs leuchten
    } else {
      // Interpolation zwischen 0 und -100 für die LED-Anzahl
      ledCount = map(closestRSSI, -90, -30, NUM_LEDS / 2, NUM_LEDS);
    }

    // Setze die Farbe für die LEDs
    for (int i = 0; i < NUM_LEDS; i++) {
      if (i < ledCount) {
        strip.setPixelColor(i, droneColors[closestDroneID]); // Farbe für die aktive Drohne
      }else{
        strip.setPixelColor(i, strip.Color(0, 0, 0)); // Farbe für die aktive Drohne
      }
    }
    
    strip.setBrightness(BRIGHTNESS);
    strip.show(); // Aktualisiere die LEDs
  }
}

void updateDroneStatus(int &closestDroneIndex, float &closestRSSI) {
  closestRSSI = -200;  // Startwert, da RSSI negativ ist
  closestDroneIndex = -1;

  for (int i = 0; i < droneCount; i++) {
    float avgRSSI = 0;
    bool isInside = true;

    // Durchschnitts-RSSI berechnen und prüfen, ob innerhalb des Bereichs
    for (int j = 0; j < MAX_VALUES; j++) {
      avgRSSI += drones[i].rssi[j];

      if (drones[i].rssi[j] < THRESHOLD_RSSI || drones[i].rssi[j] >= 0) {
        isInside = false; // Drohne ist außerhalb des Bereichs
      }
    }

    avgRSSI /= MAX_VALUES; // Durchschnitt berechnen
    drones[i].isInside = isInside;

    // Nächstgelegene Drohne aktualisieren
    if (avgRSSI > closestRSSI && avgRSSI < 0) {
      closestRSSI = avgRSSI;
      closestDroneIndex = i;
    }
  }
}

// Funktion zum Speichern oder Aktualisieren empfangener Daten
void storeDroneData(ReceivedDroneData receivedData) {
  // Extrahiere das Suffix, um den RSSI/Count-Index zu bestimmen
  //printElapsedTime("Start storeDroneData loop");

  int index = -1;
  if (strcmp(&receivedData.deviceName[strlen(receivedData.deviceName) - 3], "_01") == 0) index = 0;
  else if (strcmp(&receivedData.deviceName[strlen(receivedData.deviceName) - 3], "_02") == 0) index = 1;
  else if (strcmp(&receivedData.deviceName[strlen(receivedData.deviceName) - 3], "_03") == 0) index = 2;

  // Wenn das Suffix nicht gefunden wurde, abbrechen
  if (index == -1) return;

  // Überprüfen, ob die Drohne bereits in der Liste ist
  //printElapsedTime("Start drone loop");
  for (int i = 0; i < droneCount; i++) {
    if (strncmp(drones[i].deviceName, receivedData.deviceName, 8) == 0) {
      // Neuen RSSI- und Counter-Wert an der bestimmten Position speichern
      drones[i].rssi[index] = receivedData.rssi;
      drones[i].count[index] = receivedData.count;

      // failed_value aktualisieren, falls der RSSI-Wert den Schwellenwert nicht erreicht
      drones[i].failed_value[index] = (receivedData.rssi < THRESHOLD_RSSI) ? receivedData.rssi : 0;
      //printElapsedTime("Datenempfang beendet");
      // isInside anhand der aktuellen RSSI-Werte neu berechnen
      //drones[i].isInside = calculateIsInside(drones[i].rssi);
      // Aktualisieren der nächstgelegenen Drohne
      int closestDroneIndex;
      float closestRSSI = 31;
      // Aufruf der neuen Funktion
      updateDroneStatus(closestDroneIndex, closestRSSI);
      //printElapsedTime("Update Status beendet");
      //Farbe ändern wenn die näheste Drone innerhalb des Rings ist
      if (drones[i].isInside && closestDroneIndex != -1) {
        current_drone_color = String(drones[closestDroneIndex].deviceName).substring(6).toInt();
      }else if (ledWhenNoDrone) {
        setAllLEDs(strip.Color(255, 255, 255), BRIGHTNESS);
      }
      //printElapsedTime("Update Farbe Led beendet");
      #ifdef DEBUG
      Serial.print("Die nächste Drohne ist: ");
      Serial.println(drones[closestDroneIndex].deviceName);
      #endif
      closest_drone_index = closestDroneIndex;
      closest_RSSI = closestRSSI;
      updateLEDBasedOnRSSI(current_drone_color, closestRSSI);
      //printElapsedTime("Update RSSI Led beendet");
      return; // Aktualisierung vorgenommen, keine weitere Speicherung nötig
    }
  }
  //printElapsedTime("Ende drone loop");
  //printElapsedTime("Start first drone loop");
  // Wenn die Drohne noch nicht gespeichert ist, füge sie hinzu
  if (droneCount < MAX_DRONES) {
    // Kopiere die ersten 8 Zeichen von receivedData.deviceName
    strncpy(drones[droneCount].deviceName, receivedData.deviceName, 8);
    drones[droneCount].deviceName[8] = '\0'; // Nullterminator hinzufügen
    
    // Alle RSSI werte initialisieren mit 0
    memset(drones[droneCount].rssi, 0, sizeof(drones[droneCount].rssi));
    memset(drones[droneCount].count, 0, sizeof(drones[droneCount].count));
    // Speichere den neuen RSSI- und Counter-Wert an der bestimmten Position
    drones[droneCount].rssi[index] = receivedData.rssi;
    drones[droneCount].count[index] = receivedData.count;

    // failed_value initialisieren
    drones[droneCount].failed_value[index] = (receivedData.rssi < THRESHOLD_RSSI) ? receivedData.rssi : 0;
    // Berechne den isInside-Status bei erstmaligem Hinzufügen
    //drones[droneCount].isInside = calculateIsInside(drones[droneCount].rssi);
    // Aktualisieren der nächstgelegenen Drohne
    int closestDroneIndex;
    float closestRSSI = 31;
    //findClosestDrone(closestDroneIndex, closestRSSI);
    // Aufruf der neuen Funktion
    updateDroneStatus(closestDroneIndex, closestRSSI);
    drones[droneCount].currentIndex = 1; // Setze den aktuellen Index auf 1
    //Farbe ändern wenn die näheste Drone innerhalb des Rings ist
    if (drones[droneCount].isInside && closestDroneIndex != -1) {
      current_drone_color = String(drones[closestDroneIndex].deviceName).substring(6).toInt();
    }else if (ledWhenNoDrone) {
      setAllLEDs(strip.Color(255, 255, 255), BRIGHTNESS);
    }
    #ifdef DEBUG
    Serial.print("Die nächste Drohne ist: ");
    Serial.println(drones[closestDroneIndex].deviceName);
    #endif
    closest_drone_index = closestDroneIndex;
    closest_RSSI = closestRSSI;
    updateLEDBasedOnRSSI(current_drone_color, closestRSSI);

    droneCount++; // Erhöhe die Drohnennummer
  }
  //printElapsedTime("Ende first drone loop");

}

// Callback-Funktion für ESP-NOW-Sendebestätigung
void onDataSent(uint8_t *mac_addr, uint8_t status) {
  //#ifdef DEBUG
  Serial.print("Sende-Status: ");
  Serial.println(status == 0 ? "Erfolgreich" : "Fehlgeschlagen");

  Serial.print("Ziel-MAC-Adresse: ");
  for (int i = 0; i < 6; i++) {
    Serial.print(mac_addr[i], HEX);
    if (i < 5) {
      Serial.print(":");
    }
  }
  Serial.println();
  //#endif
}

// Callback-Funktion für den Empfang von ESP-NOW-Daten
void onDataRecv(uint8_t *mac, uint8_t *incomingData, uint8_t len) {
  ReceivedDroneData receivedData;
  memcpy(&receivedData, incomingData, sizeof(receivedData));
  //#ifdef DEBUG
  Serial.print("Daten empfangen von: ");
  for (int i = 0; i < 6; i++) {
      Serial.printf("%02X", mac[i]);
      if (i < 5) Serial.print(":");
  }
  Serial.printf(" | Gerätename: %s | RSSI: %d | Counter: %d\n", receivedData.deviceName, receivedData.rssi, receivedData.count);
  //#endif
  // Drohne zu den Daten hinzufügen oder aktualisieren
  storeDroneData(receivedData);
}

// Funktion zum Erstellen des JSON-Dokuments für die Drohnendaten
String getDroneDataJson() {
  StaticJsonDocument<1024> jsonDoc;
  
  // Verwende jsonDoc["drones"].to<JsonArray>() anstelle von createNestedArray
  JsonArray jsonDrones = jsonDoc["drones"].to<JsonArray>();
  //printElapsedTime("Start webside loop");
  for (int i = 0; i < droneCount; i++) {
    // Verwende jsonDrones.add<JsonObject>() anstelle von createNestedObject
    JsonObject drone = jsonDrones.add<JsonObject>();
    
    // Füge nur die ersten 8 Zeichen von deviceName hinzu
    char shortDeviceName[9]; // Array für die ersten 8 Zeichen plus Nullterminator
    strncpy(shortDeviceName, drones[i].deviceName, 8);
    shortDeviceName[8] = '\0'; // Nullterminator hinzufügen
    drone["deviceName"] = shortDeviceName;

    // Verwende obj[key].to<JsonArray>() anstelle von createNestedArray für Arrays
    JsonArray rssiArray = drone["rssi"].to<JsonArray>();
    JsonArray countArray = drone["count"].to<JsonArray>();
    JsonArray failedValueArray = drone["failed_value"].to<JsonArray>();

    for (int j = 0; j < MAX_VALUES; j++) {
      rssiArray.add(drones[i].rssi[j]);
      countArray.add(drones[i].count[j]);
      failedValueArray.add(drones[i].failed_value[j]);
    }

    // isInside-Status direkt aus der Struktur übernehmen
    drone["isInside"] = drones[i].isInside;
    drone["closest"]["drone_index"] = closest_drone_index;
    drone["closest"]["rssi"] = closest_RSSI;
  }
  //printElapsedTime("Ende webside loop");
  String json;
  serializeJson(jsonDoc, json);
  
  return json; // Rückgabe des JSON-Strings
}

// HTML-Seite für die Anzeige
const char* htmlPage = R"rawl(
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Drone Data</title>
  <style>
    table {
      width: 100%;
      border-collapse: collapse;
    }
    th, td {
      border: 1px solid black;
      padding: 8px;
      text-align: left;
    }
    th {
      background-color: #f2f2f2;
    }
    .green-bg {
      background-color: #a8e6a1; // Grün für niedrigen RSSI
    }
    .red-bg {
      background-color: #f4a8a8; // Rot für hohen RSSI
    }
    .closest {
      background-color: lime;
      color: black;
    }
    .farther {
      background-color: yellow;
      color: black;
    }
    .config-button {
      margin-top: 20px; /* Space above */
      padding: 10px 20px; /* Padding for the button */
      font-size: 16px; /* Font size */
      background-color: #4CAF50; /* Green background */
      color: white; /* White text color */
      border: none; /* No borders */
      border-radius: 5px; /* Rounded corners */
      cursor: pointer; /* Pointer on hover */
    }
    .config-button:hover {
      background-color: #45a049; /* Darker green on hover */
    }
  </style>
  <script>
      let THRESHOLD_RSSI_JAVA;

      // Hole den THRESHOLD_RSSI-Wert vom Server
      fetch('/threshold')
        .then(response => response.json())
        .then(data => {
          THRESHOLD_RSSI_JAVA = data.threshold;
        });


  setInterval(function() {
    fetch('/droneData')
      .then(response => response.json())
      .then(data => {
        const tableBody = document.getElementById('droneList');
        tableBody.innerHTML = ''; // Tabelle leeren

        data.drones.forEach((drone, index) => {
          const row = document.createElement('tr');

          // Setze die Klasse basierend auf "closest"
          const rowClass = (index === data.drones[0].closest.drone_index) ? 'closest' : 'farther';
          row.className = rowClass;

          // Bestimme die Klasse für die RSSI-Werte basierend auf THRESHOLD_RSSI_JAVA
          const rssiCells = drone.rssi.map(rssi => {
          // Überprüfen, ob rssi einen Wert hat, sonst rot setzen
            const className = (rssi === null || rssi === undefined || rssi === 0 || rssi <= THRESHOLD_RSSI_JAVA) ? 'red-bg' : 'green-bg';
            return `<td class="${className}">${rssi || ''}</td>`;
          });

          row.innerHTML = `<td>${drone.deviceName}</td>
                           ${rssiCells[0]}<td>${drone.count[0] || ''}</td>
                           ${rssiCells[1]}<td>${drone.count[1] || ''}</td>
                           ${rssiCells[2]}<td>${drone.count[2] || ''}</td>
                           <td>${drone.isInside ? 'true' : 'false'}</td>`;

          tableBody.appendChild(row);
        });
      });
  }, 10); // Aktualisiere alle 0.01 Sekunde
</script>
</head>
<body>
  <h1>Live Drone Data</h1>
  <table>
    <thead>
      <tr>
        <th>Gerätename</th>
        <th>RSSI 1</th>
        <th>Counter 1</th>
        <th>RSSI 2</th>
        <th>Counter 2</th>
        <th>RSSI 3</th>
        <th>Counter 3</th>
        <th>isInside</th>
      </tr>
    </thead>
    <tbody id="droneList"></tbody>
  </table>
  <button class="config-button" onclick="window.location.href='/config'">Configuration</button>
  <button class="config-button" target="_blank" onclick="window.location.href='/droneData'">RAW_DATA</button>
</body>
</html>
)rawl";

// Web server handler for the configuration page
void handleConfigPage() {
    String html = R"=====(
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="UTF-8">
      <title>Configuration</title>
      <style>
        body {
          background-color: #f0f0f0;
          font-family: Arial, sans-serif;
          color: black;
        }
        input[type="number"] {
          width: 50px; /* Width for number fields */
        }
        input[type="text"] {
          width: 80px; /* Width for hex value input fields */
        }
      </style>
      <script>
        function updateHexValue(colorInput, hexInput) {
            document.getElementById(hexInput).value = colorInput.value;
        }
        
        function resetColors() {
            // Reset to default colors
            const defaultColors = [
                "#FF0000", "#FFFF00", "#00FF00", "#0000FF", 
                "#FF00FF", "#00FFFF", "#FFA500", "#800080", 
                "#4bb7d6", "#808080"
            ];
            for (let i = 0; i < 10; i++) {
                document.getElementById("drone_0" + (i + 1)).value = defaultColors[i];
                document.getElementById("drone_0" + (i + 1) + "_hex").value = defaultColors[i];
            }
        }
      </script>
    </head>
    <body>
      <h1>LED Configuration</h1>
      <form action="/saveConfig" method="POST">
        <label for="brightness">LED Brightness (0-255):</label>
        <input type="number" id="brightness" name="brightness" min="0" max="255" value=")=====" + String(BRIGHTNESS) + R"=====(">
        <br><br>

        <label for="thresholdrssi">thresholdrssi Value (-200 bis -1):</label>
        <input type="number" id="thresholdrssi" name="thresholdrssi" min="-200" max="-1" value=")=====" + String(THRESHOLD_RSSI) + R"=====(">
        <br><br>

        <label for="resetInterval">resetInterval Intervall (1-1000ms):</label>
        <input type="number" id="resetInterval" name="resetInterval" min="1" max="1000" value=")=====" + String(RESETINTERVAL) + R"=====(">
        <br><br>

        <label for="ledWhenNoDrone">Switch LED to white when no drone is detected:</label>
        <input type="checkbox" id="ledWhenNoDrone" name="ledWhenNoDrone")=====" + (ledWhenNoDrone ? "checked" : "") + R"=====( value="1">
        <br><br>

        )=====";

#if ENABLE_COLOR_PICKER
    html += "<label for=\"color\">Color selection for drones:</label><br>";

    for (int i = 0; i < 10; i++) {
        String droneName = "drone_0" + String(i + 1);
        String hexColor = String(droneColors[i], HEX);

        // Add leading zeros to ensure the value is 6 digits
        while (hexColor.length() < 6) {
            hexColor = "0" + hexColor; 
        }
        hexColor = "#" + hexColor; // Prepend '#' for the color selection

        html += "<label for=\"" + droneName + "\">Drone_0" + String(i + 1) + " (Colors):</label>";
        html += "<input type=\"color\" id=\"" + droneName + "\" name=\"" + droneName + "\" value=\"" + hexColor + "\" onchange=\"updateHexValue(this, '" + droneName + "_hex')\">";
        html += "<input type=\"text\" id=\"" + droneName + "_hex\" name=\"" + droneName + "_hex\" value=\"" + hexColor + "\"><br>";
        //html += "<span>Current value: " + hexColor + "</span><br>";
    }

    html += "<br><br>";
#endif

    // Button to reset colors
    html += "<input type=\"button\" value=\"Reset colors\" onclick=\"resetColors()\"><br><br>";

    html += R"=====(
        <input type="submit" value="Save">
        <input type="button" value="Back" onclick="window.location.href='/'">
      </form>
    </body>
    </html>
    )=====";

    server.send(200, "text/html", html);
}

// Webserver Handler für das Speichern der Konfiguration
void handleSaveConfig() {
  if (server.hasArg("brightness")) {
    int brightness = server.arg("brightness").toInt();
    if (brightness >= 0 && brightness <= 255) {
      BRIGHTNESS = brightness;
    }
  }

  if (server.hasArg("thresholdrssi")) {
    int thresholdrssi = server.arg("thresholdrssi").toInt();
    if (thresholdrssi >= -200 && thresholdrssi <= -1) {
      THRESHOLD_RSSI = thresholdrssi;
    }
  }

  if (server.hasArg("resetInterval")) {
    int resetInterval = server.arg("resetInterval").toInt();
    if (resetInterval >= 1 && resetInterval <= 1000) {
      RESETINTERVAL = resetInterval;
    }
  }
  
  if (server.hasArg("ledWhenNoDrone")) {
    // Wenn die Checkbox angehakt ist, wird der Wert "1" übergeben, damit ist die variable true gesetzt
    ledWhenNoDrone = (server.arg("ledWhenNoDrone") == "1");
  } else {
    // Wenn das Argument fehlt, ist die Checkbox nicht angehakt, setze ledWhenNoDrone auf false
    ledWhenNoDrone = false;
  }

#if ENABLE_COLOR_PICKER
    for (int i = 0; i < 10; i++) {
        String hexFieldName = "drone_0" + String(i + 1) + "_hex"; // Name des Textfelds für den Hex-Wert
        if (server.hasArg(hexFieldName)) {
            String hexValue = server.arg(hexFieldName); // Hole den Hex-Wert als String

            // Überprüfen, ob das '#' am Anfang steht und nur die letzten 6 Zeichen für RGB verwenden
            if (hexValue.startsWith("#")) {
                hexValue = hexValue.substring(1); // Entferne das '#'
            }

            // Stellen Sie sicher, dass der Hex-Wert 6 Zeichen hat, indem Sie führende Nullen hinzufügen
            while (hexValue.length() < 6) {
                hexValue = "0" + hexValue; // Fügen Sie führende Nullen hinzu
            }

            // Stelle sicher, dass der Hex-Wert 6 Zeichen hat
            if (hexValue.length() == 6) {
                droneColors[i] = strtol(hexValue.c_str(), NULL, 16); // Konvertiere in Ganzzahl
            } else {
                Serial.println("Invalid hex value for Drone " + String(i + 1) + ": " + hexValue); // Error log
            }
            #if DEBUG
            Serial.println("Drone " + String(i + 1) + " Color: " + String(droneColors[i], HEX)); // Debugging
            #endif
        } else {
            Serial.println("No argument found for Drone " + String(i + 1)); // Error log when the argument is missing
        }
    }
#endif

  saveConfigToEEPROM(); // Konfiguration ins EEPROM speichern
  
  // Umleitung zur Konfigurationsseite
  server.sendHeader("Location", "/config"); // Hier "config" sollte der Pfad zur Konfigurationsseite sein
  server.send(303); // HTTP 303 See Other
}

// Funktion zur Initialisierung des WLAN-AP und des Webservers
void setupWiFiAndServer() {

  WiFi.mode(WIFI_AP_STA); // Ermöglicht AP und Station gleichzeitig
  // AP-Modus starten
  WiFi.softAP(ssid, password, CHANNEL);
  Serial.println("Access Point gestartet auf");

  // Eigene MAC-Adresse anzeigen
  Serial.print("MAC-Adresse: ");
  Serial.println(WiFi.softAPmacAddress());

  // IP-Adresse des Access Points ausgeben
  Serial.print("IP-Adresse: ");
  Serial.println(WiFi.softAPIP());

  
  if (int32_t n = WiFi.scanNetworks()) {
      for (uint8_t i=0; i<n; i++) {
          if (!strcmp(ssid, WiFi.SSID(i).c_str())) {
              CHANNEL = WiFi.channel(i); } } }

  wifi_set_channel(CHANNEL);
  Serial.print("CHANNEL: ");
  Serial.println(CHANNEL);

  // Webserver-Routen
  server.on("/", []() {
    server.send(200, "text/html", htmlPage);
  });

  server.on("/droneData", []() {
    String json = getDroneDataJson(); // Aufruf der Funktion zur Erstellung des JSON
    server.send(200, "application/json", json);
  });

  server.on("/threshold", []() {
  String json;
  StaticJsonDocument<32> doc;
  doc["threshold"] = THRESHOLD_RSSI;
  serializeJson(doc, json);
  server.send(200, "application/json", json);
  });

  // Neue Routen für Konfigurationsseite
  server.on("/config", handleConfigPage);
  server.on("/saveConfig", HTTP_POST, handleSaveConfig);

  server.begin();
  Serial.println("Webserver gestartet");

}

void initESPNow() {
  if (esp_now_init() != 0) {   // Ersetzen Sie ESP_OK durch 0
    Serial.println("Fehler bei der Initialisierung von ESP-NOW");
    return;
  }

  esp_now_register_recv_cb(onDataRecv);
  esp_now_register_send_cb(onDataSent);
  esp_now_add_peer((uint8_t*)senderIDs[0], ESP_NOW_ROLE_COMBO, CHANNEL, NULL, 0);
  esp_now_add_peer((uint8_t*)senderIDs[1], ESP_NOW_ROLE_COMBO, CHANNEL, NULL, 0);
  esp_now_add_peer((uint8_t*)senderIDs[2], ESP_NOW_ROLE_COMBO, CHANNEL, NULL, 0);
  Serial.println("ESP-NOW erfolgreich initialisiert und bereit für Senden und Empfangen.");
}

void startLed() {
  strip.begin(); // NeoPixel initialisieren
  strip.setBrightness(BRIGHTNESS);
  strip.show(); // Sicherstellen, dass die LEDs zu Beginn ausgeschaltet sind
}

void setup() {
  Serial.begin(115200);
  delay(6000);
  Serial.println("");

  loadConfigFromEEPROM(); // Lade gespeicherte Konfiguration
  startLed();
  // WLAN und Webserver einrichten
  setupWiFiAndServer();
  initESPNow();

  Serial.println("Warte auf ESP-NOW-Nachrichten...");

}

void loop() {
  // ESP-NOW arbeitet mit Callback, daher keine Logik im Haupt-Loop nötig
  server.handleClient(); // Clientanfragen bearbeiten
    // Überprüfen, ob das Intervall abgelaufen ist
  elapsedMillis = millis();
  if ((unsigned long)(elapsedMillis - previousMillis) >= (unsigned long)RESETINTERVAL) {
    // Nächsten Sender bestimmen
    currentSenderIndex = (currentSenderIndex + 1) % (sizeof(senderIDs) / sizeof(senderIDs[0]));
    previousMillis = elapsedMillis;
    
    // Token an aktuellen Sender senden
    // Casten Sie `senderIDs[currentSenderIndex]` und "SEND" zu `u8*`
    char message[] = "SEND"; // Dies ist ein char-Array, das die Größe des Strings enthält
    int result = esp_now_send((uint8_t*)senderIDs[currentSenderIndex], (uint8_t *)message, sizeof(message) - 1); 
    Serial.println("esp_now_send " + String(result));
    Serial.print("Sender ");
    Serial.print(currentSenderIndex);
    Serial.println(" darf jetzt senden.");
  }
}

Post much more detailed information what you are trying do do.
Scanner sounds like scanning documents.

Did you try a testcode that does nothing more than sending an ESP-NOW message
= a code that has zero bluetooth?

Ok I reduced it to a minimum, what I want to have is that the Server AP will triger the slave that it´s allowd to send data. After that the slave should send back data to the server AP:

Slave:

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <Arduino.h>
#include <WiFi.h>
#include <esp_now.h>
#include <string>  // In Arduino wird dies meist automatisch eingebunden

//#define DEBUG // Kommentiere diese Zeile aus, um Debugging-Ausgaben zu deaktivieren

const char* ssid = "LED_GATE_SERVER_01";           // SSID des Access Points (ESP8266)
const char* password = "12345678";                  // Passwort des Access Points (ESP8266)

// Empfänger MAC-Adresse eintragen (Beispiel MAC-Adresse, anpassen!)
//ESP8266 von Leadgate mit 18650
//EE:FA:BC:12:C7:4F
uint8_t broadcastAddress[] = {0xEE, 0xFA, 0xBC, 0x12, 0xC7, 0x4F};

bool canSend = false;

void onDataRecv(const uint8_t *mac, const uint8_t *incomingData, int len) {
      // Print the MAC address of the sender
    Serial.print("Daten empfangen von: ");
    for (int i = 0; i < 6; i++) {
        Serial.printf("%02X", mac[i]);
        if (i < 5) Serial.print(":");
    }
    Serial.print(", Länge: ");
    Serial.println(len);

    // Check if the incoming data matches the expected length and content
    if (len == 4 && memcmp(incomingData, "SEND", 4) == 0) {
        canSend = true;
        Serial.println("Befehl 'SEND' empfangen. canSend auf true gesetzt.");
    } else {
        Serial.println("Unerwartete Daten empfangen.");
    }
}

// Callback-Funktion für ESP-NOW-Sendebestätigung
void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  //#ifdef DEBUG
  Serial.print("Sende-Status: ");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Erfolgreich" : "Fehlgeschlagen");
  //#endif
}

// ESP-NOW initialisieren
void initESPNow() {
  if (esp_now_init() != ESP_OK) {
    Serial.println("Fehler bei der Initialisierung von ESP-NOW");
    return;
  }
  esp_now_register_recv_cb(onDataRecv);           // Callback für den Empfang registrieren
  esp_now_register_send_cb(onDataSent);           // Callback für den Versand registrieren
}

void connectToWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.setSleep(false);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Verbinde mit dem Access Point...");
  }
  Serial.println("Verbunden mit dem Access Point");
}

void setup() {
  Serial.begin(115200);
  delay(6000);

  connectToWiFi(); // WiFi-Verbindung aufbauen
  
  // Gebe die MAC-Adresse des ESP32 aus
  Serial.print("MAC-Adresse des ESP32: ");
  Serial.println(WiFi.macAddress());

  // ESP-NOW initialisieren
  initESPNow();

  // Empfänger hinzufügen
  esp_now_peer_info_t peerInfo;
  memcpy(peerInfo.peer_addr, broadcastAddress, 6);
  peerInfo.channel = 0;  
  peerInfo.encrypt = NULL;

  if (esp_now_add_peer(&peerInfo) != ESP_OK) {
    Serial.println("Fehler beim Hinzufügen des Peers");
    return;
  }
}

void loop() {

  // Überprüfe die WiFi-Verbindung
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Verbindung verloren. Versuche, erneut zu verbinden...");
    connectToWiFi(); // WiFi erneut verbinden
  }
  if (canSend) {
    Serial.println("Darf senden... ");
    // Daten per ESP-NOW senden
    char message[] = "SENDBACK"; // Dies ist ein char-Array, das die Größe des Strings enthält
    // Daten senden
    esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *)message, sizeof(message) - 1); 
    
    canSend = false;
  }

}

Master (Server with AP):

#include <ESP8266WiFi.h>
#include <espnow.h>
#include <ESP8266WebServer.h>
#include <ArduinoJson.h>
#include <Adafruit_NeoPixel.h> // NeoPixel Bibliothek
#include <EEPROM.h> // EEPROM für Speichern von Werten

//info: https://www.digikey.at/en/maker/tutorials/2024/how-to-implement-two-way-communication-in-esp-now
//#define DEBUG // Kommentiere diese Zeile aus, um Debugging-Ausgaben zu deaktivieren

const char* ssid = "LED_GATE_SERVER_01";           // SSID des Access Points
const char* password = "12345678";                  // Passwort des Access Points
int CHANNEL;

const uint8_t senderIDs[][6] = {
  {0x3C, 0x84, 0x27, 0xAF, 0x19, 0x48}, // 3C:84:27:AF:19:48 von Sender 1
  // Fügen Sie weitere Sender-MAC-Adressen hinzu
};

int currentSenderIndex = 0;  // Aktueller Sender
int RESETINTERVAL = 50; // Intervall zwischen den Scans in Millisekunden

unsigned long previousMillis = 0; // speichert die Zeit des letzten Scans
unsigned long elapsedMillis = 0;  // speichert die verstrichene Zeit zwischen Scans
int currentIndex = 0; // Starte mit dem ersten ESP der Daten sendet

ESP8266WebServer server(80);

// Callback-Funktion für ESP-NOW-Sendebestätigung
void onDataSent(uint8_t *mac_addr, uint8_t status) {
  //#ifdef DEBUG
  Serial.print("Sende-Status: ");
  Serial.println(status == 0 ? "Erfolgreich" : "Fehlgeschlagen");

  Serial.print("Ziel-MAC-Adresse: ");
  for (int i = 0; i < 6; i++) {
    Serial.print(mac_addr[i], HEX);
    if (i < 5) {
      Serial.print(":");
    }
  }
  Serial.println();
  //#endif
}

// Callback-Funktion für den Empfang von ESP-NOW-Daten
void onDataRecv(uint8_t *mac, uint8_t *incomingData, uint8_t len) {
      // Print the MAC address of the sender
    Serial.print("Daten empfangen von: ");
    for (int i = 0; i < 6; i++) {
        Serial.printf("%02X", mac[i]);
        if (i < 5) Serial.print(":");
    }
    Serial.print(", Länge: ");
    Serial.println(len);

    // Check if the incoming data matches the expected length and content
    if (len == 8 && memcmp(incomingData, "SENDBACK", 8) == 0) {
        Serial.println("Befehl 'SENDBACK' empfangen. canSend auf true gesetzt.");
    } else {
        Serial.println("Unerwartete Daten empfangen.");
    }
}

// Funktion zur Initialisierung des WLAN-AP und des Webservers
void setupWiFiAndServer() {

  WiFi.mode(WIFI_AP_STA); // Ermöglicht AP und Station gleichzeitig
  WiFi.setSleepMode(WIFI_NONE_SLEEP);
  // AP-Modus starten
  WiFi.softAP(ssid, password, CHANNEL);
  Serial.println("Access Point gestartet auf");

  // Eigene MAC-Adresse anzeigen
  Serial.print("MAC-Adresse: ");
  Serial.println(WiFi.softAPmacAddress());

  // IP-Adresse des Access Points ausgeben
  Serial.print("IP-Adresse: ");
  Serial.println(WiFi.softAPIP());

  
  if (int32_t n = WiFi.scanNetworks()) {
      for (uint8_t i=0; i<n; i++) {
          if (!strcmp(ssid, WiFi.SSID(i).c_str())) {
              CHANNEL = WiFi.channel(i); } } }

  wifi_set_channel(CHANNEL);
  Serial.print("CHANNEL: ");
  Serial.println(CHANNEL);

  server.begin();
  Serial.println("Webserver gestartet");

}

void initESPNow() {
  if (esp_now_init() != 0) {   // Ersetzen Sie ESP_OK durch 0
    Serial.println("Fehler bei der Initialisierung von ESP-NOW");
    return;
  }

  esp_now_register_recv_cb(onDataRecv);
  esp_now_register_send_cb(onDataSent);
  esp_now_add_peer((uint8_t*)senderIDs[0], ESP_NOW_ROLE_COMBO, CHANNEL, NULL, 0);
  Serial.println("ESP-NOW erfolgreich initialisiert und bereit für Senden und Empfangen.");
}

void setup() {
  Serial.begin(115200);
  delay(6000);
  Serial.println("");
  // WLAN und Webserver einrichten
  setupWiFiAndServer();
  initESPNow();

  Serial.println("Warte auf ESP-NOW-Nachrichten...");

}

void loop() {
  // ESP-NOW arbeitet mit Callback, daher keine Logik im Haupt-Loop nötig
  server.handleClient(); // Clientanfragen bearbeiten
    // Überprüfen, ob das Intervall abgelaufen ist
  elapsedMillis = millis();
  if ((unsigned long)(elapsedMillis - previousMillis) >= (unsigned long)RESETINTERVAL) {
    // Nächsten Sender bestimmen
    currentSenderIndex = (currentSenderIndex + 1) % (sizeof(senderIDs) / sizeof(senderIDs[0]));
    previousMillis = elapsedMillis;
    
    // Token an aktuellen Sender senden
    // Casten Sie `senderIDs[currentSenderIndex]` und "SEND" zu `u8*`
    char message[] = "SEND"; // Dies ist ein char-Array, das die Größe des Strings enthält
    int result = esp_now_send((uint8_t*)senderIDs[currentSenderIndex], (uint8_t *)message, sizeof(message) - 1); 
    Serial.println("esp_now_send " + String(result));
    Serial.print("Sender ");
    Serial.print(currentSenderIndex);
    Serial.println(" darf jetzt senden.");
  }
}

And the start trigger, so the server do not send out the massage. I get error -3 on sending
Bevor I change to this, I already had a version, where the slave did only send to the server and this worked. But the Request from the server is not not working.

In the example I now have for the ESP8266 a SEND massage which should be send to the ESP32-C3 and then the ESP32-C3 should awnser with SENDBACK to the ESP8266 and parallel I want to have a AP on the ESP8266.

On an ESP8266 the Wifi and the ESP-NOW must use the same WIFi-channel.

Why don't you do some googling with the relevant words yourself?

I already goggle and use chatgpt and the channels is inside with 0 and a search on the Server. I checke this also several Times bevor i Post here but did Not help.
The example i already did See yesterday and checke also.

int CHANNEL;

Zudem sendet in dem Beispiel der Server keine Daten sondern empängt nur daten, das habe ich ja bereits hinbekommen. Ich will vom Server aus Daten versenden und empfangen und beim anderen esp32 auch.

Ich habe noch das Beispiel gefunden.

und das obere genannte, hab den Code jetzt noch umgebaut, bekomme aber keine verbindung hin, was beide Richtungen angeht.

Auch dieses Beispiel hab ich angeschaut:

Beide ESP´s sagen aber das sie auf Channel 1 sind.

vom ESP32 auf den Server senden, geht einwandfrei, nur die andere Richtung vom Server auf den ESP32 geht eben nicht.

Das bedeutet ja eigentlich, dass der Kanal passen muss.

mein Aktueller code ist folgender:
ESP32 Empfänger/Sender:

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <Arduino.h>
#include <WiFi.h>
#include <esp_wifi.h>
#include <esp_now.h>
#include <string>  // In Arduino wird dies meist automatisch eingebunden

//#define DEBUG // Kommentiere diese Zeile aus, um Debugging-Ausgaben zu deaktivieren

const char* ssid = "LED_GATE_SERVER_01";           // SSID des Access Points (ESP8266)
const char* password = "12345678";                  // Passwort des Access Points (ESP8266)
esp_now_peer_info_t peerInfo;
uint8_t channel = 1;
bool channelFound = false;

// Empfänger MAC-Adresse eintragen (Beispiel MAC-Adresse, anpassen!)
//ESP8266 von Leadgate mit 18650
//EE:FA:BC:12:C7:4F
uint8_t broadcastAddress[] = {0xEE, 0xFA, 0xBC, 0x12, 0xC7, 0x4F};

bool canSend = false;

// ----------------------------------------------------------------------------
// Offsets wifi channel by 1 when called
// ----------------------------------------------------------------------------
void tryNextChannel() {
  Serial.println("Changing channel from " + String(channel) + " to " + String(channel+1));
  channel = channel % 13 + 1;
  esp_wifi_set_promiscuous(true);
  esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
  esp_wifi_set_promiscuous(false);
}

void onDataRecv(const uint8_t *mac_addr, const uint8_t *incomingData, int len) {
      // Print the MAC address of the sender
    Serial.print("Daten empfangen von: ");
    for (int i = 0; i < 6; i++) {
        Serial.printf("%02X", mac_addr[i]);
        if (i < 5) Serial.print(":");
    }
    Serial.print(", Länge: ");
    Serial.println(len);

    // Check if the incoming data matches the expected length and content
    if (len == 4 && memcmp(incomingData, "SEND", 4) == 0) {
        canSend = true;
        Serial.println("Befehl 'SEND' empfangen. canSend auf true gesetzt.");
    } else {
        Serial.println("Unerwartete Daten empfangen.");
    }
}

// Callback-Funktion für ESP-NOW-Sendebestätigung
void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  if (!channelFound && status != ESP_NOW_SEND_SUCCESS) {
    Serial.println("Delivery Fail because channel" + String(channel) + " does not match receiver channel.");
    tryNextChannel(); // If message was not delivered, it tries on another wifi channel.
  }
  else {
    Serial.println("Delivery Successful ! Using channel : " + String(channel));
    channelFound = true;
  }
}

// ESP-NOW initialisieren
void initESPNow() {
  if (esp_now_init() != ESP_OK) {
    Serial.println("Fehler bei der Initialisierung von ESP-NOW");
    return;
  }

  // Empfänger hinzufügen
  memcpy(peerInfo.peer_addr, broadcastAddress, 6);
  peerInfo.channel = channel;  
  peerInfo.encrypt = false;

  if (esp_now_add_peer(&peerInfo) != ESP_OK) {
    Serial.println("Fehler beim Hinzufügen des Peers");
    return;
  }

  esp_wifi_set_promiscuous(true);
  esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
  esp_wifi_set_promiscuous(false);

  esp_now_register_recv_cb(onDataRecv);           // Callback für den Empfang registrieren
  esp_now_register_send_cb(onDataSent);           // Callback für den Versand registrieren
}

void connectToWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.setSleep(false);
  WiFi.begin(ssid, password);


  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Verbinde mit dem Access Point...");
  }
  Serial.println("Verbunden mit dem Access Point");
}

void setup() {
  Serial.begin(115200);
  delay(6000);

  connectToWiFi(); // WiFi-Verbindung aufbauen
  
  // Gebe die MAC-Adresse des ESP32 aus
  Serial.print("MAC-Adresse des ESP32: ");
  Serial.println(WiFi.macAddress());

  // ESP-NOW initialisieren
  initESPNow();

}

void loop() {

  // Überprüfe die WiFi-Verbindung
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Verbindung verloren. Versuche, erneut zu verbinden...");
    connectToWiFi(); // WiFi erneut verbinden
  }
  if (canSend) {
    Serial.println("Darf senden... ");
    // Daten per ESP-NOW senden
    char message[] = "SENDBACK"; // Dies ist ein char-Array, das die Größe des Strings enthält
    // Daten senden
    esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *)message, sizeof(message) - 1); 
    
    canSend = false;
  }

}

ESP8266 Server Empfänger/Sender:

#include <ESP8266WiFi.h>
#include <espnow.h>
#include <ESP8266WebServer.h>
#include <ArduinoJson.h>
#include <Adafruit_NeoPixel.h> // NeoPixel Bibliothek
#include <EEPROM.h> // EEPROM für Speichern von Werten

//info: https://www.digikey.at/en/maker/tutorials/2024/how-to-implement-two-way-communication-in-esp-now
//#define DEBUG // Kommentiere diese Zeile aus, um Debugging-Ausgaben zu deaktivieren

const char* ssid = "LED_GATE_SERVER_01";           // SSID des Access Points
const char* password = "12345678";                  // Passwort des Access Points

const uint8_t senderIDs[][6] = {
  {0x3C, 0x84, 0x27, 0xAF, 0x19, 0x48}, // 3C:84:27:AF:19:48 von Sender 1
  // Fügen Sie weitere Sender-MAC-Adressen hinzu
};
uint8_t broadcastAddress[] = {0x3C, 0x84, 0x27, 0xAF, 0x19, 0x48};

int currentSenderIndex = 0;  // Aktueller Sender
int RESETINTERVAL = 50; // Intervall zwischen den Scans in Millisekunden

unsigned long previousMillis = 0; // speichert die Zeit des letzten Scans
unsigned long elapsedMillis = 0;  // speichert die verstrichene Zeit zwischen Scans
int currentIndex = 0; // Starte mit dem ersten ESP der Daten sendet

ESP8266WebServer server(80);

// Callback-Funktion für ESP-NOW-Sendebestätigung
void onDataSent(uint8_t *mac_addr, uint8_t status) {
  //#ifdef DEBUG
  Serial.print("Sende-Status: ");
  Serial.println(status == 0 ? "Erfolgreich" : "Fehlgeschlagen");

  Serial.print("Ziel-MAC-Adresse: ");
  for (int i = 0; i < 6; i++) {
    Serial.print(mac_addr[i], HEX);
    if (i < 5) {
      Serial.print(":");
    }
  }
  Serial.println();
  //#endif
}

// Callback-Funktion für den Empfang von ESP-NOW-Daten
void onDataRecv(uint8_t *mac, uint8_t *incomingData, uint8_t len) {
      // Print the MAC address of the sender
    Serial.print("Daten empfangen von: ");
    for (int i = 0; i < 6; i++) {
        Serial.printf("%02X", mac[i]);
        if (i < 5) Serial.print(":");
    }
    Serial.print(", Länge: ");
    Serial.println(len);

    // Check if the incoming data matches the expected length and content
    if (len == 8 && memcmp(incomingData, "SENDBACK", 8) == 0) {
        Serial.println("Befehl 'SENDBACK' empfangen. canSend auf true gesetzt.");
    } else {
        Serial.println("Unerwartete Daten empfangen.");
    }
}

// Funktion zur Initialisierung des WLAN-AP und des Webservers
void setupWiFiAndServer() {

  WiFi.mode(WIFI_AP_STA); // Ermöglicht AP und Station gleichzeitig
  WiFi.setSleepMode(WIFI_NONE_SLEEP);
  // AP-Modus starten
  WiFi.softAP(ssid, password);
  Serial.println("Access Point gestartet auf");

  // Station-Informationen ausgeben
  Serial.print("IP-Adresse: ");
  Serial.println(WiFi.softAPIP());
  Serial.print("Wi-Fi Channel: ");
  Serial.println(WiFi.channel());
  Serial.print("MAC-Adresse: ");
  Serial.println(WiFi.softAPmacAddress());

  // Access Point Informationen ausgeben
  Serial.print("Access Point IP Address: ");
  Serial.println(WiFi.softAPIP());
  Serial.print("Device MAC Address (AP): ");
  Serial.println(WiFi.softAPmacAddress());

  server.begin();
  Serial.println("Webserver gestartet");

}

void initESPNow() {
  if (esp_now_init() != 0) {   // Ersetzen Sie ESP_OK durch 0
    Serial.println("Fehler bei der Initialisierung von ESP-NOW");
    return;
  }

  esp_now_register_recv_cb(onDataRecv);
  esp_now_register_send_cb(onDataSent);
  esp_now_add_peer((uint8_t*)senderIDs[0], ESP_NOW_ROLE_COMBO, WiFi.channel(), NULL, 0);
  Serial.println("ESP-NOW erfolgreich initialisiert und bereit für Senden und Empfangen.");
}

void setup() {
  Serial.begin(115200);
  delay(6000);
  Serial.println("");
  // WLAN und Webserver einrichten
  setupWiFiAndServer();
  initESPNow();

  Serial.println("Warte auf ESP-NOW-Nachrichten...");

}

void loop() {
  // ESP-NOW arbeitet mit Callback, daher keine Logik im Haupt-Loop nötig
  server.handleClient(); // Clientanfragen bearbeiten
    // Überprüfen, ob das Intervall abgelaufen ist
  elapsedMillis = millis();
  if ((unsigned long)(elapsedMillis - previousMillis) >= (unsigned long)RESETINTERVAL) {
    // Nächsten Sender bestimmen
    currentSenderIndex = (currentSenderIndex + 1) % (sizeof(senderIDs) / sizeof(senderIDs[0]));
    previousMillis = elapsedMillis;
    
    // Token an aktuellen Sender senden
    // Casten Sie `senderIDs[currentSenderIndex]` und "SEND" zu `u8*`
    char message[] = "SEND"; // Dies ist ein char-Array, das die Größe des Strings enthält
    //int result = esp_now_send((uint8_t*)senderIDs[currentSenderIndex], (uint8_t *)message, sizeof(message) - 1); 
    int result = esp_now_send(broadcastAddress, (uint8_t *)message, sizeof(message) - 1); 
    Serial.println("esp_now_send " + String(result));
    Serial.print("Sender ");
    Serial.print(currentSenderIndex);
    Serial.println(" darf jetzt senden.");
  }
}

Your thread is in the english speaking forum.
So you should continue in english.

I haven't read your code. Did you register the peers on the other sending direction too?
I am not really familiar with ESP-NOW. But as registering peers must be done I guess it must be done on both sides for each and every participant in the ESP-NOW-communication

Oh sorry. It was in the morning :grin:.

Yes both sides have the peering. Its Different because one is esp32 the other one esp8266.
I have checked All the points several Times.

There are quite a few demo sketches where sending/receiving works in both directions.

You now have the choice between trying out your existing code at random
or taking a working demo sketch where sending/receiving works in both directions and adding the rest to the working demo code in small portions.

The smaller the number of lines you add before the next test,
the more precisely you will know what the problem is if it suddenly stops working.

The more lines, the more lines you have to search through and analyze
but only leave out some of them.

It just depends on what you enjoy more
The guessing game or systematic testing.

I cant find any example where an esp8266 is with a WiFi AP and an second esp32 is the Client and the a toway Communication. I only finde some with the Same esp type (the Syntax ist Different betwen both esps) and with WiFi AP i cant find any example, so i Do not know how to use a finished example which i can test. Because its Clear that this is the best way. But if i find no example its hard to Check without any changed.

This means
modifying an existing example starts at adding the WiFi-AP

Start with a demo-code that simply does send/receive ESP-NOW for ESP8266
and a code for ESP32 that does send / receive ESP-NOW.

If the only thing that happends is send/receive ESP-NOW this should work
If it works not second best to know that the "bug" is already inside this

start with broadcasting-adress which is mac-adress 0xFF:0xFF:0xFF:0xFF:0xFF:0xFF:

I try to build this example, but again it goes only in one direction and not back:

See Information/Error, but I google for it and also use chatgpt and do not realy get a solution for this. (it´s a step forward because I get an error/information, but maybe the same topic/similiar as in my own code)

in the Screenshot of the example there should come both lines send and recive.

I only find examples where people use 2 esp32 or two esp8266, which I do not have.

ESP32: (i get data received, but nothing is send back and I get a information)
E (10004) ESPNOW: Peer channel is not equal to the home channel, send fail!
Data received!
Counter: 3
X: 10000
Y: 1191391488.000000

//#include <ESP8266WebServer.h>
#ifdef ESP32
  // ESP32 Imports
  #include <WiFi.h>
  #include <esp_now.h>
  #include <esp_wifi.h>
#else
  // ESP8266 Imports
  #include <ESP8266WiFi.h>
  #include <espnow.h>
#endif

//info: https://www.digikey.at/en/maker/tutorials/2024/how-to-implement-two-way-communication-in-esp-now
//#define DEBUG // Kommentiere diese Zeile aus, um Debugging-Ausgaben zu deaktivieren

//const char* ssid = "LED_GATE_SERVER_01";           // SSID des Access Points
//const char* password = "12345678";                  // Passwort des Access Points

#define CHANNEL 4
#define UPDATE_DELAY 2500

#ifdef ESP32
  esp_now_peer_info_t peerInfo;
#endif

typedef struct SensorReadings {
    unsigned long counter;
    unsigned long x;
    float y;
} SensorReadings;


#ifdef ESP32
uint8_t destinationAddress[] = {0xEE, 0xFA, 0xBC, 0x12, 0xC7, 0x4F}; //esp32 mac
#else
uint8_t destinationAddress[] = {0x3C, 0x84, 0x27, 0xAF, 0x19, 0x48}; // ESP8266 mac
#endif

unsigned long lastUpdateMillis = 0UL;
unsigned long counter = 0UL;
bool dataReady = false;
SensorReadings receivedData;

#ifdef ESP32
  void onDataReceived(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
    memcpy(&receivedData, data, sizeof(receivedData));
    dataReady = true;
  }
#else
  void onDataReceived(uint8_t *mac_addr, uint8_t *data, uint8_t data_len) {
    memcpy(&receivedData, data, sizeof(receivedData));
    dataReady = true;
  }
#endif

#ifdef ESP32
  void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
    if (status == ESP_NOW_SEND_SUCCESS) {
      Serial.println("Data sent");
    }
  }
#else
  void onDataSent(uint8_t *mac_addr, uint8_t status) {
    if (status == 0) {
      Serial.println("Data sent");
    }
  }
#endif

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  esp_now_init();
#ifdef ESP32
  esp_now_register_recv_cb(onDataReceived);
  esp_now_register_send_cb(onDataSent);
  peerInfo.channel = CHANNEL;  
  peerInfo.encrypt = false;
  memcpy(peerInfo.peer_addr, destinationAddress, 6);
  esp_now_add_peer(&peerInfo);
#else
  esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
  esp_now_register_recv_cb(onDataReceived);
  esp_now_register_send_cb(onDataSent);
  esp_now_add_peer(destinationAddress, ESP_NOW_ROLE_COMBO, CHANNEL, NULL, 0);
#endif
}

void loop() {
  if (dataReady) {
    Serial.println("Data received!");
    Serial.printf("Counter: %d\n", receivedData.counter);
    Serial.printf("X:       %d\n", receivedData.x);
    Serial.printf("Y:       %f\n\n", receivedData.y);
    dataReady = false;
  }
  unsigned long currentMillis = millis();
  if (currentMillis - lastUpdateMillis >= UPDATE_DELAY) {
    SensorReadings outgoingData;
    outgoingData.counter = counter++;
    outgoingData.x = currentMillis;
    outgoingData.y = (float) rand();
    esp_now_send(destinationAddress, (uint8_t *) &outgoingData, sizeof(outgoingData));
    lastUpdateMillis = currentMillis;
  }
}

ESP8266: (i get Data Send, but nothing is comming back)

//#include <ESP8266WebServer.h>
#ifdef ESP32
  // ESP32 Imports
  #include <WiFi.h>
  #include <esp_now.h>
  #include <esp_wifi.h>
#else
  // ESP8266 Imports
  #include <ESP8266WiFi.h>
  #include <espnow.h>
#endif

//info: https://www.digikey.at/en/maker/tutorials/2024/how-to-implement-two-way-communication-in-esp-now
//#define DEBUG // Kommentiere diese Zeile aus, um Debugging-Ausgaben zu deaktivieren

//const char* ssid = "LED_GATE_SERVER_01";           // SSID des Access Points
//const char* password = "12345678";                  // Passwort des Access Points

#define CHANNEL 4
#define UPDATE_DELAY 2500

#ifdef ESP32
  esp_now_peer_info_t peerInfo;
#endif

typedef struct SensorReadings {
    unsigned long counter;
    unsigned long x;
    float y;
} SensorReadings;


#ifdef ESP32
uint8_t destinationAddress[] = {0xEE, 0xFA, 0xBC, 0x12, 0xC7, 0x4F}; //esp32 mac
#else
uint8_t destinationAddress[] = {0x3C, 0x84, 0x27, 0xAF, 0x19, 0x48}; // ESP8266 mac
#endif

unsigned long lastUpdateMillis = 0UL;
unsigned long counter = 0UL;
bool dataReady = false;
SensorReadings receivedData;

#ifdef ESP32
  void onDataReceived(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
    memcpy(&receivedData, data, sizeof(receivedData));
    dataReady = true;
  }
#else
  void onDataReceived(uint8_t *mac_addr, uint8_t *data, uint8_t data_len) {
    memcpy(&receivedData, data, sizeof(receivedData));
    dataReady = true;
  }
#endif

#ifdef ESP32
  void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
    if (status == ESP_NOW_SEND_SUCCESS) {
      Serial.println("Data sent");
    }
  }
#else
  void onDataSent(uint8_t *mac_addr, uint8_t status) {
    if (status == 0) {
      Serial.println("Data sent");
    }
  }
#endif

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  esp_now_init();
#ifdef ESP32
  esp_now_register_recv_cb(onDataReceived);
  esp_now_register_send_cb(onDataSent);
  peerInfo.channel = CHANNEL;  
  peerInfo.encrypt = false;
  memcpy(peerInfo.peer_addr, destinationAddress, 6);
  esp_now_add_peer(&peerInfo);
#else
  esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
  esp_now_register_recv_cb(onDataReceived);
  esp_now_register_send_cb(onDataSent);
  esp_now_add_peer(destinationAddress, ESP_NOW_ROLE_COMBO, CHANNEL, NULL, 0);
#endif
}

void loop() {
  if (dataReady) {
    Serial.println("Data received!");
    Serial.printf("Counter: %d\n", receivedData.counter);
    Serial.printf("X:       %d\n", receivedData.x);
    Serial.printf("Y:       %f\n\n", receivedData.y);
    dataReady = false;
  }
  unsigned long currentMillis = millis();
  if (currentMillis - lastUpdateMillis >= UPDATE_DELAY) {
    SensorReadings outgoingData;
    outgoingData.counter = counter++;
    outgoingData.x = currentMillis;
    outgoingData.y = (float) rand();
    esp_now_send(destinationAddress, (uint8_t *) &outgoingData, sizeof(outgoingData));
    lastUpdateMillis = currentMillis;
  }
}

So now I found a solution which works also with ap, but I have one point which is not working. If I set the server MAC, it´s not working it only works with global mac:
uint8_t broadcastAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // Broadcast-Adresse

But I want to have my MAC of the server because for my project I have somre more of the esps and I don´t want to broadcast to all. I want only to broadcast to special adresses.

i don´t understand why it only works with "global" mac adresse so broadcast to all.
I check my mac several times and its 100% the right mac what I write down.

This is the Code:

/*  Flow of the code

  1 - Put WiFi in STA Mode
  2 - Intialize ESPNOW
  3 - Add peer device
  4 - Define Send Callback Function
  5 - Define Receive Callback Function

*/

#include <esp_now.h>
#include <WiFi.h>
int CHANNEL = 1;
#define UPDATE_DELAY 2000
unsigned long lastUpdateMillis = 0UL;

// REPLACE WITH THE MAC Address of your receiver
//uint8_t broadcastAddress[] = {0xEE, 0xFA, 0xBC, 0x12, 0xC7, 0x4F}; // ESP8266 mac
uint8_t broadcastAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // Broadcast-Adresse
//Structure example to send data
//Must match the receiver structure
typedef struct struct_message {
    char msg[50];
} struct_message;

// Create a struct_message called outgoingReadings to hold outgoing data
struct_message outgoingReadings;

// Create a struct_message called incomingReadings to hold incoming data              
struct_message incomingReadings;

// Variable to store if sending data was successful
String success;
// Callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  Serial.print("Last Packet Send Status:");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}

// Callback when data is received
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len)
{
  memcpy(&incomingReadings, incomingData, sizeof(incomingReadings));
  Serial.print("Bytes received: ");
  Serial.println(len);
  Serial.print("Data: "); Serial.println(incomingReadings.msg);
}

void setup()
{
  // Init Serial Monitor
  Serial.begin(115200);
  Serial.println("Code start");

  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);
  delay(5000);               
  // MAC-Adresse ausgeben
  Serial.print("MAC-Adresse: ");
  Serial.println(WiFi.macAddress());

  // IP-Adresse ausgeben
  Serial.print("IP-Adresse: ");
  Serial.println(WiFi.localIP());

  // WLAN-Kanal ausgeben
  Serial.print("WLAN-Kanal: ");
  Serial.println(WiFi.channel());
  
  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }

  // Register peer
  /*esp_now_peer_info_t peerInfo;
  memset(&peerInfo, 0, sizeof(peerInfo));
  for (int ii = 0; ii < 6; ++ii )
  {
    peerInfo.peer_addr[ii] = (uint8_t) broadcastAddress[ii];
  }
  peerInfo.channel = CHANNEL;
  peerInfo.encrypt = false;*/

  esp_now_peer_info_t peerInfo;
  memcpy(peerInfo.peer_addr, broadcastAddress, 6);
  peerInfo.channel = CHANNEL;  
  peerInfo.encrypt = false;

  // Add peer
  if (esp_now_add_peer(&peerInfo) != ESP_OK) {
    Serial.println("Failed to add peer");
    return;
  }

  // Register for a callback function that will be called when data is received
  esp_now_register_recv_cb(OnDataRecv);

  // Once ESPNow is successfully Init, we will register for Send CB to
  // get the status of Trasnmitted packet
  esp_now_register_send_cb(OnDataSent);

}

void loop()
{

  unsigned long currentMillis = millis();
  if (currentMillis - lastUpdateMillis >= UPDATE_DELAY) {
    strcpy(outgoingReadings.msg, "Hello from ESP32");
    esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &outgoingReadings, sizeof(outgoingReadings));
    lastUpdateMillis = currentMillis;
  }

}

and:

/*
  Flow of the code

  1 - Put WiFi in STA Mode
  2 - Intialize ESPNOW
  3 - Set Role to Combo
  4 - Add peer device
  5 - Define Send Callback Function
  6 - Define Receive Callback Function
*/

#include <ESP8266WiFi.h>
#include <espnow.h>
int CHANNEL = 1;
#define UPDATE_DELAY 2500
unsigned long lastUpdateMillis = 0UL;

const char* ssid = "LED_GATE_SERVER_01";           // SSID des Access Points
const char* password = "12345678";                  // Passwort des Access Points

// REPLACE WITH THE MAC Address of your receiver
uint8_t broadcastAddress[] = {0x3C, 0x84, 0x27, 0xAF, 0x19, 0x48}; // ESP32 MAC
//Structure example to send data
//Must match the receiver structure
typedef struct struct_message {
  char msg[50];
} struct_message;

// Create a struct_message called outgoingReadings to hold outgoing data
struct_message outgoingReadings;

// Create a struct_message called incomingReadings to hold incoming data
struct_message incomingReadings;

// Variable to store if sending data was successful
String success;

// Callback when data is sent
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
  Serial.print("Last Packet Send Status: "); 
  if (sendStatus == 0) {
    Serial.println("Delivery success");
  }
  else {
    Serial.println("Delivery fail");
  }
}

// Callback when data is received
void OnDataRecv(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
  memcpy(&incomingReadings, incomingData, sizeof(incomingReadings));
  Serial.print("Bytes received: ");
  Serial.println(len);
  Serial.print("Data: "); Serial.println(incomingReadings.msg);
}


void setup() {
  // Init Serial Monitor
  Serial.begin(115200);
  Serial.println("Code start");                             

  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_AP_STA); // Ermöglicht AP und Station gleichzeitig
  WiFi.setSleepMode(WIFI_NONE_SLEEP);
  
  // AP-Modus starten
  WiFi.softAP(ssid, password);

  // MAC-Adresse ausgeben
  Serial.print("MAC-Adresse: ");
  Serial.println(WiFi.softAPmacAddress());

  // IP-Adresse ausgeben
  Serial.print("IP-Adresse: ");
  Serial.println(WiFi.softAPIP());

  // WLAN-Kanal ausgeben
  Serial.print("WLAN-Kanal: ");
  Serial.println(WiFi.channel());

  // Init ESP-NOW
  if (esp_now_init() != 0) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }

  // Set ESP-NOW Role
  esp_now_set_self_role(ESP_NOW_ROLE_COMBO);

  // Register peer
  esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, CHANNEL, NULL, 0);

  // Once ESPNow is successfully Init, we will register for Send CB to
  // get the status of Trasnmitted packet
  esp_now_register_send_cb(OnDataSent);

  // Register for a callback function that will be called when data is received
  esp_now_register_recv_cb(OnDataRecv);
}

void loop() {

  unsigned long currentMillis = millis();
  if (currentMillis - lastUpdateMillis >= UPDATE_DELAY) {
    strcpy(outgoingReadings.msg, "Hello from NodeMCU");
    esp_now_send(broadcastAddress, (uint8_t *) &outgoingReadings, sizeof(outgoingReadings));
    lastUpdateMillis = currentMillis;
  }
}

my code is now working but only with the general adresse not with the real mac. Do anybody have a solution for this.

here are all versions
without AP:

with AP:

dronegate:

what is so hard about using the

direct code-section-function

of this forum?

WHy does everybody have to look-up github and click to the code and then click again onto "show RAW-code" and then
manually

  • mark all
  • copy

when copying the complete sketch can be done with a

single mouseclick?

in the top-right corner of a code-section?