Problems with the WeMos D1

I won´t to publish e.g. the temperature to a channel on thingspeak. So I decided to use the WeMos D1.

For the program I found a good explanation on So I included different libraries and when i compiled the sketch I got the following fault:

Arduino: 1.8.1 (Windows 7), Board: “WeMos D1 R1, 80 MHz, 4M (1M SPIFFS), v2 Prebuilt (MSS=536), Disabled, None, 921600”

C:\Users\Anwender\Documents\Arduino\libraries\WiFi101\src\WiFiMDNSResponder.cpp:24:26: fatal error: avr/pgmspace.h: No such file or directory

#include <avr/pgmspace.h>


compilation terminated.

exit status 1
Error compiling for board WeMos D1 R1.

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

The library avr/pgmspace.h had not been included in the sketch by me. I tested the sketch with this library included too but that also didn´t work.

Had anybody the same problem and knows how to solve it?

you have the wrong example. it is for wifi101 avr library

I worte the programm for myself it is not an example

then why do you use avr libraries? use esp8266 libraries

Thats my problem I didn´t used thath library but there is still this fault:

#include <PubSubClient.h>
#include <SPI.h>
#include <WiFi101.h>

#define DHTPIN 2 // DHT Sensor connected to digital pin 2.
#define DHTTYPE DHT11 // Type of DHT sensor.
#define LIGHTPIN A0 // Analog light sensor connected to analog pin A0.

char ssid = “xxx”; // Change this to your network SSID (name).
char pass = “xxx#”; // Change this your network password
char mqttUserName = “xx_xx_x”; // Can be any name.
char mqttPass = “xx”; // Change this your MQTT API Key from Account > MyProfile.
char writeAPIKey = “xx”; // Change to your channel Write API Key.
long channelID = xx;

static const char alphanum =“0123456789”
“abcdefghijklmnopqrstuvwxyz”; // For random generation of client ID.

WiFiClient client; // Initialize the Wifi client library.
// DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor.

PubSubClient mqttClient(client); // Initialize the PuBSubClient library.
const char* server = “”;

unsigned long lastConnectionTime = 0;
const unsigned long postingInterval = 20L * 1000L; // Post data every 20 seconds.

void setup()
int status = WL_IDLE_STATUS; // Set a temporary WiFi status.

// Attempt to connect to WiFi network
while (status != WL_CONNECTED)
status = WiFi.begin(ssid, pass); // Connect to WPA/WPA2 Wi-Fi network.

Serial.println(“Connected to wifi”);
mqttClient.setServer(server, 1883); // Set the MQTT broker details.

void loop()
// Reconnect if MQTT client is not connected.
if (!mqttClient.connected())

mqttClient.loop(); // Call the loop continuously to establish connection to the server.

// If interval time has passed since the last connection, Publish data to ThingSpeak
if (millis() - lastConnectionTime > postingInterval)

void reconnect()
char clientID[10];

// Loop until we’re reconnected
while (!mqttClient.connected())
Serial.print(“Attempting MQTT connection…”);
// Generate ClientID
for (int i = 0; i < 8; i++) {
clientID = alphanum[random(51)];

  • }*

  • // Connect to the MQTT broker*

  • if (mqttClient.connect(clientID,mqttUserName,mqttPass))*

  • {*

  • Serial.println(“connected”);*

  • } else*

  • {*

  • Serial.print(“failed, rc=”);*

  • // Print to know why the connection failed.*

  • // See for the failure code explanation.*

  • Serial.print(mqttClient.state());*

  • Serial.println(" try again in 5 seconds");*

  • delay(5000);*

  • }*

  • }*
    // Use this function instead to publish to a single field directly. Don’t forget to comment out the above version.
    void mqttpublish() {

  • float t = 5; // Read temperature from DHT sensor.*

  • String data = String(t, DEC);*

  • int length = data.length();*

  • char msgBuffer[length];*

  • data.toCharArray(msgBuffer,length+1);*

  • Serial.println(msgBuffer);*

  • // Create a topic string and publish data to ThingSpeak channel feed.*

  • String topicString =“channels/” + String( channelID ) + “/publish/”+String(writeAPIKey);*

  • length=topicString.length();*

  • char topicBuffer[length];*

  • topicString.toCharArray(topicBuffer,length+1);*

  • mqttClient.publish( topicBuffer, msgBuffer );*

  • lastConnectionTime = millis();*

WiFi101 is not for the esp8266. look at the esp8266 examples in IDE

This is what I used:

Thank you! Now it workes.