#include "connection.h"
void setup() {
Serial.begin(115200);
Funcs::Connect conn;
conn.connectWifi();
}
void loop() {
}
then connection.h file:
// connection.h
namespace Funcs
{
class Connect
{
public:
void connectWifi();
};
}
and then connection.cpp
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "connection.h"
const char* ssid = "ssid";
const char* password = "password";
namespace Funcs
{
void connectWifi() {
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(10);
Serial.print(".");
}
Serial.println("");
Serial.print("WiFi connected with ip ");
Serial.println(WiFi.localIP());
}
}
On compiling I get this error:
/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266/HardwareSerial.h:76:
undefined reference to `Funcs::Connect::connectWifi()'
collect2: error: ld returned 1 exit status
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board WeMos D1 R1.
But I do not have Funcs::Connect::connectWifi()
in my code, it was in old code.