Hi everyone. I am having a couple of issues with my IoT thermostat project.
I have a room and set temperature on my thermostat and am keeping those variables updated on Firebase. I have 2 push buttons on my thermostat and they can increase/decrease the set temperature.
At first I was able to use an interrupt on my push buttons to trigger a boolean value and update the new set temperature to Firebase and it worked great (calling Firebase API in interrupt service routine gave me a ton of errors).
Here is the ISR:
void pin_ISR_Increase() {
interruptTrigger = true;
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
if (interrupt_time - last_interrupt_time > 350) {
setTemperature++;
}
last_interrupt_time = interrupt_time;
}
My issue now is I am trying to have it so not only can I use the push buttons to update the set temperature on Firebase, but at the same time try and read the set temperature from Firebase in case I change the value on Firebase, or in the future my Android application.
This will allow me have controls on the device itself and change the set temperature from the Android app and they will stay synchronized.
When I try to do this now however, I am running into the issue where my push buttons are not changing the temperature anymore.
Here is a small sample of my code:
if (interruptTrigger == true) {
setFirebaseSetTemperature();
interruptTrigger = false;
} else {
getFirebaseSetTemperature();
}
}
It seems to just be hitting the else statement constantly, even when it does hit the if statement when debugging in Serial monitor it doesn't change the temperature value.
Are there any better ways to to read and write from Firebase in a timely manner?
A couple more issues I've run into:
Does anyone have any recommendations for running a task every x amount of seconds? I also have code to push the room temperature to Firebase, but it's not necessary to constantly do this every loop. I have considered using for loops to run certain portions of the code every few times around, but it didn't work too well. My idea next is to try using millis() like I did with my interrupts.
Serial.println has been acting very funny in the monitor all of a sudden. For example Serial.println("Current temp: " + setTemperature);
would only print "rrent temp" in serial monitor, yet Serial.println(setTemperature); would print the integer like I wanted it to.
And lastly, the push buttons I have require a slight delay between each press to increment/decrement the tmperature, I've tried adjusting my debounce algorithmn in the ISRs but can't improve the response time anymore. Do better push buttons exist that can deliver very instant responses when spamming the buttons or is a 0.5-1 second delay between each press is as good as I am going to get?