Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By marcin8352
#92773 Hello,

Im new to ESP8266 im trying to run one of my first programs from this site:

https://highvoltages.co/iot-internet-of ... mqtt/#Code

I installed all libaries, connected ESP8266 and installed driver. I got this error:

Arduino:1.8.16 (Windows 10), Płytka:"Generic ESP8266 Module, 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, dtr (aka nodemcu), 26 MHz, 40MHz, DOUT (compatible), 1MB (FS:64KB OTA:~470KB), 2, nonos-sdk 2.2.1+100 (190703), v2 Lower Memory, Disabled, None, Only Sketch, 115200"









In file included from c:\users\marcin\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\assert.h:10,

from c:\users\marcin\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\sys\reent.h:503,

from c:\users\marcin\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\stdlib.h:18,

from c:\users\marcin\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\c++\10.3.0\cstdlib:75,

from c:\users\marcin\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\c++\10.3.0\stdlib.h:36,

from C:\Users\Marcin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/Arduino.h:27,

from sketch\8266kod_v1.ino.cpp:1:

C:\Users\Marcin\Documents\Arduino\libraries\WhareHauoraWiFiManager/WiFiManager.h:25:24: error: 'const char HTTP_HEAD []' redeclared as different kind of entity

25 | const char HTTP_HEAD[] PROGMEM = "<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\"/><title>{v}</title>";

| ^~~~~~~

In file included from C:\Users\Marcin\Desktop\8266kod_v1\8266kod_v1.ino:5:

C:\Users\Marcin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266WebServer\src/ESP8266WebServer.h:47:39: note: previous declaration 'HTTPMethod HTTP_HEAD'

47 | enum HTTPMethod { HTTP_ANY, HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_DELETE, HTTP_OPTIONS };

| ^~~~~~~~~

C:\Users\Marcin\Desktop\8266kod_v1\8266kod_v1.ino: In function 'void callback(char*, byte*, unsigned int)':

8266kod_v1:11:13: error: 'D2' was not declared in this scope

11 | #define LED D2

| ^~

C:\Users\Marcin\Desktop\8266kod_v1\8266kod_v1.ino:40:20: note: in expansion of macro 'LED'

40 | digitalWrite(LED,HIGH);

| ^~~

8266kod_v1:11:13: error: 'D2' was not declared in this scope

11 | #define LED D2

| ^~

C:\Users\Marcin\Desktop\8266kod_v1\8266kod_v1.ino:44:20: note: in expansion of macro 'LED'

44 | digitalWrite(LED,LOW);

| ^~~

C:\Users\Marcin\Desktop\8266kod_v1\8266kod_v1.ino: In function 'void setup()':

8266kod_v1:11:13: error: 'D2' was not declared in this scope

11 | #define LED D2

| ^~

C:\Users\Marcin\Desktop\8266kod_v1\8266kod_v1.ino:57:11: note: in expansion of macro 'LED'

57 | pinMode(LED,OUTPUT);

| ^~~

exit status 1

'D2' was not declared in this scope



Ten raport powinien zawierać więcej informacji jeśli w
File -> Preferencje zostanie włączona opcja "Pokaż
szczegółowe informacje podczas kompilacji"


Code: Select all#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
 
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager
#include <DHT.h>
#include <PubSubClient.h>
 
#define DHTPIN 5 // Digital pin connected to the DHT sensor
#define LED D2
// Uncomment the type of sensor in use:
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
 
unsigned long previousMillis = 0;
unsigned long interval = 10000;
 
const char* mqttServer = "192.168.0.81";
const int mqttPort = 1883;
 
void callback(char* topic, byte* payload, unsigned int length) {
 
  Serial.print("Message arrived in topic: ");
  Serial.println(topic);
 
  Serial.print("Message:");
    Serial.println();
   
  String message = "";
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
    message+=(char)payload[i];
  }
  Serial.println("-----------------------");
  if(String(topic)=="LED"){
    if(message=="LED ON"){
      digitalWrite(LED,HIGH);
      Serial.println("LED IS ON");
    }
    else{
      digitalWrite(LED,LOW);
    }
  }
     
}
 
WiFiClient espClient;
PubSubClient client(mqttServer, mqttPort, callback, espClient);
 
 
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(LED,OUTPUT);
  digitalWrite(LED,LOW);
  //WiFiManager
  //Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wifiManager;
  //reset saved settings
// wifiManager.resetSettings();
 
  //set custom ip for portal
  //wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
 
  //fetches ssid and pass from eeprom and tries to connect
  //if it does not connect it starts an access point with the specified name
  //here  "AutoConnectAP"
  //and goes into a blocking loop awaiting configuration
  wifiManager.autoConnect("AutoConnectAP");
  //or use this for auto generated name ESP + ChipID
  //wifiManager.autoConnect();
 
 
  //if you get here you have connected to the WiFi
  Serial.println("connected...yeey :)");
  dht.begin();
  client.setServer(mqttServer, mqttPort);
  client.setCallback(callback);
    while (!client.connected()) {
    Serial.println("Connecting to MQTT...");
 
    if (client.connect("ESP8266Client" )) {
      client.subscribe("LED");
      Serial.println("connected");
 
    } else {
 
      Serial.print("failed with state ");
      Serial.print(client.state());
      delay(2000);
 
    }
}
}
 
void loop() {
    client.loop();
unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    // save the last time you updated the DHT values
    previousMillis = currentMillis;
    float t = dht.readTemperature();
    float h = dht.readHumidity();
    if(!isnan(h)&&!isnan(t)){
      Serial.println("Temperature : " +String(t));
      Serial.println("Humidity : " +String(h));
      String toSend = String(t) + "," +String(h);
      client.publish("data",toSend.c_str());
    }
 
  }
}









what is causing this issue ? how can i repair this ?
User avatar
By QuickFix
#92777 Please select the correct board in the "Tools" -> "Board" - menu in the Arduino IDE.

D0-D15 is generally the numbering scheme of a NodeMCU or Wemos development board, but you have to check yourself, since you didn't state that info in your question. :idea:

Also, just a friendly hint: this is not a "Compiler Chat" question and actually belongs in our "Newbie Corner", so please use that forum for beginners questions instead.