Hi, first time post, hopefully I am following the guidlines properly.
My general goal is to create a sketch that uses a DHT22 and a PIR sensor to publish temperature via MQTT and turn off my Lutron light via IFTTT Webhooks after no motion is detected for a pre-determined amount of time.
I want the timer to reset each time motion IS present.
What I am using:
SimpleTimer.h Library from Arduino Playground - SimpleTimer Library
esp8266 - generic D1 mini
I have the PIR working, one standard SimpleTimer, and the webhook.
Following the SimpleTimer examples linked above, I have not been able to get a second timer to work.
Below is a small section of my code which I believe covers what applies to my question.
#include <SimpleTimer.h> //https://playground.arduino.cc/Code/SimpleTimer/#Usage
SimpleTimer timer;
SimpleTimer timerPIR; //Creates a second timer to be used for PIR Lights
void setup()
}
// Start the timers for void loop
timer.setInterval(3000, readSensor);
timer.setInterval(3000, sendMQTT);
timer.setInterval(5000, checkPIR);
timerPIR.setInterval(180000, sendIFTTT); //Doesn't appear to work unless I change from timerPIR to
timer
{
void sendIFTTT()
{
Serial.println("Sending Webhook");
HTTPClient http; //Declare an object of class HTTPClient
http.begin("http://maker.ifttt.com/trigger/Off/with/key/"); //Specify request destination
http.GET(); //Send the request
http.end(); //Close connection
}
void checkPIR()
{
PIRstate = digitalRead(PIR); //HIGH when motion detected, else LOW
if (PIRstate == 1) //Checkig for motion
{
digitalWrite(LED_BUILTIN, HIGH);
client.publish("Office_PIR", "1");
//timer.restartTimer(timerPIR); //Creates Error
//void restartTimer(int timerPIR); //Doesn't work(maybe because the second timer doesn't work), but also does not creates error
}
else
{
digitalWrite(LED_BUILTIN, LOW);
client.publish("Office_PIR", "0");
}
lastPIRstate = PIRstate;
}
void loop()
{
//Initiates timers to control function calls
timer.run();
//MQTT
client.loop();
//OTA
ArduinoOTA.handle();
}
The error I get with the first attempt to restart the timer 'timer.restartTimer(timerPIR);' is:
"no matching function for call to 'SimpleTimer::restartTimer(SimpleTimer&)'
I do not get an error with 'void restartTimer(int timerPIR);' however it doesn't work either.
Perhaps both of these conditions are because I am not actually creating the timerPIR. I have noticed that timerPIR does not appear to do anything.
I am having trouble interpreting the examples and the instructions for this library. I have seen several versions of "SimpleTimer" however I am successfully using this version in several other sketches with single timers and no restart functions.
For this reason I would prefer to continue with this library, or at least a code compatible fork.