A big thank you for your contribution. I modified the program according to your proposals. Everything is working. I am attaching you the pieces of code relating to the door contact.
My problem is solved.
.
.
.
attachInterrupt(digitalPinToInterrupt(DOOR_PIN), DoorMoving, CHANGE);
DoorChange = 1;
LastDoor = 0;
}
void DoorMoving() {
DoorChange = 1;
}
void readDoor() {
if (DoorChange) {
boolean Door = (digitalRead(DOOR_PIN));
if (Door != LastDoor) {
send(msgDoor.set((Door) == HIGH ? 1 : 0));
LastDoor = Door;
DoorChange = 0;
}
}
}
.
.
.
void loop() {
unsigned long currentMillis = millis();
readDoor();
if (currentMillis - previousMillis >= UPDATE_INTERVAL) {
previousMillis = currentMillis;
readDHT();
read1Wire();
}
}