I want to include the WebServer.h library from the ESP32 Core Installation.
I already added the URL down below to the Boardmanager and successfully used for example the WiFi.h library.
However if I reference the WebServer.h it always raises an error saying:
Arduino: 1.8.19 (Windows 10), Board: "NodeMCU-32S, 80MHz, 921600"
Multiple libraries were found for "WiFi.h"
CarMatrix:6:10: fatal error: WebServer.h: No such file or directory
Used: C:\Users\hoebe\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2\libraries\WiFi
#include <Webserver.h>
Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
^~~~~~~~~~~~~
compilation terminated.
exit status 1
Webserver.h: No such file or directory
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
I searched for the path and the file is present in:
C:\Users\user\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2\libraries\WebServer\src
URL used for ESP32 Core:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
Here is my Code:
//Include Libraries and Files
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#include <WiFi.h>
#include <WebServer.h>
#include <ArduinoJson.h>
#include "index.h"
////Define Globals
#define PIN 4
//Init the NeoPixel Matrix
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN, NEO_MATRIX_BOTTOM + NEO_MATRIX_RIGHT + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG, NEO_GRB + NEO_KHZ800);
//Defined Colors
const uint16_t colors[] = {matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(255, 255, 0), matrix.Color(0, 0, 255), matrix.Color(255, 0, 255), matrix.Color(0, 255, 255), matrix.Color(255, 255, 255)};
//DisplayedText
String displayedText = "This is a very long text";
//Wifi Credetials
char *SSID = "Autodisplay";
char *PASSWORD = "2022#display";
//WebServer and API-Response
WebServer server(80);
String header;
// JSON data buffer for sending information to Webclient
StaticJsonDocument<250> jsonDocument;
char buffer[250];
void setup() {
//Start Consol Output
Serial.begin(115200);
Serial.println();
//Init the NeoPixel Matrix
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(5);
matrix.setTextColor(colors[0]);
//Setup Accesspoint & WebServer
setupAccessPoint();
setupWebServer();
}
int x = matrix.width();
int pass = 0;
int scrollLength = (displayedText.length() * 5 + 25) * (-1);
void loop() {
//shift current Text
shiftText();
matrix.show();
//listen for web requests
server.handleClient();
delay(30);
}
//Shift Text on NeoPixel Matrix to the left
void shiftText() {
//Text scrolling by
matrix.fillScreen(0); //Turn off all the LEDs
matrix.setCursor(x, 0);
matrix.print(displayedText);
if ( --x < scrollLength ) {
x = matrix.width();
if (++pass >= 8) pass = 0;
matrix.setTextColor(colors[pass]);
}
}
//Init the AccessPoint of the ESP32 WiFi Module
void setupAccessPoint() {
Serial.println("Setting up AccessPoint");
WiFi.softAP(SSID, PASSWORD);
IPAddress ap_ip = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(ap_ip);
}
//Init the Webserver and the routing
void setupWebServer() {
Serial.println("Setup Webserver routing");
//Setup for GET Requests
server.on("/get/settings", sendSettings);
server.on("/", handleRoot);
//Setup for POST Requests
server.on("/post/settings", HTTP_POST, handleSettingsPost);
//Start Websever
Serial.println("Start Webserver on Port 80");
server.begin();
}
//Create JSON-Data in the jsonDocument
void create_json(char *key, char *value) {
jsonDocument.clear();
jsonDocument[key] = value;
serializeJson(jsonDocument, buffer);
}
//Add JSON-Data to the jsonDocument
void add_json_object(char *key, char *value) {
JsonObject obj = jsonDocument.createNestedObject();
obj[key] = value;
}
//send Settings to connected Client in JSON-Format
void sendSettings() {
Serial.println("Sending Settings to Client");
create_json("testKey", colors[0]);
server.send(200, "application/json", buffer);
//Send Website back
handleRoot();
}
//Handle Settings Post from Client
void handleSettingsPost() {
if (server.hasArg("plain") == false) {
//Client hasten Send any data
Serial.println("No JSON Data sent as Settings");
}
String body = server.arg("plain");
deserializeJson(jsonDocument, body);
displayedText = jsonDocument["displayedText"];
Serial.print("Text is changed to: ");
Serial.println(displayedText);
}
void handleRoot() {
Serial.println("Response with Website");
server.send(200, "text/html", MAIN_page);
}