I am building a ESP-07 based IOT device, that detects the status of 4 doors. The device must connect to WiFi and send an http request, when 1 of 4 doors is opened. I want to place a reed switch, for example on each door. The battery consumption should be minimal, so I thought of using deepsleep () or something similar to keep the device asleep most of the time, or keep it completely off (like most Dash buttons does).
I have studied several options, but almost all use a single GPIO to wake up the device. For example, this option wakes the device up if D3 goes high, and sleep if D3 is low. #include #include #define WAKE_PIN D3
const char* ssid = "SSID";
const char* pass = "PASSWORD";
extern "C" {
#include "gpio.h"
}
extern "C" {
#include "user_interface.h"
}
void setup(){
WiFi.begin(ssid, pass);
uint8_t i = 0;
while (WiFi.status() != WL_CONNECTED && i++ < 10) delay(250);
Serial.begin(115200);
Serial.println("Setup");
pinMode(WAKE_PIN, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
gpio_init(); // Initilise GPIO pins
}
void loop(){
Serial.println("Do something...");
if(!digitalRead(WAKE_PIN)){
sleep();
}
delay(1000);
}
void sleep(){
Serial.println("Going to sleep...");
delay(10);
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); // set sleep type
gpio_pin_wakeup_enable(GPIO_ID_PIN(WAKE_PIN), GPIO_PIN_INTR_HILEVEL);
wifi_fpm_open(); // Enables force sleep
wifi_fpm_do_sleep(0xFFFFFFF); // Sleep for longest possible time
delay(100);
Serial.println("Woke up!");
}
Here, GPIO_ID_PIN(2) corresponds to GPIO2 on ESP8266-01 , GPIO_PIN_INTR_LOLEVEL for a logic low, can also do other interrupts.
My question is:
Can I use more than one GPIO, that is, one of 4 GPIOs to wake up the device?
I have the problem of knowing which of the four doors has been opened!
The other option I have thought is to use a latch circuit that turns on the (previously turned off) device using a single GPIO. Something like this:
What I meant is that ESP-07 can latch its own power on (and off) using an MOSFET pair connected in parallel with the physical (momentary contact) power switch. When the power switch is pressed (or a door is opened), one of the first things the ESP8266 needs to do is latch the power on. When the current iteration of this programm is done, it simply turns it's own power off again.
#define POWER_SW 2 // GPIO connected to POWER_LATCH
void LatchOn() {
pinMode(POWER_SW, OUTPUT);
digitalWrite(POWER_SW, HIGH);
}
void LatchOff() {
digitalWrite(POWER_SW, LOW);
}
What I want to know is how I can use more than one signal from each of the 4 doors, or, use 4 GPIOs to activate the latch circuit. I tried with one single door connected to the GPIO that wakes the chip up. I want to extend the functionality of my program so that any of the 4 doors turns the chip on.
Thanks in advance!
P.S.
I have opened a thread about this topic in Arduino Forum as well.
-
1do you have the option of using a logic IC?ratchet freak– ratchet freak2018年01月17日 15:59:00 +00:00Commented Jan 17, 2018 at 15:59
-
Sounds good! Any ideas?Jose Alfredo Sanchez Diaz– Jose Alfredo Sanchez Diaz2018年01月17日 16:06:50 +00:00Commented Jan 17, 2018 at 16:06
-
1Idea: Wire the four door-GPIOs together with an OR gate, connect that to your wakeup pin, but still connect all door-GPIOs to 4 different GPIO pins on your ESP8266. When a wakeup is triggered (because ANY of the door GPIOs were triggered), read the state of the 4 door-GPIOs, act on it, then go back to sleep. You can use simple diode-ORs or CMOS (N)OR logic gates for this.Maximilian Gerhardt– Maximilian Gerhardt2018年01月17日 17:51:53 +00:00Commented Jan 17, 2018 at 17:51
-
1Also asked at stackoverflow.com/q/48279829per1234– per12342018年01月17日 19:55:12 +00:00Commented Jan 17, 2018 at 19:55
-
A friend from Arduino Forum told me that I can use a bunch of diodes to have all door switches trigger two pins: the shared wake-up pin, and a unique one for each switch. I have no idea how I could do that. Any idea of what a circuit with these characteristics would look like? Thanks in advance.Jose Alfredo Sanchez Diaz– Jose Alfredo Sanchez Diaz2018年01月18日 11:06:27 +00:00Commented Jan 18, 2018 at 11:06