My UnuUno WiFi Rev2 outputs on the serial monitor after ~30 min "no socket available". Until that point everything wirksworks 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
}
#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
}
The main structure istis copied from here https://www.arduino.cc/en/Tutorial/WiFiNINAWiFiWebClientRepeating so it theoretically should work.