Arduino Uno wifi Shield No socket available

I need to make requests to a laravel api, but when I try to make a connection client.connect(server, 8000)
I get the error "no socket available".

#include <WiFi.h>

char ssid[] = "****";     //  your network SSID (name)
char pass[] = "*****";    // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

char server[] = "ip";

WiFiClient client;

//pines donde estan conectados los sensores
int MQ_3 = A0;
int MQ_2 = A1;
int MQ_135 = A2;
const int MQ_DELAY = 500;

void setup() {

  // initialize serial:
  Serial.begin(9600);

  // attempt to connect using WPA2 encryption:
  Serial.println("Attempting to connect to WPA network...");
  status = WiFi.begin(ssid, pass);

  // if you're not connected, stop here:
  if ( status != WL_CONNECTED) {
    Serial.println("Couldn't get a wifi connection");

    while(true);
  }

  // if you are connected, print out info about the connection:
  else {
    Serial.println("Connected to network");
  }
////////////////////////////////////////////////////////////////////
  if(client.connect(server, 8000)){
    Serial.println("connected to server");

    //Make a HTTP request:
    client.println("GET /api/sensores/?q1=100&q2=200&q335=300 HTTP/1.1");
    client.println("Host: 192.0.0,0");
    client.println("Connetion: close");
    client.println();
  }
}
////////////////////////////////////////////////////////////////////
void loop() {

  // do nothing
  int resmq2 = analogRead(MQ_2);
  int resmq3 = analogRead(MQ_3);
  int resmq135 = analogRead(MQ_135);

  delay(MQ_DELAY);  

  if(client.connect(server, 8000)){

    String resultado = String("q1=")+resmq2+String("&q2=")+resmq3+String("&q3=")+resmq135;

    //HTTP request
    client.println("GET /api/sensores/?"+resultado+" HTTP/1.1");
    client.println("Host: 192.0.0.0");
    client.println("Connetion: close");
    client.println();

    char c = client.read();
    Serial.write(c);

    
  }
  delay(5000);
}

add client.stop();

1 Like

Where?
I was try whit a client.flush and client.Close before the line if(client.conect()) but not work
Thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.