# ESP32:MqttHive:1:25: fatal error: ESP8266WiFi.h: No such file or directory

**URL:** <https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283>\
**Category:** HiveMQ Community Edition\
**Created:** [June 28, 2022, 10:23am UTC](https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283 "2022-06-28T10:23:15Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![shararku](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@shararku](https://community.hivemq.com/u/shararku)\
**Post date:** [June 28, 2022, 10:23am UTC](https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283/1 "2022-06-28T10:23:15Z")

</div>

Hello,  
after generating the certs.ar and Image Uploaded I am getting this error from my ESP32 board:  
"Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: “ESP32 Dev Module …  
MqttHive:1:25: fatal error: ESP8266WiFi.h: No such file or directory  
compilation terminated.  
exit status 1  
ESP8266WiFi.h: No such file or directory”  
How can i resolve this issue ?

---

<div class="post-metadata">

**Author:** ![Daria\_H](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@Daria\_H](https://community.hivemq.com/u/Daria_H)\
**Post date:** [June 28, 2022, 1:16pm UTC](https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283/2 "2022-06-28T13:16:19Z")

</div>

Hi @shararku ,

It seems that you are following the instructions for ESP8266 board, while you have ESP32 board. You need to replace all ESP8266-specific libraries with ESP32-specific ones.

Kind regards,  
Dasha from HiveMQ Team

---

<div class="post-metadata">

**Author:** ![shararku](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@shararku](https://community.hivemq.com/u/shararku)\
**Post date:** [June 28, 2022, 4:28pm UTC](https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283/3 "2022-06-28T16:28:47Z")

</div>

Hello HiveMQ,  
Thank you very much for your reply , I will try to follow your instructions and hopefully will solve the issue soon !  
Best wishes  
Sharar

---

<div class="post-metadata">

**Author:** ![shararku](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@shararku](https://community.hivemq.com/u/shararku)\
**Post date:** [June 29, 2022, 8:35am UTC](https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283/4 "2022-06-29T08:35:49Z")

</div>

Hello HiveMQ,

So i tried to “replace all ESP8266-specific libraries with ESP32-specific ones.” but i started to get more errors and more searches and google has no clue on how to go about it !  
I hope you could clarify which #include to replace with which or some pointer to where the solution could be found .  
Best wishes  
Sharar

---

<div class="post-metadata">

**Author:** ![Daria\_H](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@Daria\_H](https://community.hivemq.com/u/Daria_H)\
**Post date:** [June 29, 2022, 3:13pm UTC](https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283/5 "2022-06-29T15:13:44Z")

</div>

Hi @shararku ,

You indicated you get more errors - could you please be specific: what action you did, what error you got.

You can also try to run your code on ESP32 simulator like this: [sketch.ino - Wokwi Arduino and ESP32 Simulator](https://wokwi.com/projects/335813053795795538)

Kind regards,  
Dasha from HiveMQ Team

---

<div class="post-metadata">

**Author:** ![shararku](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@shararku](https://community.hivemq.com/u/shararku)\
**Post date:** [June 30, 2022, 8:20am UTC](https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283/6 "2022-06-30T08:20:18Z")

</div>

Hello HiveMQ,  
Thank you very much for your support but It looks like it is going to be a long, drawn out trial and error process so I better seek an alternative solution to my data needs.  
Should you finish developing an ESP32 example please let me know .  
Best wishes  
Sharar

---

<div class="post-metadata">

**Author:** ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://community.hivemq.com/u/Mike)\
**Post date:** [June 30, 2022, 4:32pm UTC](https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283/7 "2022-06-30T16:32:40Z")

</div>

Hi, Here a template for the ESP32 using WIFI to connect to the broker. Enjoy, just replace the XXXX with your value

#include \<WiFi.h\>  
#include \<PubSubClient.h\>  
#include \<WiFiClientSecure.h\>

//---- WiFi settings  
const char\* ssid = “XXXX”;  
const char\* password = “XXXX”;  
//---- MQTT Broker settings  
const char\* mqtt\_server = “XXXX”; // replace with your broker url  
const char\* mqtt\_username = “XXXX”;  
const char\* mqtt\_password = “XXXX”;  
const int mqtt\_port =8883;

WiFiClientSecure espClient;  
PubSubClient client(espClient);  
unsigned long lastMsg = 0;

#define MSG\_BUFFER\_SIZE (50)  
char msg[MSG\_BUFFER\_SIZE];

const char\* sensor1\_topic= “sensor1”;  
const char\* sensor2\_topic=“sensor2”;

static const char \*root\_ca PROGMEM = R"EOF(  
-----BEGIN CERTIFICATE-----  
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw  
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh  
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4  
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu  
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY  
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc  
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+  
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U  
A5/TR5d8mUgjU+g4rk8Kb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HpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc  
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq  
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA  
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d  
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=  
-----END CERTIFICATE-----  
)EOF";

void setup() {

Serial.begin(9600);  
Serial.print("\nConnecting to ");  
Serial.println(ssid);

WiFi.mode(WIFI\_STA);  
WiFi.begin(ssid, password);

while (WiFi.status() != WL\_CONNECTED) {  
delay(500);  
Serial.print(“.”);  
}  
randomSeed(micros());  
Serial.println("\nWiFi connected\nIP address: ");  
Serial.println(WiFi.localIP());

while (!Serial) delay(1);

espClient.setCACert(root\_ca);  
client.setServer(mqtt\_server, mqtt\_port);  
client.setCallback(callback);  
}

void loop() {

```
  if (!client.connected()) reconnect();
  client.loop();

publishMessage(sensor1_topic,String(XXXX),true);    
publishMessage(sensor2_topic,String(XXXX),true);

```

}

//=======================================================================Function=================================================================================

void reconnect() {  
// Loop until we’re reconnected  
while (!client.connected()) {  
Serial.print(“Attempting MQTT connection…”);  
String clientId = “ESP8266Client-”; // Create a random client ID  
clientId += String(random(0xffff), HEX);  
// Attempt to connect  
if (client.connect(clientId.c\_str(), mqtt\_username, mqtt\_password)) {  
Serial.println(“connected”);

```
  client.subscribe(command1_topic); // subscribe the topics here
  //client.subscribe(command2_topic); // subscribe the topics here
} else {
  Serial.print("failed, rc=");
  Serial.print(client.state());
  Serial.println(" try again in 5 seconds"); // Wait 5 seconds before retrying
  delay(5000);
}

```

}  
}

//=======================================  
// This void is called every time we have a message from the broker

void callback(char\* topic, byte\* payload, unsigned int length) {  
String incommingMessage = “”;  
for (int i = 0; i \< length; i++) incommingMessage+=(char)payload[i];  
Serial.println(“Message arrived [”+String(topic)+“]”+incommingMessage);  
// check for other commands  
/\* else if( strcmp(topic,command2\_topic) == 0){  
if (incommingMessage.equals(“1”)) { } // do something else  
}  
\*/  
}

//======================================= publising as string  
void publishMessage(const char\* topic, String payload , boolean retained){  
if (client.publish(topic, payload.c\_str(), true))  
Serial.println(“Message publised [”+String(topic)+"]: "+payload);  
}

---

<div class="post-metadata">

**Author:** ![shararku](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@shararku](https://community.hivemq.com/u/shararku)\
**Post date:** [July 1, 2022, 2:19pm UTC](https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283/8 "2022-07-01T14:19:53Z")

</div>

Hello Mike,  
Thanks alot for your help(code) i will try it soon but i have small problem with user name for the MQTT,once resolved i will test it .  
Best Regards  
Sharar

---

<div class="post-metadata">

**Author:** ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://community.hivemq.com/u/Mike)\
**Post date:** [July 4, 2022, 2:06pm UTC](https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283/9 "2022-07-04T14:06:44Z")

</div>

i did a small HOW TO on an other topic on how to use ESP32 with HIVEMQ and NODERED

there is more information there 🙂

Happy coding !

---

<div class="post-metadata">

**Author:** ![shararku](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@shararku](https://community.hivemq.com/u/shararku)\
**Post date:** [July 8, 2022, 9:24am UTC](https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283/10 "2022-07-08T09:24:04Z")

</div>

Hello Mike,  
I just tested your code but unfortunately it does not work ! I hope you can find a fix for it .  
Best wishes  
Sharar

"Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: “ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, None”

MqttHive2:8:1: error: stray ‘\342’ in program  
const char\* ssid = “Farxxxxxx”;  
^  
MqttHive2:8:1: error: stray ‘\200’ in program  
MqttHive2:8:1: error: stray ‘\234’ in program  
MqttHive2:8:1: error: stray ‘\342’ in program  
MqttHive2:8:1: error: stray ‘\200’ in program  
MqttHive2:8:1: error: stray ‘\235’ in program  
MqttHive2:9:1: error: stray ‘\342’ in program  
const char\* password = “xxxxxxxxx”;  
^  
MqttHive2:9:1: error: stray ‘\200’ in program  
MqttHive2:9:1: error: stray ‘\234’ in program  
MqttHive2:9:1: error: stray ‘\342’ in program  
MqttHive2:9:1: error: stray ‘\200’ in program  
MqttHive2:9:1: error: stray ‘\235’ in program  
MqttHive2:11:1: error: stray ‘\342’ in program  
const char\* mqtt\_server = “xxxxxxxxxxxxxxxxxxx.s1.eu.hivemq.cloud”; // replace with your broker url  
^  
MqttHive2:11:1: error: stray ‘\200’ in program  
MqttHive2:11:1: error: stray ‘\234’ in program  
MqttHive2:11:30: error: exponent has no digits  
const char\* mqtt\_server = “xxxxxxxxxxxxxxxxxxxxxx.s1.eu.hivemq.cloud”; // replace with your broker url  
^  
MqttHive2:11:1: error: stray ‘\342’ in program  
const char\* mqtt\_server = “xxxxxxxxxxxxxxxxxxxxxxx.s1.eu.hivemq.cloud”; // replace with your broker url  
^  
MqttHive2:11:1: error: stray ‘\200’ in program  
MqttHive2:11:1: error: stray ‘\235’ in program  
MqttHive2:12:1: error: stray ‘\342’ in program  
const char\* mqtt\_username = “hivexxxxx”;  
"

---

<div class="post-metadata">

**Author:** ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://community.hivemq.com/u/Mike)\
**Post date:** [July 8, 2022, 10:47am UTC](https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283/11 "2022-07-08T10:47:44Z")

</div>

Start by commenting everything and uncomment step by step

Start with the wifi then move on to the MQTT

Which ESP32 are you using ?

---

<div class="post-metadata">

**Author:** ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://community.hivemq.com/u/Mike)\
**Post date:** [July 8, 2022, 10:51am UTC](https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283/12 "2022-07-08T10:51:14Z")

</div>

The error 342 seem to be because this website has unicode

Give me an email and il send you the .ino

---

<div class="post-metadata">

**Author:** ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://community.hivemq.com/u/Mike)\
**Post date:** [July 15, 2022, 12:02pm UTC](https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283/13 "2022-07-15T12:02:41Z")

</div>

i shared a googleDrive link in my other post for the ino file

---

<div class="post-metadata">

**Author:** ![LuisPereira](https://avatars.discourse-cdn.com/v4/letter/l/9d8465/32.png) [@LuisPereira](https://community.hivemq.com/u/LuisPereira)\
**Post date:** [December 9, 2022, 4:25pm UTC](https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283/14 "2022-12-09T16:25:31Z")

</div>

Thank god and example for ESP32 and HiveMQ…altough its not working for me ^^  
I haven’t used the secure connection as Mike does, and I dont use the certificate, simply because I don’t know where to get that…cannot be the same for everyone right?  
Also, how come so many examples just use broker url as “[broker.hivemq.com](http://broker.hivemq.com)” and port 1883 ?

Thank you.  
Cheers, Luís Pereira.

---

<div class="post-metadata">

**Author:** ![Daria\_H](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@Daria\_H](https://community.hivemq.com/u/Daria_H)\
**Post date:** [December 14, 2022, 8:59am UTC](https://community.hivemq.com/t/esp321-fatal-error-esp8266wifi-h-no-such-file-or-directory/1283/15 "2022-12-14T08:59:38Z")

</div>

Hi @LuisPereira ,

Great that you are interested in MQTT and HiveMQ, welcome to the community!

[broker.hivemq.com](http://broker.hivemq.com) is a test broker, all data on it is public and visible to anybody, it is not using any SSL (TLS) and thus is easy to connect and run a test.

For getting started with HiveMQ Cloud please start by checking [Frequently Asked Questions](https://community.hivemq.com/t/frequently-asked-questions/514). You can download server CA from [here](https://letsencrypt.org/certs/isrgrootx1.pem). Note that in order to stable a connection to the HiveMQ Cloud cluster, your MQTT client must support and use [SSL-SNI extension](https://en.wikipedia.org/wiki/Server_Name_Indication) (server name indication).

I hope this helps

Regards,  
Dasha from HiveMQ team
