Skip to content

Commit 3a35289

Browse files
committed
Cleanup
1 parent 7846baa commit 3a35289

6 files changed

Lines changed: 46 additions & 32 deletions

File tree

ESPEssentials.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#ifndef _ESPESSENTIALS_H_1436481
2-
#define _ESPESSENTIALS_H_1436481
1+
#ifndef ESPESSENTIALS_H
2+
#define ESPESSENTIALS_H
33

44
#include "Wifi.h"
5-
#include "WebServer.h"
65
#include "OTA.h"
6+
#include "WebServer.h"
77

88
#define ESSENTIALS_BAUD 115200
99

OTA.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,25 @@ void OTAClass::init(char const *hostname, char const *password, uint16_t port)
2424
onError([](ota_error_t error)
2525
{
2626
Serial.printf("[OTA] Error[%u]: ", error);
27-
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
28-
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
29-
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
30-
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
31-
else if (error == OTA_END_ERROR) Serial.println("End Failed");
27+
28+
switch(error)
29+
{
30+
case OTA_AUTH_ERROR:
31+
Serial.println("Auth Failed");
32+
break;
33+
case OTA_BEGIN_ERROR:
34+
Serial.println("Begin Failed");
35+
break;
36+
case OTA_CONNECT_ERROR:
37+
Serial.println("Connect Failed");
38+
break;
39+
case OTA_RECEIVE_ERROR:
40+
Serial.println("Receive Failed");
41+
break;
42+
case OTA_END_ERROR:
43+
Serial.println("End Failed");
44+
break;
45+
}
3246
});
3347

3448
begin();

OTA.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#ifndef _OTA_H_714124218
2-
#define _OTA_H_714124218
1+
#ifndef ESPESSENTIALS_OTA_H
2+
#define ESPESSENTIALS_OTA_H
33

4-
#include <ArduinoOTA.h>
54
#include "Wifi.h"
65

6+
#include <ArduinoOTA.h>
7+
78
class OTAClass : public ArduinoOTAClass
89
{
910
public:

WebServer.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void WebServerClass::init()
1616
Serial.println("[Storage] Couldn't mount file system.");
1717
return;
1818
}
19-
19+
2020
on("/edit", HTTP_GET, [&]()
2121
{
2222
if(!handleFileRead("/edit.htm"))
@@ -32,7 +32,7 @@ void WebServerClass::init()
3232
});
3333
on("/edit", HTTP_PUT, _handle_file_create);
3434
on("/edit", HTTP_DELETE, _handle_file_delete);
35-
on("/edit", HTTP_POST, [&](){ send(200, "text/plain", ""); }, _handle_file_upload);
35+
on("/edit", HTTP_POST, [&]() { send(200, "text/plain", ""); }, _handle_file_upload);
3636
on("/list", HTTP_GET, _handle_file_list);
3737
on("/update", HTTP_GET, [&]()
3838
{
@@ -64,7 +64,7 @@ void WebServerClass::init()
6464
send(404, "text/plain", "Oops, file not found!");
6565
}
6666
});
67-
67+
6868
begin();
6969
}
7070

@@ -106,7 +106,7 @@ String WebServerClass::getContentType(String filename)
106106
bool WebServerClass::handleFileRead(String path)
107107
{
108108
Serial.println("[Storage] File read: " + path);
109-
109+
110110
webserverBusy = true;
111111
if(path.endsWith("/")) path += "index.htm";
112112
String contentType = getContentType(path);
@@ -135,7 +135,7 @@ void WebServerClass::handleFileUpload()
135135
return;
136136

137137
HTTPUpload& _upload = upload();
138-
138+
139139
if(_upload.status == UPLOAD_FILE_START)
140140
{
141141
String filename = _upload.filename;
@@ -148,7 +148,6 @@ void WebServerClass::handleFileUpload()
148148
}
149149
else if(_upload.status == UPLOAD_FILE_WRITE)
150150
{
151-
//Serial.print("[Storage] Receiving..." + _upload.currentSize);
152151
if(fsUploadFile)
153152
fsUploadFile.write(_upload.buf, _upload.currentSize);
154153
}
@@ -164,17 +163,17 @@ void WebServerClass::handleFileDelete()
164163
{
165164
if(args() == 0)
166165
return send(500, "text/plain", "BAD ARGS");
167-
166+
168167
String path = arg(0);
169168
Serial.println("[Storage] Deleting file: " + path);
170-
169+
171170
if(path == "/")
172171
return send(500, "text/plain", "BAD PATH");
173172
if(!SPIFFS.exists(path))
174173
return send(404, "text/plain", "Oops, file not found (3)!");
175-
174+
176175
SPIFFS.remove(path);
177-
176+
178177
send(200, "text/plain", "");
179178
path = String();
180179
}
@@ -183,22 +182,22 @@ void WebServerClass::handleFileCreate()
183182
{
184183
if(args() == 0)
185184
return send(500, "text/plain", "BAD ARGS");
186-
185+
187186
String path = arg(0);
188187
Serial.println("[Storage] Creating file: " + path);
189-
188+
190189
if(path == "/")
191190
return send(500, "text/plain", "BAD PATH");
192191
if(SPIFFS.exists(path))
193192
return send(500, "text/plain", "File already exists!");
194-
193+
195194
File file = SPIFFS.open(path, "w");
196-
195+
197196
if(file)
198197
file.close();
199198
else
200199
return send(500, "text/plain", "Oops, creating file failed!");
201-
200+
202201
send(200, "text/plain", "");
203202
path = String();
204203
}
@@ -210,7 +209,7 @@ void WebServerClass::handleFileList()
210209
send(500, "text/plain", "BAD ARGS");
211210
return;
212211
}
213-
212+
214213
String path = arg("dir");
215214
Dir dir = SPIFFS.openDir(path);
216215
path = String();

WebServer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#ifndef _WEBSERVER_H_471412218
2-
#define _WEBSERVER_H_471412218
1+
#ifndef ESPESSENTIALS_WEBSERVER_H
2+
#define ESPESSENTIALS_WEBSERVER_H
33

44
#include <Arduino.h>
55
#include <ESP8266WebServer.h>
66
#include <ESP8266WiFi.h>
7-
#include <WiFiUdp.h>
87
#include <FS.h>
8+
#include <WiFiUdp.h>
99

1010
class WebServerClass : public ESP8266WebServer
1111
{

Wifi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef _WIFI_H_471412218
2-
#define _WIFI_H_471412218
1+
#ifndef ESPESSENTIALS_WIFI_H
2+
#define ESPESSENTIALS_WIFI_H
33

44
#include <WiFiManager.h>
55

0 commit comments

Comments
 (0)