1
1
#include < WiFi.h>
2
2
#include < WiFiClient.h>
3
3
#include < WebServer.h>
4
- #include < SD.h>
4
+ #include < SD_MMC.h>
5
+
6
+ #include < uri/UriRegex.h>
5
7
6
8
const char * ssid = " **********" ;
7
9
const char * password = " **********" ;
8
10
9
11
WebServer server (80 );
10
12
11
13
File rawFile;
14
+
12
15
void handleCreate () {
13
16
server.send (200 , " text/plain" , " " );
14
17
}
18
+
15
19
void handleCreateProcess () {
16
20
String path = server.pathArg (0 );
17
21
HTTPRaw& raw = server.raw ();
18
22
if (raw.status == RAW_START) {
19
- if (SD .exists ((char *)path.c_str ())) {
20
- SD .remove ((char *)path.c_str ());
23
+ if (SD_MMC .exists ((char *)path.c_str ())) {
24
+ SD_MMC .remove ((char *)path.c_str ());
21
25
}
22
- rawFile = SD .open (path.c_str (), FILE_WRITE);
26
+ rawFile = SD_MMC .open (path.c_str (), FILE_WRITE);
23
27
Serial.print (" Upload: START, filename: " );
24
28
Serial.println (path);
25
29
} else if (raw.status == RAW_WRITE) {
@@ -46,10 +50,10 @@ void printDirectory() {
46
50
return returnFail (" BAD ARGS" );
47
51
}
48
52
String path = server.arg (" dir" );
49
- if (path != " /" && !SD .exists ((char *)path.c_str ())) {
53
+ if (path != " /" && !SD_MMC .exists ((char *)path.c_str ())) {
50
54
return returnFail (" BAD PATH" );
51
55
}
52
- File dir = SD .open ((char *)path.c_str ());
56
+ File dir = SD_MMC .open ((char *)path.c_str ());
53
57
path = String ();
54
58
if (!dir.isDirectory ()) {
55
59
dir.close ();
@@ -98,14 +102,13 @@ void handleNotFound() {
98
102
message += " " + server.argName (i) + " : " + server.arg (i) + " \n " ;
99
103
}
100
104
server.send (404 , " text/plain" , message);
101
- digitalWrite (led, 0 );
102
105
}
103
106
104
107
void setup (void ) {
105
108
Serial.begin (115200 );
106
109
107
- while (!SD .begin ()) delay ();
108
- Serial.println (" SD Card initialized." );
110
+ while (!SD_MMC .begin ()) delay (10 );
111
+ Serial.println (" SD_MMC Card initialized." );
109
112
110
113
WiFi.mode (WIFI_STA);
111
114
WiFi.begin (ssid, password);
@@ -122,7 +125,7 @@ void setup(void) {
122
125
server.on (UriRegex (" /upload/(.*)" ), HTTP_PUT, handleCreate, handleCreateProcess);
123
126
server.onNotFound (handleNotFound);
124
127
server.begin ();
125
- server .println (" HTTP server started" );
128
+ Serial .println (" HTTP server started" );
126
129
127
130
}
128
131
0 commit comments