ESP8266WiFi .h file and many more missing

hey guys,

I am using a small esp8266 module and a arduino mega 2560 r3.
When I compile a script I got the error that ESPWiFi.h was massing.
So I installed that.
But after doing that there are new ".h" file missing errors.
After fixing one of them there is instantly one more.
Here is an error message example:

Arduino: 1.8.19 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from C:\Users\km085\Downloads\esp4\esp4.ino:1:0:

C:\Users\km085\Documents\Arduino\libraries\ESP8266WiFi\src/ESP8266WiFi.h:28:10: fatal error: wl_definitions.h: No such file or directory

#include <wl_definitions.h>

      ^~~~~~~~~~~~~~~~~~

compilation terminated.

exit status 1

Error compiling for board Arduino Mega or Mega 2560.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Example end:

I hope you can help me. I am sure that it isn't a hardware problem.
Since so many ".h" files are shown missing I think that there is maybe something wrong with my instalation.
Thanks to everyone deciding to help me.

 Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

When you have the Mega set as the target board the ESP8266 specific libraries will not be available and would not work even if they were

Please explain exactly which board you are trying to program, post the full sketch that you are trying to upload and please use code tags when you do

And install the esp8266 core.

Thank you for your response.

#include <ESP8266WiFi.h>

const char* ssid = "xxxx";
const char* password = "yyyy";
const char* host = "api.thingspeak.com";

WiFiClient client;

void setup() {
    Serial.begin(115200);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
        delay(1000);
        Serial.println("Connecting to WiFi...");
    }
    Serial.println("Connected to WiFi");
}

void loop() {
    int analogValue = analogRead(A0);

    String postStr = "field1=";
    postStr += String(analogValue);

    if (client.connect(host, 80)) {
        client.println("POST /update HTTP/1.1");
        client.println("Host: api.thingspeak.com");
        client.println("Connection: close");
        client.println("X-THINGSPEAKAPIKEY: zzzz");
        client.println("Content-Type: application/x-www-form-urlencoded");
        client.print("Content-Length: ");
        client.println(postStr.length());
        client.println();
        client.print(postStr);
        client.stop();
    }

    delay(15000);
}

I try to program the ESP to make it send sensor data from Analog Pin 0 to a ThingSpeak website.
I upload it to mega because I am getting no connection to the ESP when I use it as a board. When I select the "Generic ESP8266" as my device I can compile the code.

// Edit
Removed possibly sensitive data

Do you mean the ESP8266 libary from ESP8266 Community?

I've removed possibly sensitive data from your code. If those were real credentials, please do not post them again for your own good.

The code will never compile with the Mega selected as the target board. The first thing that you need to fix is the USB connection to the ESP. What happens when you plug in the ESP to a USB port ? Does your Operating System recognise it ? Does it show up in Device Manager or the equivalent of it for your OS ?

Thank you

I am using one of these tiny ESPs which don't come with a USB port and I don't have a adaptor.
Thats the error message I get when trying to connect to the esp module directly.

Arduino: 1.8.19 (Windows 10), Board: "Generic ESP8266 Module, 80 MHz, Flash, Disabled, All SSL ciphers (most compatible), ck, 26 MHz, 40MHz, DOUT (compatible), 512K (no SPIFFS), 2, nonos-sdk 2.2.1 (legacy), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

Sketch uses 273308 bytes (54%) of program storage space. Maximum is 499696 bytes.

Global variables use 27032 bytes (32%) of dynamic memory, leaving 54888 bytes for local variables. Maximum is 81920 bytes.

esptool.py v2.6

2.6

esptool.py v2.6

Serial port COM3

Connecting........_____....._____....._____....._____....._____....._____.....____Traceback (most recent call last):

  File "C:\Users\xxxxx\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2/tools/upload.py", line 25, in <module>

    esptool.main(fakeargs)

  File "C:/Users/xxxxx/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 2653, in main

    esp.connect(args.before)

  File "C:/Users/xxxxx/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 468, in connect

    raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))

esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header

esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header

If you don't have a USB to Serial adapter then exactly how are you connecting the ESP to the PC ?

Are you trying to program the ESP using the Mega as a programmer ?

Exactly. Should I get a adapter?

We have finally established what you are trying to do. It would have helped if you had said that in the first place

Please post a diagram of how you have the ESP, Mega and PC are wired together when programming the ESP. A photo of a hand drawn circuit is good enough

If you are following instructions from the Web then please post a link to them

I didn't follow particular instructions.

Those shields include the level shifting, but to upload firmware (a sketch) to the ESP, GPIO 0 needs to be pulled LOW at boot, and there is no connection for that on the shield. Best is to add a switch or a jumper and solder a connection to the shield.

There is 2 ways to then upload a sketch. Either you disable the Mega's UART and connect the ESP to Mega RX to RX & TX to TX (using the Mega's USB to TTL )

Or you can leave TX/RX connections as they are, find the SerialPassThrough example from the IDE (examples->communication->SerialPassThrough
and change both baudrates to 115200(upload speed for the ESP) and upload it to the Mega.
And then you try to upload to the ESP Through the Mega's UART's

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.