collect2: error: ld returned 1 exit status
*** [.pio/build/esp32doit-devkit-v1/firmware.elf] Error
Hello I am doing an application on ESP32 using Platformio. When I compile, I get the following error message.
When I compile the same code with Arduino ide, it does not give an error.
What could be the mistake.
// Import required libraries
#include <Arduino.h>
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include “SPIFFS.h”
#include <Arduino_JSON.h>
// Replace with your network credentials
const char* ssid = “xxxxxxxx”;
const char* password = “xxxxxxxx”;
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
// Create a WebSocket object
AsyncWebSocket ws(“/ws”);
// Set number of outputs
#define NUM_OUTPUTS 4
// Assign each GPIO to an output
int outputGPIOs[NUM_OUTPUTS] = {2, 4, 12, 14};
// Initialize SPIFFS
void initSPIFFS() {
if (!SPIFFS.begin(true)) {
Serial.println(“An error has occurred while mounting SPIFFS”);
}
Serial.println(“SPIFFS mounted successfully”);
}
// Initialize WiFi
void initWiFi() {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print(“Connecting to WiFi ..”);
while (WiFi.status() !=WL_CONNECTED) {
Serial.print(‘.’);
delay(1000);
}
Serial.println(WiFi.localIP());
}
String getOutputStates(){
JSONVarmyArray;
for (inti=0; i<NUM_OUTPUTS; i++){
myArray[“gpios”][i][“output”]=String(outputGPIOs[i]);
myArray[“gpios”][i][“state”]=String(digitalRead(outputGPIOs[i]));
}
StringjsonString=JSON.stringify(myArray);
returnjsonString;
}
void notifyClients(String state) {
ws.textAll(state);
}
void handleWebSocketMessage(void *arg, uint8_t *data, size_t len) {
AwsFrameInfo*info= (AwsFrameInfo*)arg;
if (info->final&&info->index==0&&info->len==len&&info->opcode==WS_TEXT) {
data[len] =0;
if (strcmp((char*)data, “states”) ==0) {
notifyClients(getOutputStates());
}
else{
intgpio=atoi((char*)data);
digitalWrite(gpio, !digitalRead(gpio));
notifyClients(getOutputStates());
}
}
}
void onEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,AwsEventType type,
void*arg, uint8_t*data, size_tlen) {
switch (type) {
caseWS_EVT_CONNECT:
Serial.printf(“WebSocket client #%u connected from %s\n”, client->id(), client->remoteIP().toString().c_str());
break;
caseWS_EVT_DISCONNECT:
Serial.printf(“WebSocket client #%u disconnected\n”, client->id());
break;
caseWS_EVT_DATA:
handleWebSocketMessage(arg, data, len);
break;
caseWS_EVT_PONG:
caseWS_EVT_ERROR:
break;
}
}
void initWebSocket() {
ws.onEvent(onEvent);
server.addHandler(&ws);
}
void setup(){
// Serial port for debugging purposes
Serial.begin(115200);
// Set GPIOs as outputs
for (inti=0; i<NUM_OUTPUTS; i++){
pinMode(outputGPIOs[i], OUTPUT);
}
initSPIFFS();
initWiFi();
initWebSocket();
// Route for root / web page
server.on(“/”, HTTP_GET, [](AsyncWebServerRequest*request){
request->send(SPIFFS, “/index.html”, “text/html”,false);
});
server.serveStatic(“/”, SPIFFS, “/”);
// Start server
server.begin();
}
void loop() {
ws.cleanupClients();
}