I am trying to follow the instructions in the web site
My ESP32 is identical to the one in the picture at the top of the page.
I have followed all the instructions but when I try to compile the sketch I get
'ESP8266WiFi.h no such file or directory'
It says to use the Node MCU 1.0(esp12-e) module but doesn't see the esp8266wifi file. If I use a wifi board it still fails to see the ESP8266wifi.h file so I assume it is not a board selection problem.
I can't find the ESP32WiFi.h file on my computer but then I can't see the ESP32.h file either unless they are in the master library files.
I can't find any reference to loading the ESP8266WiFi.h file other than this one
which makes it look as if it is in the master files and won't let me add the ESP8266wifi.h file anyway.
Can anyone see what I am doing wrong?
If you have a ESP8266, then follow tutorials about the ESP8266.
If you have a ESP32, then follow tutorials about the ESP32.
Forget the Instructables website, go to this website: https://randomnerdtutorials.com/
Yes, my error it is an ESP8266 as everything else in the thread is including the title.
I went through the instructions on the web page, very informative but it has nothing to do with the fact that I don't have ESP8266WiFi.h in my computer.
I altered ESP8266WiFi.h to WiFi.h in the sketch and it said I don't even have that?
I added it from the Library Manager (WiFi by arduino).
When I tried to compile I got 'Compilation error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
for the line WiFi.begin(ssid, password);
I found a WiFiEsp in the Library manager and loaded that.
Altered #include <WiFi.h> to WiFiEsp.h and this time compiling gave me
'Compilation error: 'WiFiServer' does not name a type; did you mean 'WiFiEspServer'?'
If I change that to WiFiEspServer and/or WiFiEspClient I just get
'Compilation error: exit status 1'.
From there I am lost.
#include<WiFiEsp.h>
//#include<WiFi.h>
const char* ssid = "Tenda"; //your WiFi Name
const char* password = "12345678"; //Your Wifi Password
int ledPin = 03;
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
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");
server.begin();
Serial.println("Server started");
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
WiFiClient client = server.available();
if (!client) {
return;
}
Serial.println("new client");
while(!client.available()){
delay(1);
}
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
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;
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("");
client.println("");
client.println("");
client.print("Led is : ");
if(value == HIGH) {
client.print("On");
} else {
client.print("Off");
} client.println("");
client.println(" On ");
client.println(" Off ");
client.println(" ");
delay(1);
Serial.println("Client disonnected");
Serial.println(""); }
Where can I get that?
I loaded WiFiEsp 2.2.2
I now have a whole load of esp8266 library files.
I changed lines 3 and 4 from const char to char in the sketch and the sketch loads in with just wifi.h but still fails with Esp8266WiFi.h .
I altered the ssid and password to mine and now the monitor is sat saying
'connecting to "my ssid"
My phone connects fine so I am wondering if I still have something missing.
I already have this added.
I am using version 2.3.0
If I go to the Library manager and search for ESP8266 I get hundreds of entries including lots that don't include esp8266 in the title
If you can see the picture look how small the 'total size box' is down the right side. There is no entry just called Esp8266 ?
The compile page still shows the red entry
H:\My Drive\Arduino files\lolinwifi\lolinwifi.ino:4:18: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
for the two ssid and password lines
but still passes and loads to the esp8266
Hmm, that is the first thing I did when I set out on this but it failed to work because I didn't have the correct libraries in I assume. I have just tried it again and it works, or at least i get 'LED is : Off On Off' on the web page.
My LED doesn't change?
I assume I need to add an LED between pin 9 (the rx pin) and gnd (via a resistor)?
I have done this .
My board has the reset button broken (snapped off) so I am momentarily touching a wire between RST and gnd to reset it, the LED on pin 9 flashes as well as the one on the board when I do this but I can't see how to change it otherwise?
Can you see what I am missing?
How interesting, I can see no difference between the two sketches apart from the extra comments in the second one and the four lines almost at the end that add two buttons to the web page, (makes it much better) but the second one fails to connect, I have tried it many times always with the same result?
I now have two buttons on the web page that turn the led on and off.
#include<ESP8266WiFi.h>
const char* ssid = "1"; //your WiFi Name
const char* password = "1"; //Your Wifi Password
int ledPin = 03;
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
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");
server.begin();
Serial.println("Server started");
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop()
{
WiFiClient client = server.available();
if (!client)
{
return;
}
Serial.println("new client");
while(!client.available())
{
delay(1);
}
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
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;
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("");
client.println("");
client.println("");
client.print("Led is : ");
if(value == HIGH)
{
client.print("On");
} else
{
client.print("Off");
}
client.println("<br><br>");
client.println("<a href=\"/LED=ON\"\"><button>Turn On </button></a>");
client.println("<a href=\"/LED=OFF\"\"><button>Turn Off </button></a><br />");
client.println("</html>");
// client.println("");
// client.println(" On ");
// client.println(" Off ");
// client.println(" ");
delay(1);
Serial.println("Client disconnected");
Serial.println("");
}
#include <ESP8266WiFi.h>
const char* ssid = "1";
const char* password = "1";
int ledPin = 03;
//int ledPin = 16;
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");
}
// HTML for buttons to work LED
client.println("<br><br>");
client.println("<a href=\"/LED=ON\"\"><button>Turn On </button></a>");
client.println("<a href=\"/LED=OFF\"\"><button>Turn Off </button></a><br />");
client.println("</html>");
delay(1);
Serial.println("Client disconnected");
Serial.println("");
}
Can anyone see the reason why the first one connects and second one doesn't?
Probably it is the missing opening html tag specifically that is the cause (you might be able to get away with skipping the !DOCTYPE declaration even though you should have one).
No, I am fairly sure that is not the problem, all that would do is alter the appearance of the web page.
It is the top sketch that doesn't have the lines
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print("Led pin is now: ");
in it that works.
I did just add the lines to the first one to see if it made any difference and remove them from the second sketch to try that but the second sketch still failed and the first sketch still worked.
I think it is the area around