So this is the code that I started with (it was working):
#include <ESP8266WiFi.h>
const char* ssid = "my ssid here";
const char* password = "my pass here";
int ledPin = 13; // GPIO13
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// Match the request
int value = LOW;
if (request.indexOf("/LED=ON") != -1) {
digitalWrite(ledPin, HIGH);
value = HIGH;
}
if (request.indexOf("/LED=OFF") != -1) {
digitalWrite(ledPin, LOW);
value = LOW;
}
// Set ledPin according to the request
//digitalWrite(ledPin, value);
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print("Led pin is now: ");
if(value == HIGH) {
client.print("On");
} else {
client.print("Off");
}
client.println("
");
client.println("<a href=\"/LED=ON\"\"><button>Turn On </button></a>");
client.println("<a href=\"/LED=OFF\"\"><button>Turn Off </button></a>
");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}
And now, with this code I get these errors:
#include <ESP8266WiFi.h>
const char* ssid = "Edimax35";
const char* password = "davidnet2003";
int ledVerde = 13; // GPIO13
int ledRosu = 12; //GPIO12
int ledAlbastru = 14; //GPIO14
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
pinMode(ledVerde, OUTPUT);
digitalWrite(ledVerde, LOW);
pinMode(ledRosu, OUTPUT);
digitalWrite(ledRosu, LOW);
pinMode(ledAlbastru, OUTPUT);
digitalWrite(ledAlbastru, LOW);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// Match the request
int value = LOW;
if (request.indexOf("/LED=ON") != -1) {
digitalWrite(ledVerde, HIGH);
value = HIGH;
}
if (request.indexOf("/LED=OFF") != -1) {
digitalWrite(ledVerde, LOW);
value = LOW;
}
int value2 = LOW;
if (request.indexOf("/LED2=ON") != -1) {
digitalWrite(ledRosu, HIGH);
value2 = HIGH;
}
if (request.indexOf("/LED2=OFF") != -1) {
digitalWrite(ledRosu, LOW);
value2 = LOW;
}
int value3 = LOW;
if (request.indexOf("/LED3=ON") != -1) {
digitalWrite(ledAlbastru, HIGH);
value3 = HIGH;
}
if (request.indexOf("/LED3=OFF") != -1) {
digitalWrite(ledAlbastru, LOW);
value3 = LOW;
}
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");
//ledVerde
client.print("ledVerde is now: ");
if(value == HIGH) {
client.print("On");
} else {
client.print("Off");
}
client.println("
");
client.println("<a href=\"/LED=ON\"\"><button>Turn On ledVerde</button></a>");
client.println("<a href=\"/LED=OFF\"\"><button>Turn Off ledVerde</button></a>
");
client.println("</html>");
client.print("ledRosu is now: ");
//ledRosu
if(value2 == HIGH) {
client.print("On");
} else {
client.print("Off");
}
client.println("
");
client.println("<a href=\"/LED2=ON\"\"><button>Turn On ledRosu</button></a>");
client.println("<a href=\"/LED2=OFF\"\"><button>Turn Off ledRosu</button></a>
");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}
//ledAlbastru
client.print("ledAlbastru is now: ");
if(value3 == HIGH) {
client.print("On");
} else {
client.print("Off");
}
client.println("
");
client.println("<a href=\"/LED3=ON\"\"><button>Turn On ledAlbastruu</button></a>");
client.println("<a href=\"/LED3=OFF\"\"><button>Turn Off ledAlbastru</button></a>
");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
Web_Server_Led2:143: error: 'client' does not name a type
client.print("ledAlbastru is now: ");
^
Web_Server_Led2:145: error: expected unqualified-id before 'if'
if(value3 == HIGH) {
^
Web_Server_Led2:147: error: expected unqualified-id before 'else'
} else {
^
Web_Server_Led2:150: error: 'client' does not name a type
client.println("
");
^
Web_Server_Led2:151: error: 'client' does not name a type
client.println("<a href="/LED3=ON"">Turn On ledAlbastruu");
^
Web_Server_Led2:152: error: 'client' does not name a type
client.println("<a href="/LED3=OFF"">Turn Off ledAlbastru
");
^
Web_Server_Led2:153: error: 'client' does not name a type
client.println("");
^
Web_Server_Led2:155: error: expected constructor, destructor, or type conversion before '(' token
delay(1);
^
Web_Server_Led2:156: error: 'Serial' does not name a type
Serial.println("Client disonnected");
^
Web_Server_Led2:157: error: 'Serial' does not name a type
Serial.println("");
^
Thanks for your attention and have a nice day!