Hi everyone,
I am trying to send bytes from my computer to the core (RGB encoding bytes) and store them in the flash memory (in an array) to use them later, to control LED strips.
However, it seems that most of the time only the first byte is going through (sometime, the stream works but rarely), then the stream is blocked and then the execution go through the last part of the code printing “Done” in the serial port although I think the thread should not reach this part since some bytes are missing.
I really don’t get it, and I am beginning to wonder if it is possible to stream accurately bytes without losses.
Moreover, when the transfer is completed, my Spark Core loose the connection, and start blinking fast red, then fast blue. I put Particle.process() along my code to prevent the Spark core to disconnect from the cloud but still the problem persist.
Thanks for your help, I am really confused with the TCP connection!
void loop()
{
if (client.connected() && !done ) {
while (i< 428){
if(client.connected() && client.available()){
BlueStack[i] = client.read();
Serial.println(BlueStack[i]);
//delay(10);
}
else {
client = server.available();
Particle.process();
}
if(client.connected() && client.available()){
RedStack[i] = client.read();
Serial.println(RedStack[i]);
//delay(10);
}
else {
client = server.available();
Particle.process();
}
if(client.connected() && client.available()){
GreenStack[i] = client.read();
Serial.println(GreenStack[i]);
//delay(10);
}
else {
client = server.available();
Particle.process();
}
i++;
/* LedStack[j] = client.read();
LedCount[j] = client.read();
j++ */
Particle.process();
}
Serial.println("C'est fini");
for (int h = 0; h<428; h++){
Serial.print(RedStack[h]);
Serial.print(GreenStack[h]);
Serial.println(BlueStack[h]);
}
done = true;
} else {
// if no client is yet connected, check for a new connection
client = server.available();
Particle.process();
}
}