Hello,
I am trying to build function that sends char array with values dependant on numbers I read from sensors to other arduino board. I receive from sensor number from 2 to lets say 20 digits and I want to send only those digits I read from sensor.
Lets say variable is "Char Varr[20];" and it has from 2 to 20 digits rest are zeros.
I use function
WifiSend(Varr);
Transmitter:
void WifiSend(char Xbuffer[]){
for (i = 0; i < 20; i++){
Xbuffer[i]=Xbuffer[i];
Serial.print(Xbuffer[i]);
}
[color=red] if (!wirelessSPI.write(Xbuffer, [b]20[/b])) {[/color]
//if the send fails let the user know over serial monitor
Serial.println("packet delivery failed");
}
for(i=0;i<20;i++){
Xbuffer[i]=0;
}
}
Receiver:
if(wirelessSPI.available()){
wirelessSPI.read( Ybuffer, 20); //read one byte of data and store it in Ybuffer variable
char cArray[10] = "done_man"; //create char array to store "done," note that the fifth char is for the null character
wirelessSPI.writeAckPayload(1, cArray, sizeof(cArray)); //send ack payload. First argument is pipe number, then pointer to variable, then variable size
Serial.println("");
Serial.print("Recieved packet: ");
for(int i=0; i<Ybuffer[0]+1; i++){
Serial.print(Ybuffer[i]);
}
Serial.println("");
[b] for(int i=0; i<20; i++){
Ybuffer[i]=0;[/b]
}
}
The question is there any way to determine correct number of bytes I am sending? Or at least making results printed without trash: