Deep Sleep Mode / Interrupt for NodeMCU Amica ESP8266 HELP PLEASE :)

Hello everybody,

I´m currently struggling to get my NodeMCU ESP 8266 in Deep Sleep and to wake it up with an Interrupt. Currently, I can send it in sleep mode for a couple seconds, but I couldn´t interfere with one of my sensors so it would send data. :confused:

Problem: What do I have to write different in my code to enter deep sleep and wake up with an Interrupt.

my code:

#include <ESP8266WiFi.h>
String deviceId = "641";
String deviceIdE = "83B";
const char* logServer = "api.pushingbox.com";

const char* ssid = "ssid was correct";
const char* password = "password was correct";

String message; 

int vibPin = D1;
int vibState = 0;           

int vibEPin = D2;
int vibEState = 0;
int Fullstand = 0; 

void setup() {
 
 pinMode(vibPin, INPUT);
pinMode(vibEPin, INPUT);  
 // Serielle Kommunikation
  Serial.begin(74880);


}

void loop() {
 vibState = digitalRead(vibPin);
 vibEState = digitalRead(vibEPin);

if (vibState == LOW) {    
   Serial. println("Voll.");
   Serial.println("- connecting to Home Router SID: " + String(ssid));
 
 WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
 }
 WiFiClient client;
 if (client.connect(logServer, 80)) {   
   String postStr = "devid=";
   postStr += String(deviceId);
   postStr += "&message_parameter=";
   postStr += String(message);
   postStr += "\r\n\r\n";
   Serial.println("- sending data...");   
   client.print("POST /pushingbox HTTP/1.1\n");
   client.print("Host: api.pushingbox.com\n");
   client.print("Connection: close\n");
   client.print("Content-Type: application/x-www-form-urlencoded\n");
   client.print("Content-Length: ");
   client.print(postStr.length());
   client.print("\n\n");
   client.print(postStr);
 }
   delay(2000);
   Fullstand = 1; 
}

if ((vibEState == LOW)&&(Fullstand == 1)) {    //scheint alst Müsste Vibrationssensor immer LOW sein, zum Auslösen
   Serial. println("LEER");
   Serial.println("- connecting to Home Router SID: " + String(ssid));
 
 WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
 }
 WiFiClient client;
 if (client.connect(logServer, 80)) {   
   String postStr = "devid=";
   postStr += String(deviceIdE);
   postStr += "&message_parameter=";
   postStr += String(message);
   postStr += "\r\n\r\n";
   Serial.println("- sending data...");   
   client.print("POST /pushingbox HTTP/1.1\n");
   client.print("Host: api.pushingbox.com\n");
   client.print("Connection: close\n");
   client.print("Content-Type: application/x-www-form-urlencoded\n");
   client.print("Content-Length: ");
   client.print(postStr.length());
   client.print("\n\n");
   client.print(postStr);
 }
   delay(2000);
   Fullstand = 0;
}
ESP.deepSleep(10000000, WAKE_RF_DEFAULT);
delay(100);
Serial.print("Test");
}

Regarding Interrupt I do know this code line.

attachInterrupt(D0, wakeUpNow, LOW);

But it someone doesn´t really fit all together.
I used this sleep mode once for my arduino uno board,
but the NodeMCU Amica somehow doesn´t want to fall asleep with this code. :frowning:

void goToSleep(void) {    //dies wäre die SleepModus Funktiond
 ACSR |= _BV(ACD);
 ADCSRA &= ~_BV(ACD);
 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
 sleep_enable();
 cli();
 mcucr1 = MCUCR | _BV(BODS) |_BV(BODSE);
 mcucr2 = mcucr1 &~_BV(BODSE);
 MCUCR = mcucr1;
 MCUCR = mcucr2;
 sei();
 sleep_cpu();
 cli();
 sleep_disable();
 sei();
}   //Ende von Sleep Modus

Like you see, I did some Googelning but I am pretty know on the topic
and have some struggles. :smiley:

Well thanks for any advice
Patrick