Arduino sia Server sia Client

Salve e complimenti per il forum.

Ho intenzione di gestire un Arduino tramite web service ma, all’inizializzazione dovrebbe essere Arduino ad inviare il proprio IP al WS.
Ecco lo sketch (che non funziona):

#include <SPI.h>
#include <WiFi.h>

char ssid[] = "htwireless";      //  your network SSID (name) 
char pass[] = "HitecoWIFI!2015";   // your network password
int keyIndex = 0;            // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;
WiFiClient client;
WiFiServer server(81);
char server1[] = "www.esempiointel.altervista.org";
unsigned long lastConnectionTime = 0;           // last time you connected to the server, in milliseconds
boolean lastConnected = false;                  // state of the connection last time through the main loop
const unsigned long postingInterval = 10*1000;  // delay between updates, in milliseconds

int pinLu = A2;
int pinTemp = A0; 
float temperature;
int B=3975;                  
float resistance;

int pinLED = 13; 
boolean acceso = false; 

void setup() {
  //Initialize serial and wait for port to open:
  pinMode(pinLED,OUTPUT);
  digitalWrite(pinLED,LOW);
  Serial.begin(9600); 
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    // don't continue:
    while(true);
  } 

  String fv = WiFi.firmwareVersion();
  if( fv != "1.1.0" )
    Serial.println("Please upgrade the firmware");
  
  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:    
    status = WiFi.begin(ssid, pass);
    //WiFi.config(ip,dnsIP, routerIP, netMask);
    // wait 10 seconds for connection:
    delay(10000);
  } 
  // you're connected now, so print out the status:
  printWifiStatus();
  sendGET();
}

void loop() {
  
  WiFiClient client = server.available();
  if (client) {
    Serial.println("new client");
    // Finisce una richiesta HTTP
    boolean currentLineIsBlank = true;
    String postText ="";
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if(postText.length()<100){
          postText +=c;
        }
        // Se viene completato l'invio della richiesta HTTP, allora il server invia la risposta
        if (c == '\n' && currentLineIsBlank) {
          
          client.println("HTTP/1.1 200 OK");
          
          client.println("Connection: close");  
          client.println();
           
          int val = analogRead(pinTemp);                               
          resistance=(float)(1023-val)*10000/val;                      
          temperature=((1/(log(resistance/10000)/B+1/298.15)-273.15)+10);

          int luce = analogRead(pinLu);

          
          client.print("{""Errore"":false,""ErroreDescrizione"":null,""luminosita"":{""Valore1"":");
          client.print(luce);
          client.print("},""temperatura"":{""Valore"":");
          client.print(temperature);
          client.print("}}");
          
          break;
        }
        if (c == '\n') {
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }

     if(postText.indexOf("?on") >0){
          digitalWrite(pinLED,HIGH);
          Serial.println("Accendi LED");
          acceso = true;
        }
     // Se l'utente ha premuto l'icona per spegnere il LED
     if(postText.indexOf("?off") >0 ){
       digitalWrite(pinLED,LOW);
        Serial.println("Spegni LED");
        acceso = false;
       }

     if(postText.indexOf("*") >0){
        char floatbuf[32];
         int s = postText.indexOf("*");
         int f = postText.indexOf("!", s);
          
          
          //Serial.println(s);
          //Serial.println(f);
       String  ro= postText.substring(s+1,f);  
       ro.toCharArray(floatbuf, sizeof(floatbuf)); 
         float par = atof(floatbuf);
        Serial.println(par);

            }
    delay(1);
    
    client.stop();
    Serial.println("client disconnected");
}
}

void printWifiStatus() {
  
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

void sendGET() //client function to send/receie GET request data.
{
  String strURL = "";
  IPAddress myIP = WiFi.localIP();
  String ipStr = String(myIP[0])+"."+String(myIP[1])+"."+String(myIP[2])+"."+String(myIP[3]);
  // if there's a successful connection:
  if (client.connect(server1, 80)) {
    Serial.println("connecting...");
    // send the HTTP PUT request:
    strURL = "POST /index.php?ip=";
    strURL += ipStr;
    strURL += " HTTP/1.1";
    client.println(strURL);
    client.println("Host: www.esempiointel.altervista.org");
    client.println("User-Agent: arduino-ethernet");
    client.println("Connection: close");
    client.println();
    Serial.println(strURL);
    Serial.println(ipStr);

    // note the time that the connection was made:
    lastConnectionTime = millis();
  } 
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
    Serial.println("disconnecting.");
    client.stop();
  }
}

Cosa c’è che non va?
Grazie in anticipo,
Lorenzo

— il codice va racchiuso tra i tag CODE e non QUOTE. Per questa volta ho corretto io il tuo post, in futuro usa i tag giusti :wink: - gpb01