fatal error: ESP8266WiFi.h: No such file or directory

Publish date: 2024-03-26

I'm trying to make a "home weight" with my ESP32 and display the value using IBMCloud, however I'm running into some issues with the Arduino IDE and my code.

I get this error:

Arduino:1.8.5 (Windows 10), Tarjeta:"ESP32 Dev Module, QIO, 80MHz, 4MB (32Mb), 921600, None"

C:\Users\XX\Documents\Arduino\IBM_Watson_Connect\IBM_Watson_Connect.ino:8:25: fatal error: ESP8266WiFi.h: No such file or directory

compilation terminated.

exit status 1 Compiling error for the ESP32 Dev Module card.

I'm using a ESP32 dev board. My code is this:

 #include <ESP8266WiFi.h> #include <PubSubClient.h> // https://github.com/knolleary/pubsubclient/releases/tag/v2.3 #include "HX711.h" //Load Cell Amplifier HX711 cell(D2, D4); //Amplifier is connected to these pins on the NodeMCU ESP8266 Board #define WLAN_SSID "XXXXX" #define WLAN_PASS "XXXXX" #define ORG "XXXXX" #define DEVICE_TYPE "XXXXXX" #define DEVICE_ID "XXXXX" #define TOKEN "XXXXXXXX" char server[] = ORG ".messaging.internetofthings.ibmcloud.com"; char topic[] = "iot-2/evt/status/fmt/json"; char authMethod[] = "use-token-auth"; char token[] = TOKEN; char clientId[] = "d:" ORG ":" DEVICE_TYPE ":" DEVICE_ID; WiFiClient wifiClient; PubSubClient client(server, 1883, NULL, wifiClient); void setup() { Serial.begin(115200); Serial.println(); // Connect to WiFi access point. Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(WLAN_SSID); WiFi.begin(WLAN_SSID, WLAN_PASS); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); } int counter = 0; void loop() { if (!!!client.connected()) { Serial.print("Reconnecting client to "); Serial.println(server); while (!!!client.connect(clientId, authMethod, token)) { Serial.print("."); delay(500); } Serial.println(); } //----------Get data from load cell and amplifier long valCalibrated = 0; long val = 0; float count = 0; count = count + 1; val = 0.5 * val + 0.5 * cell.read(); valCalibrated = (val - 4137240) / 234.20; //----------Send data to IBM Waton IoT Service String payload = "{\"d\":{\"weight\":"; payload += valCalibrated; payload += "}}"; Serial.print("Sending payload: "); Serial.println(payload); if (client.publish(topic, (char*) payload.c_str())) { Serial.println("Publish ok"); } else { Serial.println("Publish failed"); } ++counter; delay(100); //adjust delay to send more or less reads per unit time } 

Some places mentioned that the library was missing, that the board wasn't properly selected, the library wasn't updated.. I checked them all.. Arduino is updated, libraries are installed and updated, proper board is selected (I actually have tried all the other Esp32 related boards with the same result)

5

1 Answer

You're building a program for the ESP32, not the ESP8266. There are a lot of similarities but they're entirely different chips with different software.

So you don't use ESP8266WiFi.h with the ESP32. On the ESP32, the header file is just called WiFi.h (keeping more in line with WiFi support on Arduinos - the ESP32 Arduino Core is intended to be more compatible with the normal Arduino Core than the ESP8266 version was).

You need to

#include <WiFi.h> 

instead of ESP8266WiFi.h

You can find the code for these files in the official repository for the Arduino SDK for the ESP32.

(It doesn't help that WiFi.h for the ESP32 identifies itself as ESP8266.h in its own comments...)

10

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobGppaGt9dX6On5itmZxisrO%2BzqtknqugbX93gtainaJlmGK7sHnSrpqhZZaeuaZ5zqtknaGimrC1u9Gy