The example program at:
https://docs.arduino.cc/tutorials/giga-r1-wifi/giga-wifi#web-client
defines client
as a global variable. I tried rewriting the body of the example to make client
a local variable within loop()
as follows:
void loop() {
WiFiClient client;
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected to server");
// Make a HTTP request:
client.println("GET /search?q=arduino HTTP/1.1");
client.println("Host: www.google.com");
client.println("Connection: close");
client.println();
}
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting from server.");
client.stop();
// do nothing forevermore:
while (true);
}
}
The example then no longer works.
So for this example client
needs to be a global variable, but for the WebServer example it needs to be a local variable; see:
https://forum.arduino.cc/t/call-to-server-available-fails-if-client-is-a-global-variable/1137604
This appears to make it impossible for my application to provide general Wi-Fi support on the GIGA. Any suggestions?