-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathESP_React_Hosting.ino
More file actions
77 lines (58 loc) · 1.59 KB
/
ESP_React_Hosting.ino
File metadata and controls
77 lines (58 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
#################################
Install LittleFS: https://randomnerdtutorials.com/arduino-ide-2-install-esp32-littlefs/
#################################
*/
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#endif
#include <ESPAsyncWebServer.h>
#include "LittleFS.h"
#define SSID "Tharusha"
#define PASS "abc12345"
AsyncWebServer server(80);
void setup() {
Serial.begin(115200);
init_wifi();
init_littlefs();
init_webserver();
}
void loop() {
// put your main code here, to run repeatedly:
}
void init_webserver() {
Serial.println(">>> [SERVER]: Setting up...");
//#################### [Your other routes here] ####################
server.on("/test", HTTP_GET, [](AsyncWebServerRequest *req) {
req->send(200, "text/plain", "this is test route...");
});
//##################################################################
handle_react(&server);
server.begin();
Serial.println(">>> [SERVER]: Successfully started.");
}
void init_littlefs() {
if(!LittleFS.begin()) {
Serial.println(">>> [LittleFS]: An Error has occurred while mounting SPIFFS !!!");
return;
}
Serial.println(">>> [LittleFS]: Initialized.");
//Serial.println(LittleFS.exists("/index.html"));
}
void init_wifi() {
WiFi.mode(WIFI_AP_STA);
WiFi.begin(SSID, PASS);
Serial.println();
Serial.print(">>> [WiFi]: Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.println();
Serial.print(">>> [WiFi]: IP = ");
Serial.println(WiFi.localIP());
}