Hi,
I've connected multiple clients to one server.
I've Arduino Pro Micro with NRF24L01+ Transceivers and I use the Mirf library from this Arduino site.
My clients are called btn01 to btn10.
I want to select one client randomly out of the connected one.
As example, if I have 6 clients connected I send 24 commands, the last command determine which client is selected.
The random array could contains something like this :
pos: 0 - Val: 4
pos: 1 - Val: 3
pos: 2 - Val: 1
pos: 3 - Val: 5
pos: 4 - Val: 6
pos: 5 - Val: 5
pos: 6 - Val: 1
pos: 7 - Val: 4
pos: 8 - Val: 1
pos: 9 - Val: 2
pos: 10 - Val: 1
pos: 11 - Val: 6
pos: 12 - Val: 1
pos: 13 - Val: 4
pos: 14 - Val: 1
pos: 15 - Val: 5
pos: 16 - Val: 6
pos: 17 - Val: 2
pos: 18 - Val: 1
pos: 19 - Val: 5
pos: 20 - Val: 6
pos: 21 - Val: 1
pos: 22 - Val: 2
pos: 23 - Val: 5
When the commands are sent with the loop there is always around 5 cmd not received by he clients for unknown reasons.
I array example above, clients on array position 6, 17, 18, 19, 20 didn't received the command.
Any idea what's going wrong here ?
Many many thanks in advance to help me to sort that out, I'm goind nut with this issue since days.
Mirf.cePin = A1;
Mirf.csnPin = A0;
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setRADDR((byte *) "btn00");
Mirf.payload = 5;
Mirf.channel = 90;
Mirf.configRegister(RF_SETUP, 0x22); //256Kbpsbps
//Mirf.configRegister(RF_SETUP, 0x06); //1Mbps
//Mirf.configRegister(RF_SETUP, 0x0E); //2Mbps - Default setting
Mirf.configRegister(SETUP_RETR, 0x0F); //Up to 15 retries
Mirf.configRegister(EN_RXADDR, 0x3F); //Activate all channels
void randomBlinkBtn() {
int btnCount = 0;
//Count connected buttons number
for (int i = 1; i <= sizeof(btnConnected); i++) {
if(btnConnected[i]) {
btnCount++;
}
}
byte rndBtn[btnCount*4];
byte rnd = 0;
//Feed array randomly
for (int i=0;i<sizeof(rndBtn);i++) {
rnd = getRandomButton();
if (i>0) {
while(rnd == rndBtn[i-1]) {
rnd = getRandomButton();
}
}
rndBtn[i] = rnd;
}
//Send cmd to the buttons
for (int i=0;i<sizeof(rndBtn);i++) {
char button[] = "btn00";
char num[2];
sprintf(num, "%d", rndBtn[i]);
if(rndBtn[i]<10){
button[4] = num[0];
}
else {
button[3] = num[0];
button[4] = num[1];
}
Mirf.setTADDR((byte *)button);
if(i==sizeof(rndBtn)-1) {
Mirf.send((byte *) "cmd11");
}
else {
Mirf.send((byte *) "cmd16");
}
while (Mirf.isSending());
delay(300);
}
}