Show Posts
Pages: [1]
1  Using Arduino / Networking, Protocols, and Devices / Re: WiFi shield help please on: October 11, 2012, 12:41:09 pm
Oh, I see. Yeah it's - I'm learning a lot here.
2  Using Arduino / Networking, Protocols, and Devices / Re: WiFi shield help please on: October 11, 2012, 11:32:35 am
Thanks for the response.

I thought that changing to "client.connect(gserver, 81)" would make my Arduino use its own port 81 for that communication. Thanks for clarifying.

The first serial messages that I get are:
Attempting to connect to SSID: belkin.3c2
Connected to wifi
SSID: belkin.3c2
IP Address:

except digits in place of 'x's - I just don't want to put the whole ip address up on the web. I can successfully go to this ip address in my browser and retrieve the "Hello" greeting from my arduino when the setup()'s WiFiClient code is commented out.

As another update, there's a current thread where someone is trying to do the same thing using the Ethernet shield at (,126545.0.html). And a good response is at (,80137.15.html). I'm not sure what all the relevant differences are between doing it with Ethernet and WiFi, though. One point that was brought up in that thread is that "client.stop()" can fail if there is data in the receive buffer, so that might be related to my problem.
3  Using Arduino / Networking, Protocols, and Devices / WiFi shield help please on: October 11, 2012, 02:08:25 am
Hi everyone, I recently got the "official" WiFi shield, and I'm running into some trouble.

Basically, I would like to run a WiFiClient interaction with an external server in the setup() and then run a WiFiServer in the loop(). It sounds pretty simple, but I'm getting some baffling results. Here's a simple sketch for the task (95% copied from the WiFi library examples):

#include "SPI.h"
#include "WiFi.h"

char ssid[] = "belkin.3c2";      //  your network SSID (name)
char pass[] = "myPassword";   // your network password
WiFiServer server(80);

void setup() {

  int status = WL_IDLE_STATUS;
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
  Serial.println("Connected to wifi");

  WiFiClient client;
  char gserver[] = "";
  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  if (client.connect(gserver, 80)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.println("GET / HTTP/1.1");
    client.println("Connection: close");
  while (client.available()) {
    char c =;



void loop() {

// listen for incoming clients
  WiFiClient client = server.available();
  if (client) {
    Serial.println("new client");
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c =;
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connnection: close");
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
    // give the web browser time to receive the data
      // close the connection:
      Serial.println("client disonnected");

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");

When you run the above code, the setup() WiFiClient successfully retrieves, but the Server doesn't work when you try to visit the arduino from your browser. However, if you comment out the setup() WiFIClient part, then the arduino is accessible from the web.

I changed the WiFiServer to port 81, and left the setup() on port 80, but I had the same problem. I changed the setup() to port 81, and then nothing works (even when the WiFiServer part is entirely commented out). It just hangs at "Connecting to server."

Any ideas?

Edit: added code tags
Pages: [1]