hi every body,
I need help with my project
I would like to turn off the lights that are on with one button.
but that disconnect blynk at the 3nd RF transmission
I tried lambda fonction, but It’s worse!
BTN value is button state
BLYNK_WRITE(V10)// ALL OFF
{
if (BTN1 == true) {
mySwitch.send(SWITCH_1_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V1, LOW);
BTN1 = false;
}
if (BTN2 == true) {
mySwitch.send(SWITCH_2_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V2, LOW);
BTN2 = false;
}
if (BTN3 == true) {
mySwitch.send(SWITCH_3_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V3, LOW);
BTN3 = false;
}
if (BTN4 == true) {
mySwitch.send(SWITCH_4_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V4, LOW);
BTN4 = false;
}
if (BTN5 == true) {
mySwitch.send(SWITCH_5_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V5, LOW);
BTN5 = false;
}
if (BTN6 == true) {
mySwitch.send(SWITCH_6_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V6, LOW);
BTN6 = false;
}
if (BTN7 == true) {
mySwitch.send(SWITCH_7_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V7, LOW);
BTN7 = false;
}
if (BTN8 == true) {
mySwitch.send(SWITCH_8_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V8, LOW);
BTN8 = false;
}
}
I’d try with timer. within BLYNK_WRITE(V10)
just initialise timer with setTimer(interval, timer_callback, n-times)
1 Like
Gunner
August 4, 2018, 7:45pm
3
When running Local Server, add this to the top of your sketch #define BLYNK_MSG_LIMIT 0
as it will disable what I called the “nanny mode” that seemed to govern the flow of multiple blynk commands if they were determined to happen too fast.
That said, it was to prevent disconnections, not cause them… so not sure if it is related to your case.
Otherwise, with repeated RF transmissions, could you be looking at either power or interference related issues?
Gunner:
BLYNK_MSG_LIMIT 0
I just tried, but same issue.
in the original code there is delay(1000) between each transmission.
but blynk can’t run with that delay.
could you tell me more about that?
ldb
August 4, 2018, 9:52pm
6
I used setTimeout to call for a function once after X time http://playground.arduino.cc/Code/SimpleTimer#F_setTimeout
I used lambda function but it’s worse
ldb
August 4, 2018, 10:17pm
8
What’s behind mySwitch.send
?
I’d use
blynk_write(V10){
Do something;
timer.settimeout(500, otherfunction);
}
Void otherfunction(){
Do something;
timer.settimeout(500, otherfunction2);
}
.
.
.
And at the last function, turn the button back to original position to inform all the steps have done and to avoid pressing it multiple times while sending RF
My idea for your problem is setting up the timer for n- runs,where for each run it would check and eventually change the state of output (light). the setTimer() would be preset after calling the BLYNK_WRITE(V10)
thank you, I’ll try that before sleep.
this is the solution to RF transmission issue
you have to keep in mind that mySwitch.send needs 1000 ms to achieve TX
so I use Lambda nested function to stage transmission every 1000 ms and now there is no issue in blynk
thanks @Gunner @ldb @marvin7
BLYNK_WRITE(V10)// ALL OFF
{
timer.setTimeout(1000L, []() {
if (BTN3 == true) {
mySwitch.send(SWITCH_3_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V3, LOW);
BTN3 = false;
}
timer.setTimeout(1000L, []() {
if (BTN4 == true) {
mySwitch.send(SWITCH_4_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V4, LOW);
BTN4 = false;
}
timer.setTimeout(1000L, []() {
if (BTN5 == true) {
mySwitch.send(SWITCH_5_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V5, LOW);
BTN4 = false;
}
timer.setTimeout(1000L, []() {
if (BTN6 == true) {
mySwitch.send(SWITCH_6_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V6, LOW);
BTN4 = false;
}
timer.setTimeout(1000L, []() {
if (BTN7 == true) {
mySwitch.send(SWITCH_7_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V7, LOW);
BTN4 = false;
}
timer.setTimeout(1000L, []() {
if (BTN8 == true) {
mySwitch.send(SWITCH_8_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V8, LOW);
BTN4 = false;
}
}); // END Timer Function
}); // END Timer Function
}); // END Timer Function
}); // END Timer Function
}); // END Timer Function
}); // END Timer Function
}
2 Likes
omegab
August 5, 2018, 12:42pm
12
When I’m updating a lot of things at once I place Blynk.run(); after every long command or every couple of commands, this may also work for you?
very good idea
I’ll test that.
what do you think about that @Gunner ?
never seen that before.
I reduced the time to 500 ms and that work !
I have a question:
how to jump from 2 to 8 if 1,3,4,5,6,7 are OFF ?
I tested “return” --> I got out of lambda loop
I tested “timer.disable” no effect.
what do you suggest ?
IBK
August 5, 2018, 6:19pm
15
@Blynk_Coeur
I’d try something like this:
void allOff() {
if (BTN3 == true) {
mySwitch.send(SWITCH_3_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V3, LOW);
BTN3 = false;
timer.setTimeout(1000L, allOff);
return();
}
else if (BTN4 == true) {
mySwitch.send(SWITCH_4_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V4, LOW);
BTN4 = false;
timer.setTimeout(1000L, allOff);
return();
}
else if (BTN5 == true) {
...
}
else if (BTN6 == true) {
...
}
....
}
BLYNK_WRITE(V10)// ALL OFF
{
allOff();
}
oh yes !!! I’ll test that !!!
@ldb thank you so much. (don’t forget , there is no () after return, I think it’s a mistake )
all is working correctly !!
but I ask myself why there is no difference between 1000L and 10L in my timers,
the result is the same:
one second between 2 buttons on/off.
probably there are some delays in the RCSwitch library .
void allOff() {
if (BTN1 == true) {
mySwitch.send(SWITCH_1_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V1, LOW);
BTN1 = false;
timer.setTimeout(10L, allOff);
return;
}
else if (BTN2 == true) {
mySwitch.send(SWITCH_2_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V2, LOW);
BTN2 = false;
timer.setTimeout(10L, allOff);
return;
}
else if (BTN3 == true) {
mySwitch.send(SWITCH_3_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V3, LOW);
BTN3 = false;
timer.setTimeout(10L, allOff);
return;
}
else if (BTN4 == true) {
mySwitch.send(SWITCH_4_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V4, LOW);
BTN4 = false;
timer.setTimeout(10L, allOff);
return;
}
else if (BTN5 == true) {
mySwitch.send(SWITCH_5_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V5, LOW);
BTN5 = false;
timer.setTimeout(10L, allOff);
return;
}
else if (BTN6 == true) {
mySwitch.send(SWITCH_6_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V6, LOW);
BTN6 = false;
timer.setTimeout(10L, allOff);
return;
}
else if (BTN7 == true) {
mySwitch.send(SWITCH_1_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V7, LOW);
BTN7 = false;
timer.setTimeout(10L, allOff);
return;
}
else if (BTN8 == true) {
mySwitch.send(SWITCH_8_OFF, PACKET_LENGTH);
Blynk.virtualWrite(V8, LOW);
BTN8 = false;
timer.setTimeout(10L, allOff);
return;
}
else {
Blynk.virtualWrite(V10, LOW);
}
}
BLYNK_WRITE(V10)// ALL OFF
{
allOff();
}
1 Like
ldb
August 5, 2018, 11:07pm
18
That’s because as you said.
I said that, because in the original code, they put delay in the main loop…
void loop() {
mySwitch.send(5393, 24);
delay(1000);
}
looking closely, I found that in my setup code
// Optional set pulse length.
mySwitch.setPulseLength(320);
// Optional set number of transmission repetitions.
mySwitch.setRepeatTransmit(15);
so I assume that we have 320x15 = 4800 pulses
but dono how many ms that takes, probably 500 ms or 1000 !
ldb
August 6, 2018, 5:26am
20
Well… to find out you’ll need to dig deeper into the library.
Just a side note, 15 repetition sounds like a overkill but I know nothing about RF specially 433mhz