Dear friends,
We are in the big trouble to make our wifi web server code to work as it is original code from arduino learning section as follows
#include <SPI.h>
#include <WiFi.h>
int iStatus = WL_IDLE_STATUS;
char szSsid[] = "S603-1"; // network SSID (name)
char szPass[] = "ipmsimk0827"; // network password
// webserver
WiFiServer server(80);
void setup(){
Serial.begin(9600);
fnConnectToAP();
// fnSendRequest();
fnStartServer();
}
void loop(){
fnWaitingRequest();
// fnReadData();
}
void fnStartServer(){
delay(1000);
server.begin();
}
void fnWaitingRequest(){
WiFiClient client = server.available();
if (client) {
Serial.println("new client comming");
boolean bCurrentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && bCurrentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println();
client.println("");
client.println("");
client.print("Hello World ");
client.println("");
break;
}
if (c == '\n') {
// you're starting a new line
bCurrentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
bCurrentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1000);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}
void fnConnectToAP(){
while ( iStatus != WL_CONNECTED) {
Serial.println("Connecting to network...");
Serial.print("SSID: ");
Serial.println(szSsid);
delay(1000);
iStatus = WiFi.begin(szSsid,szPass); // connect
}
Serial.print("Connected successfully. IP address:");
IPAddress myAddress = WiFi.localIP();
Serial.println(myAddress);
}
However, it is no working. We use both arduino wifi shield and arduino mega 2560. In the similation, it works on the tranfermation cmd and ping checking is fine but do not show the window out. Your urgently assist is much appreciated