Next stupid problem connecting to IOT Cloud

Ok I have a working script that was connected to my WiFi by using WiFi.h and were doin OTA updates all the time.

Then I did want to integrate OTA Cloud and to not mess my electronics up I beforehand did multiple testing with another board (Wemos D1 R1) which finally connected fine to IOT Cloud.

So I integrated all that stuff into my working script and uploaded it via OTA as before and the upload worked as before.

BUT after uploading my board didn't even connect to my WiFi anymore even with that code the 8266 (wemos) with that code perfectly did.

So basically I got no clue why its not connecting to my WiFi anymore.
I checked multiple times the wifi name as well as the WiFi password and They are correctly entered in the IOT and they were correctly in the secrets.h as well.

Any idea?

Here is the working code for the Wemos D1 I used for testing:

#include "arduino_secrets.h"
#include "thingProperties.h"
#include <ArduinoOTA.h>

#define OTA_Passwort "XXX"

void setup() {
  // Defined in thingProperties.h
  initProperties();

  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(14, OUTPUT);

  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED off
  digitalWrite(14, LOW);
  
  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  // OTA Update starten
  ArduinoOTA.setHostname("Testschloss");
  ArduinoOTA.setPassword(OTA_Passwort);
  ArduinoOTA.begin();
  ArduinoOTA.handle();  // OTA Update starten
}

void loop() {
  ArduinoOTA.handle();  // OTA Update starten
  ArduinoCloud.update();
}

void onDoorOnlineOpenChange()  {
  if (DoorOnlineOpen == 1) {
    Open();
  }
  DoorOpenOnlineLED = 0;
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED off
  digitalWrite(14, LOW);
}

void Open() {
  DoorOpenOnlineLED = 1;
  ArduinoCloud.update();
  digitalWrite(LED_BUILTIN, LOW);  // turn the LED on
  digitalWrite(14, HIGH);
  delay(3000);
}

And here the code for the ESP32 that I integrated it in (compiles and uploads into my device (DOIT ESP32 Devkit V1) fine:

/*  TODO:
    1) Online Variable Stromausfall
    2) Online Türöffnung



Anleitung: 

Startsequenz:
Power An - LED grün
Wlan verbunden - LED aus
Initialisiert und startklar - LED auf entsprechender Farbe

Delete Data: 
Beim Einschalten Türöffner Taste gedrückt halten oder...
AdminFinger draufhalten bis es rot blinkt, Finger entfernen. Alle Finger werden gelöscht und resettet. Danach wird sofort nach Neustart der Adminfinger zum einlesen angefordert (lila Blinken).

Add Fingerprint:
AdminFinger draufhalten bis es lila blinkt, Finger entfernen, neuen Fingerabdruck einlesen, Finger entfernen, erneut neuen Fingerabdruck einlesen. Bestätigung ist blaues waberndes Licht 
*/

#include "arduino_secrets.h"
#include "thingProperties.h"
#include <ArduinoOTA.h>
#include <HardwareSerial.h>
#include <Bounce2.h>
#include <AccelStepper.h>
#include <Adafruit_Fingerprint.h>
#include <DYPlayerArduino.h>
#include <EEPROM.h>

// Passwörter (WLAN etc.)
#define OTA_Passwort "XXX"

// Lautsprecher Lautstärke
#define Speaker_Volume 18  // 100% Lautstärke = 30
#define Sound_Random 1     // 0 = Sound wird der Reihenfolge nach abgespielt  1 = Sound wird zufällig abgespielt

//Alarmcounter
#define ACount 5  // Ab wievieltem Finger-Fehlversuch soll erstmalig Alarm ausgelöst werden (Reset durch erfolgreiche Türöffnung)

// Liste der Sounds
char *Sound[] = {
  "/Sound/1.mp3",  // AkteX
  "/Sound/2.mp3",
  "/Sound/3.mp3",
  "/Sound/4.mp3",
  "/Sound/5.wav",  // Wölfe
  "/Sound/6.mp3",
  "/Sound/7.mp3",
  "/Sound/8.mp3",
};
size_t Playlistsize = sizeof(Sound) / sizeof(Sound[0]);
int AktuellerSound = 0;

//Serielle Schnittstelle2 initialisieren
HardwareSerial SerialPort1(1);  // use UART1
HardwareSerial SerialPort2(2);  // use UART2

// Variablen Fingerprint Sensor
byte AlarmCount = 0;
uint8_t id;
byte FingerID = 0;
byte AdminFinger = 0;
void (*resetFunc)(void) = 0;  //declare reset function at address 0
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&SerialPort2);

// Variablen Schloss
const byte DoorOPENAlarm = 14;   // Reed Kontakt HIGH = Tür geöffnet, LOW = Tür geschlossen
const byte LockDoorSwitch = 22;  // LOW = Schnapper, HIGH = Doppelt verriegelt                                                  ??????????????????? stimmt???
const byte OpenDoorButton = 23;  // Taster zum Tür öffnen (innen) LOW = gedrückt

// Debounce objecte für Taster/Schalter initialisieren
Bounce DBDoorOPENAlarm = Bounce();
Bounce DBLockDoorSwitch = Bounce();
Bounce DBOpenDoorButton = Bounce();

// Variablen Motor
const bool EEpromOn = 0;  // Soll Stromausfall während Bewegung detektiert werden? Achtung nur ca 10.000 Zyklen möglich! 0=AUS 1=AN

const byte MicroSteps = 4;                  // Eingestellte Microsteps am Stepper Controller
const byte MotorSteps = 200;                // 200 Hardware-Steps per Umdrehung des Motors
const int Steps = MotorSteps * MicroSteps;  // Gesamte reelle Steps Pro Umdrehung

const byte StepPin = 18;
const byte DirPin = 5;
const byte ENPin = 19;

#define Zahnradfaktor 3                                // 20 Zähne auf 60 Zähne übersetzt am GT2 Riemen = Faktor 3
const int Verriegeln = 2 * Steps * Zahnradfaktor;      // Anzahl Umdrehungen zum Verriegeln (aus Nullstellung des Schlüssels)    (alles negativ,da 2 Zahnräder die Richtung imvertieren!)
const int Oeffnen = -68 * MicroSteps * Zahnradfaktor;  // Anzahl Motorsteps * MicroSteps zum öffnen des Schnappers (aus Nullstellung des Schlüssels)       //////////////////////// NOCH ANPASSEN !!!!!!

AccelStepper Motor(1, StepPin, DirPin);  // AccelStepper Objekt Motor erstellen 1= Motortreiber verwenden

// Schlüsselpositionen
#define Nullstellung 0
#define Verriegelt 1
bool SchluesselPos = Nullstellung;  // 0=Schlüssel Nullstellung (Schnapper zu), 1=Schlüssel verriegelt

// Variablen LED
const byte LEDRed = 27;
const byte LEDGreen = 26;

// Musik initialisieren
DY::Player Music(&SerialPort1);  // Initialise the player on UART1, pins TX: 33, RX: 25.



void setup() {
  initProperties();  // Defined in thingProperties.h

  // LEDs initialisieren
  pinMode(LEDRed, OUTPUT);
  pinMode(LEDGreen, OUTPUT);
  digitalWrite(LEDRed, HIGH);    // HIGH = AUS
  digitalWrite(LEDGreen, HIGH);  // HIGH = AUS

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  digitalWrite(LEDGreen, LOW);  // LED auf Grün wenn WLAN steht

  // OTA Update einrichten
  ArduinoOTA.setHostname("Tuerschloss");
  ArduinoOTA.setPassword(OTA_Passwort);
  ArduinoOTA.begin();
  ArduinoOTA.handle();  // OTA Update starten

  // Serielle Schnittstellen initialisieren
  Serial.begin(115200);                          // Serielle Ausgabe an
  SerialPort1.begin(9600, SERIAL_8N1, 33, 25);   // Serielle Schnittstelle 1 für Audio an
  SerialPort2.begin(57600, SERIAL_8N1, 16, 17);  // Serielle Schnittstelle 2 für Fingerprint Sensor an
  delay(1000);                                   // 1 Sek warten auf Schnittstelle

  // Sound initialisieren
  Music.begin();
  delay(100);                                // Delay notwendig, damit Lautstärkeeinstellung funktioniert
  Music.setVolume(Speaker_Volume);           // Oben definiert bei define
  Music.setCycleMode(DY::PlayMode::OneOff);  // File einmal abspielen, dann stop

  // Taster uns Schalter initialisieren
  DBDoorOPENAlarm.attach(DoorOPENAlarm, INPUT_PULLUP);  // 0 = Tür geschlossen, 1 = Tür offen
  DBDoorOPENAlarm.interval(5);
  DBLockDoorSwitch.attach(LockDoorSwitch, INPUT_PULLUP);  // 0 = Schalter Position                                ????????????????????????????? stimmt?
  DBLockDoorSwitch.interval(5);
  DBOpenDoorButton.attach(OpenDoorButton, INPUT_PULLUP);  // 0 = Taster gedrückt
  DBOpenDoorButton.interval(5);

  FingerprintSetup();  // Fingerprint Sensor initialisieren

  // Falls beim Einschalten Open-Taste gedrückt gehalten wird Fingerprint-Reset durchführen und per LED anzeigen.
  DBOpenDoorButton.update();            // Auslesen mit "!DBOpenDoorButton.read()" (INVERTIERT! Dann 1 = gedrückt)
  if (!DBOpenDoorButton.read() == 1) {  // HIGH = Taste gedrückt
    for (int i = 0; i <= 20; i++) {
      digitalWrite(LEDGreen, 0);  // LED grün AUS
      digitalWrite(LEDRed, 1);    // LED rot An
      delay(150);
      digitalWrite(LEDGreen, 1);  // LED grün AN
      digitalWrite(LEDRed, 0);    // LED rot AUS
      delay(150);
    }
    deletedata();
  }

  ////////////////////////////////////////////////////////////////////////////////////////////// STROM-AUS VARIABLE ONLINE prüfen!

  // Falls EEprom aktiv, initialisieren, einlesen und auf Stromausfall prüfen
  if (EEpromOn == 1) {
    EEPROM.begin(4);  // EEprom initialisieren 4 Byte lang (minimum)
    // Für EEPROM resett nach Stromausfall Kommentar dieser 2 Zeilen einmalig entfernen
    /* 
    EEPROM.write(0, 255);  // Zum Schluss EEprom wieder auf 255 setzen
     EEPROM.commit();
    */
    if (EEPROM.read(0) == 0) {
      Error();  // EEprom war auf 0 also Stromausfall während Bewegung (Position unsicher, abschalten!)
    }
  }

  // Motorvariablen initialisieren
  pinMode(StepPin, OUTPUT);
  pinMode(DirPin, OUTPUT);
  pinMode(ENPin, OUTPUT);

  Motor.setEnablePin(ENPin);
  Motor.setMaxSpeed(6000);                    // 6000-8000 (max. ca. 8000) [war 6000]
  Motor.setAcceleration(2000);                // 1000 Steps/Sek = 1 Sek bis volle Geschwindigkeit. 4000 = 1/4 Sek [war 4000]
  Motor.setPinsInverted(false, false, true);  // Enable muss low sein um an zu sein
}



void loop() {
  ArduinoOTA.handle();  // OTA Update starten
  ArduinoCloud.update();

  DBLockDoorSwitch.update();              // Auslesen mit "!DBLockDoorSwitch.read()" (INVERTIERT! Dann 1= Schalter auf AN)
  if (!DBLockDoorSwitch.read() == 0) {    // Wenn Schalter auf Schnapper steht
    if (SchluesselPos == Nullstellung) {  // Falls schon auf Nullstellung
      digitalWrite(LEDRed, LOW);          // LED auf gelb
      digitalWrite(LEDGreen, LOW);
    } else if (SchluesselPos == Verriegelt) {  // Falls verriegelt entriegeln und LED auf gelb
      Serial.println("MOTOR AN");
      Motor.enableOutputs();
      Motor.runToNewPosition(Nullstellung);
      Motor.disableOutputs();
      Serial.println("MOTOR AUS");
      SchluesselPos = Nullstellung;
      digitalWrite(LEDRed, LOW);  // LED auf gelb
      digitalWrite(LEDGreen, LOW);
    }
  } else if (!DBLockDoorSwitch.read() == 1) {
    if (SchluesselPos == Verriegelt) {  // Falls schon verriegelt
      digitalWrite(LEDRed, LOW);        // LED auf rot
      digitalWrite(LEDGreen, HIGH);
    } else if (SchluesselPos == Nullstellung) {  // Falls noch auf Nullstellung und verriegeln eingestellt, auf eingestellte Position fahren
      Serial.println("MOTOR AN");
      Motor.enableOutputs();
      Motor.runToNewPosition(Verriegeln);
      Motor.disableOutputs();
      Serial.println("MOTOR AUS");
      SchluesselPos = Verriegelt;
      digitalWrite(LEDRed, LOW);  // LED auf rot
      digitalWrite(LEDGreen, HIGH);
    }
  }

  DBOpenDoorButton.update();  // Auslesen mit "!DBOpenDoorButton.read()" (INVERTIERT! Dann 1 = Öffnen)
  if (!DBOpenDoorButton.read() == 1) {
    DoorOpen();
    DBOpenDoorButton.update();  // Nach DoorOpen() Nochmal updaten ansonsten fährt er 2x durch DoorOpen()
  }

  // START FINGERPRINT SENSOR LOOP
  getFingerprintID();  // Check Fingerprint
  Checkfinger();       // Entsprechend erkanntem Print handeln
}



void FingerprintSetup() {
  Serial.println("\n\nFinger detect test");
  finger.begin(57600);  // set the data rate for the sensor serial port
  delay(5);

  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor!");
    Error();
  }

  // LEDs aus falls noch an
  finger.LEDcontrol(FINGERPRINT_LED_OFF, 0, FINGERPRINT_LED_BLUE);
  finger.LEDcontrol(FINGERPRINT_LED_OFF, 0, FINGERPRINT_LED_RED);
  finger.LEDcontrol(FINGERPRINT_LED_OFF, 0, FINGERPRINT_LED_PURPLE);

  // Einschaltsignal 10x15ms blau
  finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 15, FINGERPRINT_LED_BLUE, 10);

  Serial.println(F("Reading sensor parameters"));
  finger.getParameters();
  Serial.print(F("Status: 0x"));
  Serial.println(finger.status_reg, HEX);
  Serial.print(F("Sys ID: 0x"));
  Serial.println(finger.system_id, HEX);
  Serial.print(F("Capacity: "));
  Serial.println(finger.capacity);
  Serial.print(F("Security level: "));
  Serial.println(finger.security_level);
  Serial.print(F("Device address: "));
  Serial.println(finger.device_addr, HEX);
  Serial.print(F("Packet len: "));
  Serial.println(finger.packet_len);
  Serial.print(F("Baud rate: "));
  Serial.println(finger.baud_rate);

  finger.getTemplateCount();

  if (finger.templateCount == 0) {
    Serial.print("Sensor doesn't contain any fingerprint Going to run 'enroll.");
    finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 100, FINGERPRINT_LED_RED, 50);
    delay(5000);
    finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_RED, 0);
    newfingerprint();
  } else {
    Serial.println("Waiting for valid finger...");
    Serial.print("Sensor contains ");
    Serial.print(finger.templateCount);
    Serial.println(" templates");
  }
}

uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      FingerID = 0;
      AdminFinger = 0;
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
  // fingerprint read ok

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
  // fingerprint converted ok

  p = finger.fingerSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_RED, 10);
    AlarmCount += 1;             // Falscher Finger = AlarmCounter hochzählen
    if (AlarmCount >= ACount) {  // wenn Counter > Schwelle Alarm auslösen
      Music.setVolume(25);
      Music.playSpecifiedDevicePath(DY::Device::Sd, "/Alarm/Alarm.mp3");
      Music.setVolume(Speaker_Volume);
    }
    delay(1500);  // Delay 1,5 Sek, damit Finger nicht mehrfach erkannt wird
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  // found a match!
  Serial.print("Found ID #");
  Serial.print(finger.fingerID);
  Serial.print(" with confidence of ");
  Serial.println(finger.confidence);

  FingerID = finger.fingerID;

  return finger.fingerID;
}

// Add new fingerprint
void newfingerprint()  // run over and over again
{
  finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_PURPLE, 0);
  Serial.println("Ready to enroll a fingerprint!");
  Serial.println("Id will be given in order First finger print is Admin");
  finger.getTemplateCount();
  Serial.print("Sensor contains ");
  Serial.println(finger.templateCount);

  id = (finger.templateCount + 1);

  if (id == 0) {  // ID #0 not allowed, try again!
    Serial.println("first run setting id to 1");
    id = 1;
    return;
  }
  Serial.print("Enrolling ID #");
  Serial.println(id);

  while (!getFingerprintEnroll())
    ;
}

uint8_t getFingerprintEnroll() {

  int s = -1;
  Serial.print("Waiting for valid finger to enroll as #");
  Serial.println(id);

  finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_PURPLE, 0);
  while (s != FINGERPRINT_OK) {
    ArduinoOTA.handle();  // OTA Update starten während auf Finger getestet wird
    s = finger.getImage();
    switch (s) {
      case FINGERPRINT_OK:
        Serial.println("Image taken");
        finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_PURPLE, 1);
        delay(2000);
        break;
      case FINGERPRINT_NOFINGER:
        break;
      case FINGERPRINT_PACKETRECIEVEERR:
        Serial.println("Communication error");
        break;
      case FINGERPRINT_IMAGEFAIL:
        Serial.println("Imaging error");
        break;
      default:
        Serial.println("Unknown error");
        break;
    }
  }

  // OK success!

  s = finger.image2Tz(1);
  switch (s) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return s;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return s;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return s;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return s;
    default:
      Serial.println("Unknown error");
      return s;
  }

  // Cherck if Finger already exists in Database and skip if so
  s = finger.fingerSearch();
  if (s == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find an existing match");
  } else if (s == FINGERPRINT_OK) {
    Serial.print("Found ID #");
    Serial.println(finger.fingerID);
    Serial.println("Known Fingerprint detected, skipping");
    finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 30, FINGERPRINT_LED_RED, 5);
    delay(2000);
    return s;
  }  // End of Check

  Serial.println("Remove finger");
  finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_BLUE, 0);
  s = 0;
  while (s != FINGERPRINT_NOFINGER) {
    s = finger.getImage();
  }
  Serial.print("ID ");
  Serial.println(id);
  s = -1;
  Serial.println("Place same finger again");
  finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_PURPLE, 0);
  while (s != FINGERPRINT_OK) {
    s = finger.getImage();
    switch (s) {
      case FINGERPRINT_OK:
        Serial.println("Image taken");
        finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_PURPLE, 1);
        break;
      case FINGERPRINT_NOFINGER:
        break;
      case FINGERPRINT_PACKETRECIEVEERR:
        Serial.println("Communication error");
        break;
      case FINGERPRINT_IMAGEFAIL:
        Serial.println("Imaging error");
        break;
      default:
        Serial.println("Unknown error");
        break;
    }
  }

  // OK success!

  s = finger.image2Tz(2);
  switch (s) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return s;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return s;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return s;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return s;
    default:
      Serial.println("Unknown error");
      return s;
  }

  // OK converted!
  Serial.print("Creating model for #");
  Serial.println(id);

  s = finger.createModel();
  if (s == FINGERPRINT_OK) {
    Serial.println("Prints matched!");
  } else if (s == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return s;
  } else if (s == FINGERPRINT_ENROLLMISMATCH) {
    Serial.println("Fingerprints did not match");
    newfingerprint();
    // return s;
  } else {
    Serial.println("Unknown error");
    return s;
  }

  Serial.print("ID ");
  Serial.println(id);
  s = finger.storeModel(id);
  if (s == FINGERPRINT_OK) {
    Serial.println("Stored!");

    finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_BLUE, 20);
    finger.LEDcontrol(FINGERPRINT_LED_GRADUAL_ON, 200, FINGERPRINT_LED_BLUE);
    delay(2000);
    finger.LEDcontrol(FINGERPRINT_LED_GRADUAL_OFF, 200, FINGERPRINT_LED_BLUE);
    delay(2000);
    finger.LEDcontrol(FINGERPRINT_LED_GRADUAL_ON, 200, FINGERPRINT_LED_BLUE);
    delay(2000);
    finger.LEDcontrol(FINGERPRINT_LED_GRADUAL_OFF, 200, FINGERPRINT_LED_BLUE);
    delay(2000);

  } else if (s == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return s;
  } else if (s == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not store in that location");
    return s;
  } else if (s == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return s;
  } else {
    Serial.println("Unknown error");
    return s;
  }
  return true;
}

void deletedata() {
  finger.emptyDatabase();
  Serial.println("All fingerprints Deleted");
  finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 5, FINGERPRINT_LED_RED, 0);
  Serial.println("Doing a soft reset of the arduino");
  resetFunc();  //call reset
}

void Checkfinger() {
  if (FingerID == 1) {  // Adminfinger erkannt
    Serial.println("Admin Fingerprint detected");
    AlarmCount = 0;  // Alarmcounter zurücksetzen
    AdminFinger = (AdminFinger + 1);
    finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_BLUE, 1);
    if (AdminFinger == 5) {
      finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_PURPLE);
      delay(1000);
      getFingerprintID();
      if (FingerID == 0) {
        Serial.println("ADD NEW USER");
        newfingerprint();
      }
    }
    if (AdminFinger >= 10) {
      finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_RED);
      delay(1000);
      getFingerprintID();   // Prüfen ob Finger losgelassen
      if (FingerID == 1) {  // Wenn nicht, löschen und Reset
        Serial.println("DELETE ALL USERS");
        deletedata();
      }
      Serial.println("Doing a soft reset of the arduino");
      resetFunc();  //call reset
    }
  } else if (FingerID != 0) {
    Serial.println("Normal fingerprint detected");
    finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_BLUE, 5);
    DoorOpen();
  }
}

void DoorOpen() {
  if (EEpromOn == 1) {   // Falls EEpromON Variable gesetzt
    EEPROM.write(0, 0);  // Vor Beginn EEprom auf 0 setzen (Stromausfallerkennung)
    EEPROM.commit();
    Serial.print("EEprom: ");
    Serial.println(EEPROM.read(0));
  }

  /////////////////////////////////////////////////////////////////////////////////////////// STROM-AUS VARIABLE ONLINE SPEICHERN!

  AlarmCount = 0;  // Alarmcounter zurücksetzen, da Tür erfolgreich geöffnet wurde
  Serial.println("MOTOR AN");
  Motor.enableOutputs();
  Serial.println("MOTOR öffnet");
  Motor.runToNewPosition(Oeffnen);
  digitalWrite(LEDRed, HIGH);  // LED auf grün
  digitalWrite(LEDGreen, LOW);
  finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_BLUE);  // Fingerprint LED AN

  while (DBDoorOPENAlarm.read() == 0) {  // Warten bis Tür geöffnet wurde
    DBDoorOPENAlarm.update();
    //////////////////////////////////////// Ggf. Zeit einfügen nach der autom. verriegelt wird
  }

  Music.playSpecifiedDevicePath(DY::Device::Sd, Sound[AktuellerSound]);  // Titel abspielen
  if (Sound_Random == 0) {                                               // Wenn Sound nach Playlist abspielt
    if (AktuellerSound == (Playlistsize - 1)) {                          // Wenn letzter Sound der Liste gerade gespielt wurde, wieder zum ersten springen, ansonsten zum nächsten in der Liste spulen
      AktuellerSound = 0;
    } else {
      AktuellerSound += 1;
    }
  } else if (Sound_Random == 1) {  // Wenn Sound zufällig ausgewählt abspielt
    AktuellerSound = random(0, (Playlistsize - 1));
    Serial.print("Nächster Sound ist Playlist Nr: ");
    Serial.println(AktuellerSound);
  }

  Serial.println("MOTOR Fährt auf Schnapper");
  Motor.runToNewPosition(Nullstellung);  // Sobald Tür geöffnet wurde Schnapper freigeben
  SchluesselPos = Nullstellung;
  finger.LEDcontrol(FINGERPRINT_LED_OFF, 0, FINGERPRINT_LED_BLUE);
  digitalWrite(LEDRed, LOW);  // LED auf gelb
  digitalWrite(LEDGreen, LOW);

  while (DBDoorOPENAlarm.read() == 1) {
    DBDoorOPENAlarm.update();  // Warten bis Tür geschlossen wurde
  }

  DBLockDoorSwitch.update();  // Auslesen mit "!DBLockDoorSwitch.read()" (INVERTIERT! Dann 1= Schalter auf AN)
  if (!DBLockDoorSwitch.read() == 1) {
    delay(500);  // Sicherheitshalber delay damit Tür auch ganz zu ehe verschlossen wird
    Serial.println("MOTOR verriegelt da eingestellt");
    Motor.runToNewPosition(Verriegeln);  // Falls verriegeln eingestellt, auf eingestellte Position fahren
    SchluesselPos = Verriegelt;
    digitalWrite(LEDRed, LOW);  // LED auf rot
    digitalWrite(LEDGreen, HIGH);
    DoorOpenOnlineLED = 0;  // Online LED aus
    ArduinoCloud.update();  // Online Daten updaten
  }

  Music.stop();  // Musik stoppen (sobald Tür zu)

  Serial.println("MOTOR AUS");
  Motor.disableOutputs();

  /////////////////////////////////////////////////////////////////////////////////////////// STROM-AUS VARIABLE ONLINE ZURÜCKSETZEN

  if (EEpromOn == 1) {     // Falls EEpromON Variable gesetzt
    EEPROM.write(0, 255);  // Zum Schluss EEprom wieder auf 255 setzen
    EEPROM.commit();
    Serial.print("EEprom: ");
    Serial.println(EEPROM.read(0));
  }
  return;
}

void onDoorOnlineOpenChange() {
  if (DoorOnlineOpen == 1) {
    DoorOpenOnlineLED = 1;  // Online LED an
    ArduinoCloud.update();  // Online Daten updaten
    DoorOpen();
  }
}

void Error() {
  Serial.println("FEHLER! MOTOR AUS, LED AN, PROGRAMMENDE BIS RESET!");
  finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_RED);
  Motor.disableOutputs();
  digitalWrite(LEDGreen, HIGH);  // grüne LED aus
  digitalWrite(LEDRed, LOW);     // LED rot an
  while (1) {                    // LED rot blinken
    delay(180);
    digitalWrite(LEDRed, !digitalRead(LEDRed));  // LED rot invertieren (blinken)
    ArduinoOTA.handle();                         // OTA Update starten
  }
}

And just to make clear it doesn't connect to my WiFi even the Wenos testboard does perfectly and it did also using WiFi.h to connect before.

I can clearly see in my WiFi router its not connected and before I integrated the code that worked on the Wemos it was.

So why doesn't it even get connected to my WIFi any more?

AND....
By now I removed the board from my electronics and got it laying besides my PC.

Also I did remove the device in the cloud and set it up new but as said its not even connecting to my WiFi anymore.

Are you positive Iot and OTA work together? I would make a small wager they do not.
I do not like using the cloud editor and the IDE editor being used on a cloud project, too much happens automatically in the cloud, and I have seen code overwritten.

Yes they do work together I tried it before.
I could connect and. Use IOT and the same time I could OTA upload on the Wemos D1.

But that's completely irrelevant because tje problem is before that.

It doesn't even connect to my WoFi router foe some reason.

Before I changed to that "connectionhandler" I used wofi.h and it connected perfectly.

It also did woth the testboard.

But foe some reason the ESP32 won't connect.

Hello, having a step back:
the Arduino IoT Cloud supports out-of-the box OTA (here some docs) and the lib is already embedded in the ArduinoIoTCloud lib so you should not handle the ArduinoOTA lib directly in the sketch.
I suggest you to remove the ArduinoOTA from the sketch and let the Arduino IoT Cloud manages all the stuff for you.
So you will be able to have OTA directly from the Cloud Editor.

1 Like

As I said multiple times ITS NOT CONNECTING TO MY WIFI so that's no problem with the Cloud.

And no the cloud doesn't handle OTA since I use an ESP32 where the cloud shows "OTA not supported" therefore I need to use the way Idid it before.

Bye.

And here is a screenshot from the official link that you have been pointed to.

Your board in on the official docs.
I suggest you take the advice previously given along with my own, to start afresh and follow the setup procedure given on the page link supplied. The developers of the ArduinoIotCloud interface (as I see it) have gone above and beyond to create something that a complete novice could follow. Everything is automated for you including sketch creation. ArduinoOTA and WiFi is all handled under the hood, so no need for the user to add it to the sketch.

1 Like

Sorry was busy the last days.

Ok, will read that docs and see if there's the solution for my problem.
But

  1. I did set up that board about maybe around 10 times by now (starting last year) and I always get the notice in the IOT that OTA is not supported.
    Will see if I can find the reason in that docs but until now I cant see a reason whyt I should have done wrongly.

  2. I tried this code to connect before and it worked perfectly on my Wemos D1. WITH AS WELL AS WITHOUT that lines for manual OTA.

And this is the most IMPORTANT:

  1. The board won't even connect to my WiFi so basically sure it can't connect to IOT if it does not even connect to the network here.

But I this night had an idea what maybe the reason...
EDIT: ---- It wasnt the reason as I just tested.

And another Edit:
Just to mention its not defective if I upload my old code without IOT it perfectly connects to my WiFi.

Hi @Gorkde.

Are you sure you were using a Thing that was associated with the Device for the ESP32-based board when you saw that message?

As was explained already by @indev2, Arduino Cloud OTA is supported for the ESP32-based boards, so it is unexpected that you would see the "OTA upload not supported" message when using a thing that is associated with a Device for an ESP32-based board.

However, Arduino Cloud OTA is not supported for the ESP8266-based boards like your Wemos D1 R1, so it is expected that you will see this message while using a Thing that is associated with a Device for the Wemos D1 R1 board (which uses an ESP8266 microcontroller).

I'm pretty sure. Will see to get screenshots once I've got time, probably tomorrow.

Any Idea why it doesn't connect to my wifi?

Sorry again today got to look that up and had few free moments.
Here is the schreenshot and a photo of the device.

Device;

Chip:

IOT Display:

To install the device to IOT I connected it by USB to my PC.

But as I said it will not connect to my WiFi with my old code but it wont even connect to my WiFi with the new IOT code.

I see now. This is a bit confusing. The "OTA Updates" section of the "Device" page is showing you a log of the OTA uploads you have performed for that Device. The "No OTA available for this device" message shown under the "OTA Updates" section is only intended to communicate that you haven't made any OTA uploads to that device, so there is no data to show.

The message does not mean that OTA is not supported for the device.

Ok, what do you suggest I should do now?
Basically I can see the device isn't even connected to my wifi therfore surely it can't connect to IOT.

With my old code before I tried to implement IOT (using wifi.h) it connected perfectly to my wifi.

If you want to switch to using Arduino Cloud OTA, then you can remove the ArduinoOTA library code from your sketch as it would no longer be needed.

If you want to continue to use the ArduinoOTA library to allow network port uploads using Arduino IDE, then you need to configure your sketch so that it completes the Wi-Fi initialization before you call ArduinoOTA.begin:

The ArduinoIoTCloud library has an asynchronous design, where ArduinoCloud.begin will return immediately after setting a flag that instructs the library to start connecting, but without actually initializing the Wi-Fi. If you call ArduinoOTA.begin before the Wi-Fi is initialized, it causes a crash. This is the reason why your Thing never connected.

The actual Wi-Fi initialization operations are performed each time you call ArduinoCloud.update:

If you look at the ArduinoOTA library's "BasicOTA" example, you will see that it actually makes sure that the Wi-Fi has been initialized before calling ArduinoOTA.begin:

So you need to do something equivalent in your sketch. I was able to get it working with this adjustment:

  // Initiate connection to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  // OTA Update starten
  ArduinoOTA.setHostname("Testschloss");
  ArduinoOTA.setPassword(OTA_Passwort);

  // Wait for Wi-Fi initialization.
  while(!ArduinoCloud.connected()){
    ArduinoCloud.update();  
  }

  // Only call ArduinoOTA.begin after the Wi-Fi has been initialized!
  ArduinoOTA.begin();

Thanks for the help.

I could not access anything lately since I had random crashes since years and never found out the reason.
I until lately just was sure it's a hardware problem.

Finally my PC always crashed before windows was booted and finally it stopped working completely and just gabe bios beeps.

Since I then knew the graphics card was the reason I inspected it under my microscope and finally unscrewed the heat sink.

The heat sink paste wasn't only hardened because of age it also nearly touched the capacitors. So I completely removed it and put new paste on.

Since then my PC finally works again without any problems.

I did plan to resume my work on this topic this afternoon.

Will give feedback afterwards.

The ESP32 might be trying to start OTA and cloud before WiFi is up. Add a short delay at the beginning of setup():

delay(1000);  // Give time for power-up stabilization

Ok I found time to look today.

Formerly I used Wifi.h to connect to WiFi before OTA and it worked perfectly.

But then I removed my former connection method from my script because I added the Arduino IOT code.

I tested it (on another board) by using this testscript (I took that code from the connection handler library example mostly):

#include <Arduino_ConnectionHandler.h>

WiFiConnectionHandler conMan("SSID", "PASS");

void setup() {
  Serial.begin(921600);
  while (!Serial) {}

  pinMode(LED_BUILTIN, OUTPUT);

  setDebugMessageLevel(DBG_INFO);

  conMan.addCallback(NetworkConnectionEvent::CONNECTED, onNetworkConnect);
  conMan.addCallback(NetworkConnectionEvent::DISCONNECTED, onNetworkDisconnect);
  conMan.addCallback(NetworkConnectionEvent::ERROR, onNetworkError);
}

void loop() {
  conMan.check();

  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(100);                       
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(100);                       
}

void onNetworkConnect() {
  Serial.println(">>>> CONNECTED to network");
}

void onNetworkDisconnect() {
  Serial.println(">>>> DISCONNECTED from network");
}

void onNetworkError() {
  Serial.println(">>>> ERROR");
}

It worked connecting to WiFi and figured out it basically is only a more specific form of

ArduinoCloud.begin(ArduinoIoTPreferredConnection);

where parts of it were in the secret file and the properties file. And it therefore basically should do the same and it was used in the arduino IOT code so I used that from then on but didn't get a connection to my WiFi anymore.