• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Webserver Visual Studio code ESP32

Q&A Forum › Webserver Visual Studio code ESP32
0 Vote Up Vote Down
Teeluck Darminder asked 5 months ago

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();
}

 

1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 5 months ago

Hi.
Can you provide more details about the issue?
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] SMART HOME with RPi, ESP32, and ESP8266 (version 1.2) March 8, 2023
  • [eBook Updated] ESP32-CAM Projects (version 1.3) January 7, 2023

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2023 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.