0

I would like to ask how to avoid the turn of the ESP8266/32 in case the door switch will be in the state closed? I am solving the situation when the doors are opened, the device is booted from the deep sleep and sending the HTTP request. But in case that door switch will be closed immediately (for example 1 sec) the device will be turned off without making the connection to wifi & sending request. See please attached scheme.

enter image description here

I tried it to do using digitalWrite(13, LOW); to given pins, but it does not help. Could You please give me somebody some link or idea how to solve it?

Many Thanks for any help.

bool doorPin = true;
String deviceID = "door_r_main";

void setup() {
  Serial.begin(115200);
  Serial.setTimeout(2000);
  // Wait for serial to initialize.
  while(!Serial) { }
  // SETUP PIN FOR DOOR MAGNETIC SENSOR 
  // https://diygeeks.org/learn/reed-door-lock-with-nodemcu/
  pinMode(13, INPUT_PULLUP);
  pinMode(12, OUTPUT);
  digitalWrite(12, LOW);
  // SETUP PIN FOR LED
  pinMode(LED_BUILTIN, OUTPUT);  
  Serial.println("I'm awake, ");
  blinkLed();
  getSwitchStatus();
  
}

void loop() {
}

void getSwitchStatus() {
    doorPin = digitalRead(13);
    Serial.println("PIN 13");
    Serial.println(doorPin);
    Serial.println("PIN 12");
    Serial.println(digitalRead(12));
    //TODO: AVOID THE TURN-OFF DEVICE WHEN THE DOOR SWITCH IS CLOSED
    while(doorPin == true) {
      Serial.println("Open");
      doorPin = digitalRead(13);
      digitalWrite(13, LOW);
      delay(1000);        
    }

    if (doorPin == false) {
      Serial.println("Close");
      digitalWrite(13, LOW);
      delay(1000);        
    }
    /*
    if (doorPin == true) {
      Serial.println("Open");
      digitalWrite(13, HIGH);
      digitalWrite(12, HIGH);
    }
    else {
      Serial.println("Close");
    }
    //doReportAlert(doorPin);
    ESP.deepSleep(0);
    */
}][1]][1]
  • ti.com/product/TPL5010 – jsotola Jun 20 at 20:12
  • don't use wifi, use esp-now (it can send out a message 200ms from power-on) and then have the reed switch control the actual power. With this, you get years of battery, actually the full shelf life if never used... – dandavis Jun 23 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.