#include <ESP8266WiFi.h> ERROR

The following code gives an ERROR saying fatal error: ESP8266WiFi.h: No such file or directory
#include <ESP8266WiFi.h>
^~~~~~~~~~~~~~~
compilation terminated.

exit status 1

Compilation error: exit status 1

I have installed ESP8266 packages too, and the problem still persists.

#include <ArduinoMqttClient.h>
#include <Arduino.h>
#include <AzureIoTHubMQTTClient.h>
#include <WiFi101.h>



const char* ssid = "";
const char* password = "";
const char* connectionString = "HostName=<MkrHub>.azure-devices.net;DeviceId=<MkrDevice>;SharedAccessKey=<>";

static const char* connectionStringValue = connectionString;
static const char* ssidValue = ssid;
static const char* passwordValue = password;

WiFiClient wifiClient;
IoTHubMQTT client(wifiClient, connectionStringValue);

void setup()
{
  Serial.begin(115200);
  WiFi.begin(ssidValue, passwordValue);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("WiFi connected");

  if (!client.begin())
  {
    Serial.println("Failed to initialize Azure IoT client");
    while (1);
  }
}

void loop()
{
  if (client.connected())
  {
    IoTHubMessage message = IoTHubMessage("Hello from Arduino!");
    client.sendEvent(message);
    Serial.println("Message sent to Azure IoT Hub");
  }
  else
  {
    if (client.connect() == 0)
    {
      Serial.println("Connected to Azure IoT Hub");
    }
    else
    {
      Serial.println("Connection to Azure IoT Hub failed");
      delay(5000);
    }
  }
  delay(5000);
}

What board do you use?

I'm using a Wifi1010 board coupled to an Arduino OPLA IOT kit.

Why do you try to use ESP8266WIFI library, that obviously not for your hardware?

Yea that's the thing, I'm new to this and I used the code I found online for the board i'm using. If you can suggest what I can use that would be helpful.

Not every arduino code can run in every Arduino board, most codes are board-specific. If the code you found uses ESP8266WIFI library - that this code is for esp8266 board and likely won't work on other boards.
You have to find and use code for mkr1010 arduino.

1 Like

with MKR WiFi 1010 use the WiFiNINA library.
but first, select MKR WiFi 1010 in the Tools menu

Yes MKR Wifi 1010 is selected and WifiNINA library is also installed
I still am getting the same error. Even after removing the #include ESP8266Wifi

AzureIoTHubMQTTClient only supports esp8266

Ok thanks for the help!

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