1

My Uno WiFi Rev2 outputs on the serial monitor after ~30 min "no socket available". Until that point everything works just fine, my requests run as expected. I use the .flush() and .stop() commands, as in several forums suggested. In the following my really messy code (sorry for that, but it's not optimized and only for testing some stuff):

#include <SPI.h>
#include <WiFiNINA.h>

//W-Lan Data
int status = WL_IDLE_STATUS;
char ssid[] = "**********";
char pass[] = "**********";

bool jsonBool;
char jsonChar;
int curlyBracket;
String jsonCode;
String json;

IPAddress HueBridge(10, 0, 0, 30);

WiFiClient WHTTP;

void setup() {
  while (status != WL_CONNECTED) {
    status = WiFi.begin(ssid, pass);
    delay(500);
  }
}

void loop() {
  jsonProcessing();
  httpRequest();

  bar1();

  delay(55);
}

void httpRequest() {
  WHTTP.flush();
  WHTTP.stop();
  if(WHTTP.connect(HueBridge, 80)) {
    WHTTP.println("GET /api/*************/lights/ HTTP/1.1");
    WHTTP.println("Host: 10.0.0.30");
    WHTTP.println("Connection: close");
    WHTTP.println();
  }
}

void jsonProcessing() {
  while(WHTTP.connected()) {
    if(WHTTP.available()) {
      curlyBracket = 7;
      while(WHTTP.available()) {
        jsonChar = WHTTP.read();
        if((jsonChar == '{') && (curlyBracket == 7)) {
          jsonBool = true;
          curlyBracket = 0;
        }
        if(jsonChar == '}') {
          jsonBool = false;
          jsonCode = jsonCode + '}';
          curlyBracket++;
        }
        if(jsonBool) {
          jsonCode = jsonCode + jsonChar;
        }
      }
    }
    WHTTP.flush();
    WHTTP.stop();
  }
  jsonBool = false;

  //processing jsonCode variable

  jsonCode = "";
}

void bar1() {
  //calculating stuff
}

If anything is unclear feel free to ask. This is not the whole code, just the WiFi relevant parts.

The main structure is copied from here https://www.arduino.cc/en/Tutorial/WiFiNINAWiFiWebClientRepeating so it theoretically should work.

Thanks in advance.

2
  • do you have the newest version of the firmware and library? Commented Jul 8, 2019 at 5:21
  • 1
    @Juraj yes, I updated both yesterday but had no improvement. Commented Jul 8, 2019 at 5:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.