Dear everybody,
I want to control a pump via alexa and an esp8266 (plus relais). The problem I have is that I just wanna switch on the pump for a small time 5s therefore I need to insert a delay for my GPIO somehow The Code i use looksas followed:
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "fauxmoESP.h"
#define WIFI_SSID ""//change your Wifi name
#define WIFI_PASS "**"//Change your Wifi Password
#define SERIAL_BAUDRATE 115200
fauxmoESP fauxmo;
//declare switching pins
//Change pins according to your NodeMCU pinouts
#define Kitchen D1
#define Bedroom D2
#define Living D3
// -----------------------------------------------------------------------------
// Wifi Setup
// -----------------------------------------------------------------------------
void wifiSetup() {
// Set WIFI module to STA mode
WiFi.mode(WIFI_STA);
// Connect
Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASS);
// Wait
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(100);
}
Serial.println();
// Connected!
Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
}
// -----------------------------------------------------------------------------
// Device Callback
// -----------------------------------------------------------------------------
void callback(uint8_t device_id, const char * device_name, bool state) {
Serial.print("Device "); Serial.print(device_name);
Serial.print(" state: ");
if (state) {
Serial.println("ON");
} else {
Serial.println("OFF");
}
//Switching action on detection of device name
if ( (strcmp(device_name, "Pumpe") == 0) ) {
// adjust the relay immediately!
if (state) {
digitalWrite(Kitchen, HIGH);
} else {
digitalWrite(Kitchen, LOW);
}
}delay (500);
}
void setup() {
//Initialize pins to Low on device start
pinMode(Kitchen, OUTPUT);
digitalWrite(Kitchen, LOW);
// Init serial port and clean garbage
Serial.begin(SERIAL_BAUDRATE);
Serial.println("FauxMo demo sketch");
Serial.println("After connection, ask Alexa/Echo to 'turn on' or 'off'");
// Wifi
wifiSetup();
// Device Names for Simulated Wemo switches
fauxmo.addDevice ("Pumpe");
fauxmo.onMessage(callback);
}
void loop() {
fauxmo.handle();
}
could someone please tell were and how I can install the delay/timer
thank you very much for you help.
best regards
Toshiro