You would flood the Blynk server.
Pete.
You would flood the Blynk server.
Pete.
Oh⌠And what will be itâs consequences?
But using timer to call swfeedback would not do that rightâŚ
If you use a timer and call if more than ten times per second then you can achieve the same result, although BlynkTimer has some safeguards built-in.
If you flood the server then your device will probably be disconnected.
With what you are trying to achieve, interrupts are by far the best approach.
Pete.
Can you give me some idea on how to use interrupts to achive this ???
you have to learn how interrupts works
we can help you after you understand.
Iâd start with a very simple, non-Blynk sketch with one button to begin with.
Look at debounce routines as well.
Youâll need an ISR handler and debounce tracking variable for each physical pin.
Pete.
First of all sorry for being Late as I was busy with my exams.
I went through the article provided above.
So it says:
attachInterrupt(GPIOPin, ISR, Mode);
will call the function whenever there is a CHANGE
in value of the GPIO Pin, where ISR is the name of the function to be called.
Now my question is that means if I have to repeat this attachInterrupt(GPIOPin, ISR, Mode);1
line 4 times for the 4 switches I am using but each cases the only difference will be the GPIOPin value. So, is there any way out to dynamically do this so I need not to write same function again and again?
I have 12 interrupts, I used copy and paste, not very difficult
You canât call the same ISR function from each of the four interrupts. You need to have separate ISR handlers for each pin, and that handler will have its own debounce routine, and turn on/off itâs own relay (and presumably synchronise itâs own button widget in the Blynk app).
A debounce routine is needed because the electrical ânoiseâ that is generated by pressing and releasing a physical button will cause the interrupt to be triggered multiple times, and you need these false triggers to be ignored. This is done with a flag variable, and you will need a separate variable for each interrupt handler.
This is why I saidâŚ
Pete.
How can I create denounce routine. Can you provide some resource to learn that?
Search the forum, or use Google.
Pete.
Just add a flag and switch between 0 and 1
Okay so I went through some details on debounce. In all the examples provided there they were using a push button. So they are debouncing all the signals for a particular period of time letâs say 50ms. So, all the signals in that period is treated as a single signal. But in this case there is no such case that we will press the button for particular time and release as we are using normal switches which will send high signal when the circuit is complete. That ia the switch is on. So in that case what is the purpose of debounce?
Because no mechanical switch makes and breaks the connnections cleanly.
Try it without and see what happens.
Pete.
Okay So letâs try one by one. In my case what would be the perfect way to implement the interrupts?
Pete.
Can you please tell in details what will exactly happen if that is done??
You will flood the Blynk cloud server with requests.
I donât know exactly what action would be taken when this occurs, but itâs most likely that the server will kick your device off the network by terminating the connection, causing your device to go offline. I guess if your device persistently does this then it would be backlisted, but I donât know for sure.
As I said earlier, BlynkTimer aims to try to prevent this situation occurring, but as you arenât using BlynkTimer, and instead are calling your swfeedback directly from the void loop you are circumventing these protections.
Butâ I really donât know why weâre having this discussion. Fixing the issue is very simple, and it will make your sketch run far better anyway.
Pete.
Yeah I am surely going to use the debounce or timer for this. As not only blynk it will make the manual switch respond more faster. I was just curious what would blynk do in that case.
I tried interrupts to call the functions for manual switches.
I am calling the functions in this manner from void setup()
attachInterrupt(s1, sw1feedback, CHANGE);
attachInterrupt(s2, sw2feedback, CHANGE);
attachInterrupt(s3, sw3feedback, CHANGE);
attachInterrupt(s4, sw4feedback, CHANGE);
These are the functions in the swfeedback.h file
void IRAM_ATTR sw1feedback()
{
if (digitalRead(s1) == HIGH && SWITCH5_FLAG == 1) {
digitalWrite(r1, LOW);
if(Blynk.connected()){
Blynk.virtualWrite(V1, LOW);
}
Serial.println("r1 on");
relay1 = 0;
SWITCH5_FLAG = 0;
}
if (digitalRead(s1) == LOW && SWITCH5_FLAG == 0) {
digitalWrite(r1, HIGH);
if(Blynk.connected()){
Blynk.virtualWrite(V1, HIGH);
}
Serial.println("r1 off");
relay1 = 1;
SWITCH5_FLAG = 1;
}
}
void IRAM_ATTR sw2feedback(){
if (digitalRead(s2) == HIGH && SWITCH6_FLAG == 1) {
digitalWrite(r2, LOW);
if(Blynk.connected()){
Blynk.virtualWrite(V2, LOW);
}
Serial.println("r2 on");
relay2 = 0;
SWITCH6_FLAG = 0;
}
if (digitalRead(s2) == LOW && SWITCH6_FLAG == 0) {
digitalWrite(r2, HIGH);
if(Blynk.connected()){
Blynk.virtualWrite(V2, HIGH);
}
Serial.println("r2 off");
relay2 = 1;
SWITCH6_FLAG = 1;
}
}
void IRAM_ATTR sw3feedback(){
if (digitalRead(s3) == HIGH && SWITCH7_FLAG == 1) {
digitalWrite(r3, LOW);
if(Blynk.connected()){
Blynk.virtualWrite(V3, LOW);
}
Serial.println("r3 on");
relay3 = 0;
SWITCH7_FLAG = 0;
}
if (digitalRead(s3) == LOW && SWITCH7_FLAG == 0) {
digitalWrite(r3, HIGH);
if(Blynk.connected()){
Blynk.virtualWrite(V3, HIGH);
}
Serial.println("r3 off");
relay3 = 1;
SWITCH7_FLAG = 1;
}
}
void IRAM_ATTR sw4feedback(){
if (digitalRead(s4) == HIGH && SWITCH8_FLAG == 1) {
digitalWrite(r4, LOW);
if(Blynk.connected()){
Blynk.virtualWrite(V4, LOW);
}
Serial.println("r4 on");
relay4 = 0;
SWITCH8_FLAG = 0;
}
if (digitalRead(s4) == LOW && SWITCH8_FLAG == 0) {
digitalWrite(r4, HIGH);
if(Blynk.connected()){
Blynk.virtualWrite(V4, HIGH);
}
Serial.println("r4 off");
relay4 = 1;
SWITCH8_FLAG = 1;
}
}
But on sending a high current to the pin, this is the error I am getting.
Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1)
Also it is giving some DUMP and rebooting after that.
What is the possible reason for this and how can it be solved??