Cannot #include <ESP8266WiFi.h>

When I include the ESP8266WiFi.h , it will show the error code is

In file included from C:\Users\phat\Documents\Arduino\libraries\ESP8266WiFi\src/ESP8266WiFiSTA.h:28:0,

from C:\Users\phat\Documents\Arduino\libraries\ESP8266WiFi\src/ESP8266WiFi.h:34,

from C:\Users\phat\AppData\Local\Temp\arduino_modified_sketch_812963\sketch_sep15a.ino:1:

C:\Users\phat\Documents\Arduino\libraries\ESP8266WiFi\src/ESP8266WiFiGeneric.h:27:22: fatal error: functional: No such file or directory

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.

This is my code,

#include <dht.h>
dht DHT;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define DHT21_PIN 2

float hum;
float temp;

LiquidCrystal_I2C lcd(0x27,16,2);// PCF8574A = 0x3F

void setup() {
lcd.begin();
lcd.home();
lcd.print("AGRI CO.,LTD");
lcd.setCursor(0,1);
lcd.print("Temp&RH%");
lcd.setCursor(0,2);
delay(3000);

Serial.begin(9600);

}

void loop() {
lcd.clear();
lcd.setCursor(0, 0);
int chk = DHT.read21(DHT21_PIN);
hum = DHT.humidity;
temp= DHT.temperature;
lcd.setCursor(0, 0);
lcd.print("Humi ");
lcd.print(hum);
lcd.print(" %");

lcd.setCursor(45, 0);
lcd.print("Temp ");
lcd.print(temp);
lcd.print(" C");

Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" % ");
Serial.print(temp);
Serial.println(" C");

delay(10000);

}

now, I can use lcd to show the Humidity&Temperature already then I would like to use esp8266-01 to send the humidity&temperature data to google sheet. For the google script, I have done but the arduino code still have the problem.

Thank you

The ESP8266WiFi library is written specifically for directly programming the ESP8266. It is part of the ESP8266 core for Arduino. You can't just chop the library out of the core and compile it for the Uno. That will never work.

If you are actually trying to directly program and ESP8266 then you need to select the correct board from the Tools > Board menu. If you are really trying to program an Uno then you can't use the library.

I would like to send the temp&humidity to google sheet but it doesn't work. I cannot include esp8266wifi.h in the arduino ide for arduino uno so I have read and see the suggestion which is use the wifiesp.h instead. and still doesn't work.

My code is this

#include <WiFiEsp.h>
#include <WiFiEspClient.h>
#include <WiFiEspServer.h>
#include <WiFiEspUdp.h>
#include <dht.h>
dht DHT;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define DHT21_PIN 2

float hum;  
float temp;

LiquidCrystal_I2C lcd(0x27,16,2);

char ssid[] = "APIWIFI";            
char pass[] = "phatcharapon";        
const int buttonPin = 2;          
int buttonState;                  
int lastButtonState = LOW;       

const char* host = "script.google.com";
const char *GScriptId = "";

const int httpsPort = 443;
WiFiEspClient client;
int status = WL_IDLE_STATUS;     // the Wifi radio's status
const char* fingerprint = "46 B2 C3 44 9C 59 09 8B 01 B6 F8 BD 4C FB 00 74 91 2F EF F6";

double it;
double ih;

void setup() {
   lcd.begin();
lcd.home();
lcd.print("AGRI CO.,LTD");
lcd.setCursor(0,1);
lcd.print("Temp&RH%");
lcd.setCursor(0,2);
delay(3000);

  Serial.begin(9600);
  Serial.begin(115200);

  
}

void loop() {
 lcd.clear();
  lcd.setCursor(0, 0);
  int chk = DHT.read21(DHT21_PIN);
  hum = DHT.humidity;
  temp= DHT.temperature;
  lcd.setCursor(0, 0);
  lcd.print("Humi ");
  lcd.print(hum);
  lcd.print(" %");
  
  lcd.setCursor(45, 0);
  lcd.print("Temp ");
  lcd.print(temp);
  lcd.print(" C");
  
  

  

  Serial.print("Humidity: ");
  Serial.print(hum);
  Serial.print(" % ");
  Serial.print(temp);
  Serial.println(" C");

   it = (double) temp;
   ih = (double) hum;
  

  delay(10000);
  }
void sendData(double temp, double hum)
{
  
  String string_temperature =  String(temp, DEC); 
  String string_humidity =  String(hum, DEC); 
  String url = String("/macros/s/") + GScriptId + "/exec?temperature=" + string_temperature + "&humidity=" + string_humidity;
  //String url = "/macros/s/" + GAS_ID + "/exec?temperature=" + string_temperature + "&humidity=" + string_humidity;
  Serial.print("requesting URL: ");
  Serial.println(url);
  client.print(String("GET /") + " HTTP/1.1\r\n" +
             "Host: " + host + "\r\n" +
             "Connection: close\r\n" +
             "\r\n"
            );
  while (client.connected()) {
  String line = client.readStringUntil('\n');
  }
 
    Serial.println("headers received");
}

phatcharapon:
still doesn't work.

Do you really think anyone will be able to help you based on such an incredibly vague description of your problem?

Sorry for bad explanation Mr.Pert

I have watch this video "Arduino: Log sensor data in the cloud - YouTube" which is sending the temp&humidity to google sheet. Esp8266wifi.h is used in the video but I cannot use for my project. Now I know that the video use ESP8266-12 but I use ESP8266-01 connect to arduino uno so it is different. Now I would like to ask you what is the code to be changed for my project.

The APIs of those libraries are fairly similar. I'd start by getting familiar with some of the example sketches under File > Examples > WiFiEsp. The WebServer examples are a good place to start. That way you can make sure things are working with known-good code before you start messing with porting your own code to WiFiEsp. Once you understand how the library is used with the example sketches, I think it will be easy enough to update your own code.

I have tried the example sketches under file File>Examples?WiFiEsp. I got the error

[WiFiEsp] Initializing ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Cannot initialize ESP module
[WiFiEsp] >>> TIMEOUT >>>
12:03:57.545 -> [WiFiEsp] No tag found
12:03:57.545 -> ********************************************** Check status WL_DISCONNECTED > FAILED (actual=255, expected=3)
12:03:57.579 -> 
[WiFiEsp] >>> TIMEOUT >>>
12:04:27.596 -> [WiFiEsp] Failed connecting to APIWIFI
********************************************** Connect > FAILED (actual=2, expected=1)
12:04:28.591 -> 
[WiFiEsp] >>> TIMEOUT >>>
12:04:39.619 -> [WiFiEsp] No tag found
12:04:39.619 -> ********************************************** Check status WL_CONNECTED > FAILED (actual=255, expected=1)
12:04:39.619 -> 
[WiFiEsp] >>> TIMEOUT >>>
12:04:50.635 -> [WiFiEsp] No tag found
12:04:50.668 -> IP Address: 0.0.0.0
[WiFiEsp] >>> TIMEOUT >>>
12:04:58.652 -> ********************************************** Ping > FAILED (actual=0, expected=1)
12:04:58.652 -> 
********************************************** Not connected > PASSED
12:05:08.678 -> 
12:05:08.678 -> [WiFiEsp] Connecting to www.brainjar.com
[WiFiEsp] >>> TIMEOUT >>>

Can you please explain me about the wire connected , for me , I connected the esp8266-01 like this

Rx => Pin 6
Tx => Pin 7
Vcc+Ch_PD => 3.3v
GND => GND

I think the example sketch provide the same so the different is my wiring.

phatcharapon:
Rx => Pin 6
Tx => Pin 7

This is wrong. You need to make the connection RX-TX, TX-RX but instead you have it connected RX-RX, TX-TX.

The reason for RX-TX, TX-RX is RX stands for "receive" and TX stands for "transmit".

After that, the other problem you'll likely encounter is that the AT firmware on your ESP8266 defaults to communication at 115200 but the WiFiEsp example sketches set the communication to 9600 baud:

  // initialize serial for ESP module
  Serial1.begin(9600);

So why would they do that? The reason is that the SoftwareSerial library won't work reliably at 115200 baud. The solution is to use the proper AT command to set the ESP8266 to communicate at 9600 baud.

I connected Rx => Pin 7 ,Tx => Pin 6 already but still have the same error

pert:
After that, the other problem you'll likely encounter is that the AT firmware on your ESP8266 defaults to communication at 115200 but the WiFiEsp example sketches set the communication to 9600 baud:

  // initialize serial for ESP module

Serial1.begin(9600);



So why would they do that? The reason is that the SoftwareSerial library won't work reliably at 115200 baud. The solution is to use the proper AT command to set the ESP8266 to communicate at 9600 baud.

There is the code in the example sketch but I complie it and get the error

#include "WiFiEsp.h"

// Emulate Serial1 on pins 7/6 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif


char ssid[] = "APIWIFI";     // your network SSID (name)
char pwd[] = "phatcharapon";  // your network password


// Initialize the Wifi client library
WiFiEspClient client;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(9600);
  WiFi.init(&Serial1);
}

void loop()
{
  bool f;
  int c;

  
  assertEquals("Check status WL_DISCONNECTED", WiFi.status(), WL_DISCONNECTED);
  
  assertEquals("Connect", WiFi.begin(ssid, pwd), WL_CONNECTED);
  
  assertEquals("Check status WL_CONNECTED", WiFi.status(), WL_CONNECTED);
  
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  
  assertEquals("Ping", WiFi.ping("www.google.com"), true);
  
  assertEquals("Not connected", client.connected(), false);
  assertEquals("Connect to server", client.connect("www.brainjar.com", 80), 1);
  assertEquals("Connected", client.connected(), true);


  //--------------------------------------------------------------
  // HTTP request without 'Connection: close' command
  
  client.println("GET /java/host/test.html HTTP/1.1");
  client.println("Host: www.brainjar.com");
  client.println();

  // wait for the response
  long _startMillis = millis();
  while (!client.available() and (millis()-_startMillis < 2000))
  {
  }
  
  assertEquals("Response received", (millis()-_startMillis < 2000), true);
  
  f = client.find("<html>");
  assertEquals("Response check", f, true);
  if (f)
  {
    while( (c = client.read()) > 0)
      Serial.print((char)c);
  }

  assertEquals("Connected", client.connected(), true);


  //--------------------------------------------------------------
  
  delay(5000);
  
  assertEquals("Check status WL_CONNECTED", WiFi.status(), WL_CONNECTED);

  assertEquals("Connected", client.connected(), true);


  //--------------------------------------------------------------
  // HTTP request without 'Connection: close' command
  
  client.println("GET /java/host/test.html HTTP/1.1");
  client.println("Host: www.brainjar.com");
  client.println("Connection: close");
  client.println();


  // wait for the response
  _startMillis = millis();
  while (!client.available() and (millis()-_startMillis < 2000))
  {
  }
  
  assertEquals("Response received", (millis()-_startMillis < 2000), true);
  
  f = client.find("<html>");
  assertEquals("Response check", f, true);
  if (f)
  {
    while( (c = client.read()) > 0)
      Serial.print((char)c);
  }

  //--------------------------------------------------------------
  
  assertEquals("Check status WL_CONNECTED", WiFi.status(), WL_CONNECTED);
  assertEquals("Not connected", client.connected(), false);

  assertEquals("Ping", WiFi.ping("www.google.com"), true);

  assertEquals("Connect", WiFi.disconnect(), WL_DISCONNECTED);
  assertEquals("Check status WL_DISCONNECTED", WiFi.status(), WL_DISCONNECTED);

  Serial.println("END OF TESTS");
  delay(30000);
}


////////////////////////////////////////////////////////////////////////////////////


void assertEquals(const char* test, int actual, int expected)
{
  if(actual==expected)
    pass(test);
  else
    fail(test, actual, expected);
}

void assertEquals(const char* test, char* actual, char* expected)
{
  if(strcmp(actual, expected) == 0)
    pass(test);
  else
    fail(test, actual, expected);
}


void pass(const char* test)
{
  Serial.print(F("********************************************** "));
  Serial.print(test);
  Serial.println(" > PASSED");
  Serial.println();
}

void fail(const char* test, char* actual, char* expected)
{
  Serial.print(F("********************************************** "));
  Serial.print(test);
  Serial.print(" > FAILED");
  Serial.print(" (actual=\"");
  Serial.print(actual);
  Serial.print("\", expected=\"");
  Serial.print(expected);
  Serial.println("\")");
  Serial.println();
  delay(10000);
}

void fail(const char* test, int actual, int expected)
{
  Serial.print(F("********************************************** "));
  Serial.print(test);
  Serial.print(" > FAILED");
  Serial.print(" (actual=");
  Serial.print(actual);
  Serial.print(", expected=");
  Serial.print(expected);
  Serial.println(")");
  Serial.println();
  delay(10000);
}

What error?

the same error

[WiFiEsp] Initializing ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Cannot initialize ESP module
[WiFiEsp] >>> TIMEOUT >>>
18:58:17.810 -> [WiFiEsp] No tag found
18:58:17.810 -> ********************************************** Check status WL_DISCONNECTED > FAILED (actual=255, expected=3)
18:58:17.845 -> 
[WiFiEsp] >>> TIMEOUT >>>
18:58:47.862 -> [WiFiEsp] Failed connecting to APIWIFI
********************************************** Connect > FAILED (actual=2, expected=1)
18:58:48.857 -> 
[WiFiEsp] >>> TIMEOUT >>>
18:58:59.884 -> [WiFiEsp] No tag found
18:58:59.884 -> ********************************************** Check status WL_CONNECTED > FAILED (actual=255, expected=1)
18:58:59.884 -> 
[WiFiEsp] >>> TIMEOUT >>>
18:59:10.888 -> [WiFiEsp] No tag found
18:59:10.923 -> IP Address: 0.0.0.0
[WiFiEsp] >>> TIMEOUT >>>
18:59:18.916 -> ********************************************** Ping > FAILED (actual=0, expected=1)
18:59:18.916 -> 
********************************************** Not connected > PASSED
18:59:28.936 -> 
18:59:28.936 -> [WiFiEsp] Connecting to www.brainjar.com
[WiFiEsp] >>> TIMEOUT >>>
18:59:33.972 -> ********************************************** Connect to server > FAILED (actual=0, expected=1)
18:59:33.972 ->

Did you change the communication speed of the ESP8266's AT firmware to 9600 baud?

pert:
Did you change the communication speed of the ESP8266's AT firmware to 9600 baud?

I cannot use 9600 baud. If I change to 9600 baud the serial monitor show "⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮Ұ⸮⸮⸮⸮⸮җ⸮x⸮⸮⸮X⸮⸮⸮K+⸮ǰY⸮I⸮⸮r%PM⸮<⸮8⸮⸮⸮\⸮" like this

NO!!! Please read what I wrote twice already:

pert:
After that, the other problem you'll likely encounter is that the AT firmware on your ESP8266 defaults to communication at 115200 but the WiFiEsp example sketches set the communication to 9600 baud:

  // initialize serial for ESP module

Serial1.begin(9600);



So why would they do that? The reason is that the SoftwareSerial library won't work reliably at 115200 baud. The solution is to use the proper AT command to set the ESP8266 to communicate at 9600 baud.

Sorry but I just don't have the patience for this right now. Maybe someone else here will jump in and help you out. Otherwise, there's always Google. There are plenty of tutorials available on this topic.

/*
 WiFiEsp test: ClientTest
 
 Test client functions.
*/

#include "WiFiEsp.h"

// Emulate Serial1 on pins 7/6 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif


char ssid[] = "APIWIFI";     // your network SSID (name)
char pwd[] = "phatcharapon";  // your network password


// Initialize the Wifi client library
WiFiEspClient client;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(9600);
  WiFi.init(&Serial1);
}

void loop()
{
  bool f;
  int c;

  
  assertEquals("Check status WL_DISCONNECTED", WiFi.status(), WL_DISCONNECTED);
  
  assertEquals("Connect", WiFi.begin(ssid, pwd), WL_CONNECTED);
  
  assertEquals("Check status WL_CONNECTED", WiFi.status(), WL_CONNECTED);
  
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  
  assertEquals("Ping", WiFi.ping("www.google.com"), true);
  
  assertEquals("Not connected", client.connected(), false);
  assertEquals("Connect to server", client.connect("www.brainjar.com", 80), 1);
  assertEquals("Connected", client.connected(), true);


  //--------------------------------------------------------------
  // HTTP request without 'Connection: close' command
  
  client.println("GET /java/host/test.html HTTP/1.1");
  client.println("Host: www.brainjar.com");
  client.println();

  // wait for the response
  long _startMillis = millis();
  while (!client.available() and (millis()-_startMillis < 2000))
  {
  }
  
  assertEquals("Response received", (millis()-_startMillis < 2000), true);
  
  f = client.find("<html>");
  assertEquals("Response check", f, true);
  if (f)
  {
    while( (c = client.read()) > 0)
      Serial.print((char)c);
  }

  assertEquals("Connected", client.connected(), true);


  //--------------------------------------------------------------
  
  delay(5000);
  
  assertEquals("Check status WL_CONNECTED", WiFi.status(), WL_CONNECTED);

  assertEquals("Connected", client.connected(), true);


  //--------------------------------------------------------------
  // HTTP request without 'Connection: close' command
  
  client.println("GET /java/host/test.html HTTP/1.1");
  client.println("Host: www.brainjar.com");
  client.println("Connection: close");
  client.println();


  // wait for the response
  _startMillis = millis();
  while (!client.available() and (millis()-_startMillis < 2000))
  {
  }
  
  assertEquals("Response received", (millis()-_startMillis < 2000), true);
  
  f = client.find("<html>");
  assertEquals("Response check", f, true);
  if (f)
  {
    while( (c = client.read()) > 0)
      Serial.print((char)c);
  }

  //--------------------------------------------------------------
  
  assertEquals("Check status WL_CONNECTED", WiFi.status(), WL_CONNECTED);
  assertEquals("Not connected", client.connected(), false);

  assertEquals("Ping", WiFi.ping("www.google.com"), true);

  assertEquals("Connect", WiFi.disconnect(), WL_DISCONNECTED);
  assertEquals("Check status WL_DISCONNECTED", WiFi.status(), WL_DISCONNECTED);

  Serial.println("END OF TESTS");
  delay(30000);
}


////////////////////////////////////////////////////////////////////////////////////


void assertEquals(const char* test, int actual, int expected)
{
  if(actual==expected)
    pass(test);
  else
    fail(test, actual, expected);
}

void assertEquals(const char* test, char* actual, char* expected)
{
  if(strcmp(actual, expected) == 0)
    pass(test);
  else
    fail(test, actual, expected);
}


void pass(const char* test)
{
  Serial.print(F("********************************************** "));
  Serial.print(test);
  Serial.println(" > PASSED");
  Serial.println();
}

void fail(const char* test, char* actual, char* expected)
{
  Serial.print(F("********************************************** "));
  Serial.print(test);
  Serial.print(" > FAILED");
  Serial.print(" (actual=\"");
  Serial.print(actual);
  Serial.print("\", expected=\"");
  Serial.print(expected);
  Serial.println("\")");
  Serial.println();
  delay(10000);
}

void fail(const char* test, int actual, int expected)
{
  Serial.print(F("********************************************** "));
  Serial.print(test);
  Serial.print(" > FAILED");
  Serial.print(" (actual=");
  Serial.print(actual);
  Serial.print(", expected=");
  Serial.print(expected);
  Serial.println(")");
  Serial.println();
  delay(10000);
}

I have done what you wrote twice already but still have the error. You can see my sketch that I do

  // initialize serial for ESP module
  Serial1.begin(9600);

Already

@phatcharapon, It is not "plug and play".

you need to send to AT firmware a command to set the default baud rate of the AT firmware to 9600. To do that you need to connect the esp8266 module directly to computer over USB. To do that you need an USB-to-TTL adapter or to know how to use the adapter on the Uno. The Internet is full of tutorials about using esp8266.

What esp8266 module do you have?