Hey guys, I know that this problem is not new, but the usual fix with using client.flush() and client.stop() isn't working for me. I use the newest firmware and library.
So this is the important part of my code. It's a bit messy, sorry for that.
#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 me.
There is also a thread on stackexchange about this, with no answer yet. (Arduino Uno WiFi Rev2 "no socket available" - Arduino Stack Exchange)
So thank you in advance!