ESP-NOW - waiting feedback and Switch-Case statement
Posted: Fri Jul 08, 2022 2:28 am
Hi everyone !
Here is Andrea from Italy, a "newbie" of esp8266
I have some questions regarding ESP-NOW communication protocol cause I have a lot of "communication Fail" feedbacks while running my code.
1 – Sender side (self role COMBO): I send a broadcast message to 5 peers and than I put sender esp8266 in a while loop to wait the feedbacks from all the peers. This is a short extract of code:
esp_now_send(0, (uint8_t *) &test, sizeof(test));
tWait = millis() + 300;
while (millis() <= tWait){
yield();
}
Is it a correct coding way? Or, am I making some mistake? (I used while to avoid delay function)
Are 300 millis of “waiting time” enough ?
2 – Receiver side (self role COMBO): I want that receiver stops running loop until it receives a message from sender. Is it ok “locking” it in a while loop like this ?
msgRcv is a “flag” variable that I include into OnDataRecv function ( if receiver receives a message –> msgRcv = true; )
while(msgRcv == false){
yield();
}
3 - In both sender and receivers, while loop is composed by a "switch-case" statement.
Is "switch-case" statement compatible with esp8266 and ESP-NOW protocol ?
Here a simplified example of my code:
void loop {
switch(val){
case 1:
// do something
break
case 2:
// do something
// wait for communication income
break
case 3:
// do something
// communicate to peers
break
}
}
Thanks to all in advance !
Here is Andrea from Italy, a "newbie" of esp8266
I have some questions regarding ESP-NOW communication protocol cause I have a lot of "communication Fail" feedbacks while running my code.
1 – Sender side (self role COMBO): I send a broadcast message to 5 peers and than I put sender esp8266 in a while loop to wait the feedbacks from all the peers. This is a short extract of code:
esp_now_send(0, (uint8_t *) &test, sizeof(test));
tWait = millis() + 300;
while (millis() <= tWait){
yield();
}
Is it a correct coding way? Or, am I making some mistake? (I used while to avoid delay function)
Are 300 millis of “waiting time” enough ?
2 – Receiver side (self role COMBO): I want that receiver stops running loop until it receives a message from sender. Is it ok “locking” it in a while loop like this ?
msgRcv is a “flag” variable that I include into OnDataRecv function ( if receiver receives a message –> msgRcv = true; )
while(msgRcv == false){
yield();
}
3 - In both sender and receivers, while loop is composed by a "switch-case" statement.
Is "switch-case" statement compatible with esp8266 and ESP-NOW protocol ?
Here a simplified example of my code:
void loop {
switch(val){
case 1:
// do something
break
case 2:
// do something
// wait for communication income
break
case 3:
// do something
// communicate to peers
break
}
}
Thanks to all in advance !