Reference.WiFiServerBegin History

Hide minor edits - Show changes to markup

November 23, 2011, at 01:01 AM by Scott Fitzgerald -
Added line 24:
  1. include <SPI.h>
Changed lines 26-33 from:
  1. include <IPAddress.h>

byte mac[6] = { 0 }; IPAddress ip; IPAddress gateway; IPAddress subnet; byte dataBuf[80] = { 0 }; char ssid[32] = { 0 };

to:

char ssid[] = "lamaison"; // your network SSID (name) char pass[] = "tenantaccess247"; // your network password

Changed lines 31-35 from:

Server server(23);

void setup() {

to:

WiFiServer server(80);

void setup() {

  // initialize serial:
Changed lines 36-37 from:
  Serial.println("Setup WiFi...");
  strcpy(ssid, "Vodafone-10289870");
to:
  Serial.println("Attempting to connect to WPA network...");
  Serial.print("SSID: ");
Changed lines 39-55 from:
  int status = WiFi.begin(ssid);
to:
  status = WiFi.begin(ssid, pass);
  if ( status != WL_CONNECTED) { 
    Serial.println("Couldn't get a wifi connection");
    while(true);
  } 
  else {
    server.begin();
    Serial.print("Connected to wifi. My address:");
    IPAddress myAddress = WiFi.localIP();
    Serial.println(myAddress);

  }

}

void loop() {

Deleted lines 56-60:
  Serial.println("Wifi Connected!");

  Serial.println("Starting server...");
  server.begin();
  delay(1000);  
Deleted lines 58-82:

void loop() {

  static uint8_t count = 0;
  Serial.println("Retry connect...");
  status = WiFi.begin(ssid);
  if (status == WL_CONNECTED)
  {
      byte status = 0;
      Client client = server.available(&status);
      if (client) {
        byte idx = 0;
        while (client.available())
        {
            dataBuf[idx++] = client.read();
        }

        if (idx>0) 
        {
          dataBuf[idx]=0; 
          server.write((char*)&dataBuf[0]);
        }
        return;
      }
  }

}

November 22, 2011, at 11:18 PM by Scott Fitzgerald -
Changed line 23 from:

[@

to:
Changed line 78 from:

@]

to:
November 22, 2011, at 03:54 AM by Scott Fitzgerald -
Added lines 1-78:

WiFi : Server class

begin()

Description

Tells the server to begin listening for incoming connections.

Syntax

server.begin()

Parameters

None

Returns

None

Example

#include <WiFi.h>
#include <IPAddress.h>

byte mac[6] = { 0 };
IPAddress ip;
IPAddress gateway;
IPAddress subnet;
byte dataBuf[80] = { 0 };
char ssid[32] = { 0 };
int status = WL_IDLE_STATUS;

Server server(23);


void setup()
{
  Serial.begin(9600);
  Serial.println("Setup WiFi...");
  strcpy(ssid, "Vodafone-10289870");
  Serial.println(ssid);
  int status = WiFi.begin(ssid);

  Serial.println("Wifi Connected!");

  Serial.println("Starting server...");
  server.begin();
  delay(1000);  
}

void loop()
{
  static uint8_t count = 0;
  Serial.println("Retry connect...");
  status = WiFi.begin(ssid);
  if (status == WL_CONNECTED)
  {
      byte status = 0;
      Client client = server.available(&status);
      if (client) {
        byte idx = 0;
        while (client.available())
        {
            dataBuf[idx++] = client.read();
        }

        if (idx>0) 
        {
          dataBuf[idx]=0; 
          server.write((char*)&dataBuf[0]);
        }
        return;
      }
  }
}

Share