Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WiFi module gets lost #229

Open
daniel-mohr opened this issue Sep 18, 2022 · 0 comments
Open

WiFi module gets lost #229

daniel-mohr opened this issue Sep 18, 2022 · 0 comments
Labels
type: imperfection Perceived defect in any part of project

Comments

@daniel-mohr
Copy link

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!
@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Sep 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants