I'm sending my Nano 33 IoT a byte at a time over TCP at a rate of one byte every half second. This establishes a heartbeat, and the intention is that the Nano will raise an alarm if the time between heartbeats exceeds one second. To my surprise, the alarm was being triggered.
I'm wondering if there is some sort of buffering going on in the NINA firmware so that it tries to accumulate a big string of bytes before making the buffer visible through client.available().
To test this, I wrote a little snippet.
WiFiClient client;
void loop() {
WiFiClient newClient = server.accept();
if (newClient) {
if (client) {
Serial.println("Rejecting second connection");
newClient.stop();
} else {
Serial.println("Accepting connection");
client = newClient;
}
}
if (client) {
// valid client
if (client.available() > 0) {
if (client.available() > 1) {
Serial.print("More than one byte available ");
Serial.println(client.available(), DEC);
}
...
Since I send bytes one a time, I would expect the "More than one byte available" to never trigger, since that means two bytes, which were sent 500ms apart, have arrived at the Nano at essentially the same instant. But the message does trigger if I run the program long enough.