From bcdd392020f2d3f2f72f2102106e6236bec45a03 Mon Sep 17 00:00:00 2001 From: Aadi Desai <21363892+supleed2@users.noreply.github.com> Date: Fri, 4 Jun 2021 01:02:32 +0100 Subject: [PATCH] Migrate to SPIFFS, untested --- Control/data/favicon.ico | Bin 0 -> 1150 bytes Control/data/index.html | 304 +++++++++++++++++++++++++++++ Control/src/main.cpp | 400 ++++++--------------------------------- 3 files changed, 360 insertions(+), 344 deletions(-) create mode 100644 Control/data/favicon.ico create mode 100644 Control/data/index.html diff --git a/Control/data/favicon.ico b/Control/data/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..cbaef43c600ad681185a856bc52468f966e77896 GIT binary patch literal 1150 zcmbW1?Mstk6vm(0^Rj2d%@t^f$u_Ln%ZF$qm@?F-1ATx4K&4=~l9;qSPpg z(gdJj4tN$tA$QDvfcFMx~0%V^$M1(_j&-f)aQQ%0RfcU<%BD7xne^$BV_H+Sb-) z<^4G|@3PK;dG-iJqfvu-S^a*$om`Cmu7e)pUh&g+)6UM0%v$`U( zlap#9k@&naS?6Rg>LhsoEOTXc0b-f+NG_MthKGl>SS)6s zJCDBX^Z6X)?xWe{PA=iOEM98F(VRmwMSQ2byIT`~JRaA_$H!H2XULW6>gsA_1u}Q( zdkL&m;#s`CU0q$q=;-LaUuHBhF>&ahZfR+;b#`_d@;eR&gJw7!Hrw0V&F1E2TPPGV zrQg23K0TYwYC}Uqn%tGttMpb51OoO{Dy2)^WHR{&gp+;+;vX0o(CBB7-d=(Q&MC7k z*4EaZ$Ye5dHlu>yzC%v@@*6=v%iZ3Pdyu)vthm3^g+k$ + + + + Rover Control Panel + + + + + + + + + + +

ROVER COMMAND CENTER

+ +
+ +
+
+

Movement Control

+
+ +
+
+ + + +
+ +
+
+ +
+
+

Sensor Data

+
    + +
  • +
    + +
    +
    + +
    +
  • + + +
  • +
    + +
    +
    + 28mm +
    +
  • + +
+
+ +
+ +
+ + + + \ No newline at end of file diff --git a/Control/src/main.cpp b/Control/src/main.cpp index a76a5e3..6cc0738 100644 --- a/Control/src/main.cpp +++ b/Control/src/main.cpp @@ -8,9 +8,10 @@ #include #include #include -#ifdef LOG_LOCAL_LEVEL - #undef LOG_LOCAL_LEVEL -#endif +#include + +// Enable extra debugging info +#undef LOG_LOCAL_LEVEL #define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE #include "esp_log.h" @@ -32,313 +33,22 @@ Ticker ticker(returnSensorData, 500, 0, MILLIS); int battery_voltage = 0; int distance_travelled = 0; -#pragma region HTMLsource -char index_html[] PROGMEM = R"=====( - - - - -Rover Control Panel - - - - - - - -

ROVER COMMAND CENTER

- -
- -
-
-

Movement Control

-
- -
-
- - - -
- -
-
- -
-
-

Sensor Data

-
    - -
  • - -
    -
    - -
    -
  • - - -
  • - -
    -
    - 28mm -
    -
  • - -
-
- -
- -
- - - - - -)====="; -#pragma endregion - void setup() { - esp_log_level_set("*", ESP_LOG_ERROR); // set all components to ERROR level - esp_log_level_set("wifi", ESP_LOG_WARN); // enable WARN logs from WiFi stack - esp_log_level_set("dhcpc", ESP_LOG_INFO); // enable INFO logs from DHCP client + esp_log_level_set("*", ESP_LOG_ERROR); // set all components to ERROR level + esp_log_level_set("wifi", ESP_LOG_WARN); // enable WARN logs from WiFi stack + esp_log_level_set("dhcpc", ESP_LOG_INFO); // enable INFO logs from DHCP client Serial.begin(115200); // Set up hardware UART0 (Connected to USB port) Serial1.begin(9600, SERIAL_8N1, RX1pin, TX1pin); // Set up hardware UART1 // Set up remaining communication ports here (Energy, Drive, Vision) + if (!SPIFFS.begin(true)) + { + Serial.println("SPIFFS failed to mount"); + return; + } + Serial.println("Connecting to AP"); WiFi.begin(WIFI_SSID, WIFI_PW); while (WiFi.status() != WL_CONNECTED) @@ -354,8 +64,10 @@ void setup() } Serial.println("mDNS set up, access Control Panel at 'rover.local/'"); - webserver.on("/", [](AsyncWebServerRequest *request) - { request->send_P(200, "text/html", index_html); }); + webserver.on("/", HTTP_GET, [](AsyncWebServerRequest *request) + { request->send(SPIFFS, "/index.html", "text/html"); }); + webserver.on("/favicon.ico", HTTP_GET, [](AsyncWebServerRequest *request) + { request->send(SPIFFS, "/favicon.ico", "image/png"); }); webserver.onNotFound(notFound); webserver.begin(); @@ -404,47 +116,47 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, size_t length) { switch (type) { - case WStype_DISCONNECTED: - { - Serial.printf("Client[%u] Disconnected!\n", num); - } - break; - case WStype_CONNECTED: - { - IPAddress ip = websocketserver.remoteIP(num); - Serial.printf("Client[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload); - } - break; - case WStype_TEXT: - { - Serial.printf("Client[%u] sent Text: %s\n", num, payload); - String command = String((char *)(payload)); + case WStype_DISCONNECTED: + { + Serial.printf("Client[%u] Disconnected!\n", num); + } + break; + case WStype_CONNECTED: + { + IPAddress ip = websocketserver.remoteIP(num); + Serial.printf("Client[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload); + } + break; + case WStype_TEXT: + { + Serial.printf("Client[%u] sent Text: %s\n", num, payload); + String command = String((char *)(payload)); - DynamicJsonDocument doc(200); //creating an instance of a DynamicJsonDocument allocating 200bytes on the heap. - DeserializationError error = deserializeJson(doc, command); // deserialize 'doc' and parse for parameters we expect to receive. - if (error) - { - Serial.print("deserializeJson() failed: "); - Serial.println(error.c_str()); - return; - } - - int MVM_F_status = doc["MVM_F"]; - int MVM_L_status = doc["MVM_L"]; - int MVM_R_status = doc["MVM_R"]; - int MVM_B_status = doc["MVM_B"]; - - Serial.println('<' + MVM_F_status + ',' + MVM_B_status + ',' + MVM_L_status + ',' + MVM_R_status + '>'); - } - break; - case WStype_PONG: + DynamicJsonDocument doc(200); //creating an instance of a DynamicJsonDocument allocating 200bytes on the heap. + DeserializationError error = deserializeJson(doc, command); // deserialize 'doc' and parse for parameters we expect to receive. + if (error) { - Serial.println("Websocket keep-alive PONG"); - } - default: - { - Serial.println(String("Websocket received invalid event type: ") + type + String(", exiting")); - exit(1); + Serial.print("deserializeJson() failed: "); + Serial.println(error.c_str()); + return; } + + int MVM_F_status = doc["MVM_F"]; + int MVM_L_status = doc["MVM_L"]; + int MVM_R_status = doc["MVM_R"]; + int MVM_B_status = doc["MVM_B"]; + + Serial.println('<' + MVM_F_status + ',' + MVM_B_status + ',' + MVM_L_status + ',' + MVM_R_status + '>'); + } + break; + case WStype_PONG: + { + Serial.println("Websocket keep-alive PONG"); + } + default: + { + Serial.println(String("Websocket received invalid event type: ") + type + String(", exiting")); + exit(1); + } } }