When I try to use a header, #ifdef doesn’t work properly, the code inside is gray out, if I call de function, I get an error. the identifier "blink" is not defined.
If I remove #ifdef, I get a new error when I try to compile, undefined reference to 'blink()'.
My headers are in include folder.
Is just init the wifi settings on esp, and put the code in header for use in other projects, I just call the function wificonfig in the setup with the SSID and Password.
Here is the code:
#include "wificonfig.h"
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
void wificonfig(const char *SSID, const char *PSK){
WiFiClient client;
ESP8266WiFiMulti WiFiMulti;
while (1){
WiFi.mode(WIFI_STA);
//WiFi.config(staticIP, subnet, gateway, dns);
WiFiMulti.addAP(SSID, PSK);
//WiFi.begin(APSSID,APPSK);
if (WiFi.status() == WL_IDLE_STATUS) { // when not connected to a network, but powered on
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
Serial.println("WL_IDLE_STATUS");
}
else if (WiFi.status() == WL_CONNECTED) {
digitalWrite(LED_BUILTIN, LOW);
Serial.print("WL_CONNECTED ");
Serial.println(WiFi.localIP());
break;
}
else if (WiFi.status() == WL_NO_SSID_AVAIL) {
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("WL_NO_SSID_AVAIL");
}
else if (WiFi.status() == WL_CONNECT_FAILED) {
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("WL_CONNECT_FAILED");
}
else if (WiFi.status() == WL_CONNECTION_LOST) {
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("WL_CONNECTION_LOST");
}
else if (WiFi.status() == WL_DISCONNECTED) {
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("WL_DISCONNECTED");
}
else {
digitalWrite(LED_BUILTIN, LOW);
}
Serial.println("Attempting again...");
delay(3000);
}
}
platfiomio.ini
[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
build_flags =
-D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY ;No sé bien que hace esto, solo se que ayuda a reservar espacio para el update.
monitor_speed = 115200
lib_deps =
PubSubClient
arduino-timer@^2.0.1
ArduinoJson@^6.15.2
arduino-timer@^2.0.1
Time
Where did you place the cpp-files corresponding to the header-files?
I assume that you have placed them in include:
If your project looks like that:
include
-> header.h header.cpp
src
-> main.cpp
/home/hst/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/d1_mini/src/main.cpp.o:(.text.setup+0x0): undefined reference to `blink()'
/home/hst/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/d1_mini/src/main.cpp.o: in function `setup':
main.cpp:(.text.setup+0xa): undefined reference to `blink()'
pio run ends with the error message described by you.
Instead if your project looks like that:
include
-> header.h
src
-> main.cpp header.cpp
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [=== ] 32.7% (used 26776 bytes from 81920 bytes)
Flash: [== ] 24.6% (used 256584 bytes from 1044464 bytes)
Creating BIN file ".pio/build/d1_mini/firmware.bin" using ".pio/build/d1_mini/firmware.elf"
=============================================================== [SUCCESS] Took 4.83 seconds ==============================================================