Skip to content

WiFi module gets lost #229

@daniel-mohr

Description

@daniel-mohr

Sending large packets (e. g. 4476 Bytes) leads to lost of the WiFi module. Sending instead 8192 Bytes seems to work.

Not every time but most of the time (about 90 %) the following example code leads to lost of the WiFi module on Arduino MKR WiFi 1010:

/*
  if a client get's data over tcp the WiFi module gets lost

  tested on: Arduino MKR WiFi 1010
*/
#include <SPI.h>
#include <WiFiNINA.h>
int WiFistatus = WL_IDLE_STATUS; // the WiFi radio's status
WiFiServer webserver(80);

#include "arduino_secrets.h"
char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;

void setup() {
  /* serial communication: */
  Serial.begin(115200);
  Serial.setTimeout(1000);
  while (!Serial) {}
  /* WiFi */
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
  } else {
    String fv = WiFi.firmwareVersion();
    if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
      Serial.println("Please upgrade the firmware");
    }
  }
}

void loop() {
  /* network WiFi */
  if (WiFi.status() == WL_NO_MODULE) {
    WiFistatus = WL_IDLE_STATUS;
    Serial.println("Communication with WiFi module failed!");
  } else {
    uint8_t it = 0;
    WiFistatus = WiFi.status();
    if (WiFistatus != WL_CONNECTED) {
      while ((it < 23) && (WiFistatus != WL_CONNECTED)) {
        WiFi.lowPowerMode();
        WiFistatus = WiFi.begin(ssid, pass);
        delay(300); // wait 0.3 seconds for connection
        it++;
      }
      if (WiFistatus == WL_CONNECTED) {
        Serial.println("connected to WiFi");
        webserver.begin();
      }
    }
    if (WiFistatus != WL_CONNECTED) {
      Serial.println("failed to connect to WiFi");
    }
  }
  /* webserver */
  WiFiClient client = webserver.available();
  if (client) {
    Serial.println("new client");
    boolean at_line_beginning = true;
    while (client.connected()) {
      char c = client.read();
      if (c != '\r') { // ignore CR
        if (c == '\n') {
          if (at_line_beginning) {
            break; // header read, stop reading further data
          } else {
            at_line_beginning = true;
          }
        } else {
          at_line_beginning = false;
        }
      }
    }
    Serial.print("WiFi.status() = ");
    Serial.println(WiFi.status());
    const size_t buffer1_len = 256;
    char buffer1[buffer1_len];
    size_t len = client.write(buffer1, buffer1_len);
    Serial.print("first buffer send: ");
    Serial.println(len);
    Serial.print("WiFi.status() = ");
    Serial.println(WiFi.status());
    const size_t buffer2_len = 4476; // lost WiFi module
    char buffer2[buffer2_len];
    len = client.write(buffer2, buffer2_len);
    Serial.print("second buffer send: ");
    Serial.println(len);
    Serial.print("WiFi.status() = ");
    Serial.println(WiFi.status());
    client.stop();
    Serial.println("client disconnected");
    Serial.print("WiFi.status() = ");
    Serial.println(WiFi.status());
    if (WiFi.status() == WL_NO_MODULE) {
      Serial.println("Communication with WiFi module failed!");
      while (true);
    }
  }
}

The output on the serial console is:

connected to WiFi
new client
WiFi.status() = 3
first buffer send: 256
WiFi.status() = 3
second buffer send: 0
WiFi.status() = 255
client disconnected
WiFi.status() = 255
Communication with WiFi module failed!

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions