80Views4Replies

Author Options:

arduino wifi shield code what is wrong? why i cant turn on and off the led? Answered

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


IPAddress ip(192, 168, 0, 120);
char ssid[] = "TP-LINK_7035CE";     //  your network SSID (name)
char pass[] = "(sabra*123)";        // your network password

WiFiServer server(80);     // create a server at port 80

String readString;         // stores the HTTP request
//////////////////////
void setup(){ WiFi.config(ip);
pinMode(6, OUTPUT); //pin selected to control LED
//start WIFI
WiFi.begin(ssid, pass);   // initialize WiFi device
digitalWrite(6, LOW);
server.begin();
}

void loop(){
// Create a client connection
WiFiClient client = server.available();  // try to get client
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

//read char by char HTTP request
if (readString.length() < 100) {

//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {

///////////////
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE>Home Automation</TITLE>");
client.println("</HEAD>");
client.println("<BODY bgcolor='aqua'>");
client.println("<H1>Home Automation</H1>");
client.println("<hr />");
client.println("<br />");

client.println("<a href=\"/?lighton\"\">Turn On Light</a>");
client.println("<a href=\"/?lightoff\"\">Turn Off Light</a><br />");

client.println("</BODY>");
client.println("</HTML>");


///////////////////// control arduino pin
if(readString.indexOf("?lighton") >-1)//checks for on
{
digitalWrite(6, HIGH); // set pin 6 high
}
else{
if(readString.indexOf("?lightoff") >-1)//checks for off
{
digitalWrite(6, LOW); // set pin 6 low
}
}
readString=""; //clearing string for next read

delay(1);
//stopping client
client.stop();

}
}
}
}
}

Tags:board

Comments

The forums are retiring in 2021 and are now closed for new topics and comments.
0
rickharris
rickharris

4 years ago

Skip the wireless shield and get the LED turning on and off.

Then worry about getting the wireless to communicate properly.

0
ahmad_pika91
ahmad_pika91

Answer 4 years ago

what do u mean by Skip the wireless shield and get the LED turning on and off plz?

0
rickharris
rickharris

Answer 4 years ago

Remove the wireless shield - get the LED turning on and off with just the Arduino then all you need to do is get the wireless bit working.

At present you don't know which part isn't working.

0
iceng
iceng

Answer 4 years ago

+1

Exactly