严重错误:ESP8266WiFi.h:没有这样的文件或目录

时间:2018-07-05 07:55:29

标签: fatal-error arduino-ide esp32

我试图用ESP32制作“家用砝码”,并使用IBMCloud显示该值,但是Arduino IDE和我的代码遇到了一些问题。

我收到此错误:

  

Arduino:1.8.5(Windows 10),Tarjeta:“ ESP32开发模块,QIO,80MHz,4MB(32Mb),921600,无”

     

C:\ Users \ XX \ Documents \ Arduino \ IBM_Watson_Connect \ IBM_Watson_Connect.ino:8:25:致命错误:ESP8266WiFi.h:无此类文件或目录

     

编译终止。

     

退出状态1   ESP32 Dev Module卡编译错误。

我正在使用ESP32开发板。我的代码是这样的:

    #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
    }

一些地方提到缺少库,未正确选择板,未更新库。.我都检查了它们。.Arduino已更新,库已安装和更新,已选择正确的板(我实际上已经尝试了所有其他与Esp32相关的板,但结果相同)

1 个答案:

答案 0 :(得分:1)

您要为ESP32(而不是ESP8266)构建程序。有很多相似之处,但是它们是完全不同的芯片,具有不同的软件。

因此您不要将ESP8266WiFi.h与ESP32一起使用。在ESP32上,头文件名为WiFi.h(与Arduinos上的WiFi支持保持更一致-ESP32 Arduino Core旨在比ESP8266版本更兼容常规Arduino Core)。

您需要

#include <WiFi.h>

代替ESP8266WiFi.h

您可以在the official repository for the Arduino SDK for the ESP32中找到这些文件的代码。

WiFi.h for the ESP32在其自身的注释中将自己标识为ESP8266.h并没有帮助。)