Skip to content

Commit

Permalink
Merge pull request #1 from forkineye/main
Browse files Browse the repository at this point in the history
Bring in changes from Main
  • Loading branch information
MartinMueller2003 authored Sep 1, 2021
2 parents 7101309 + 8376de8 commit d03710d
Show file tree
Hide file tree
Showing 31 changed files with 230 additions and 192 deletions.
15 changes: 8 additions & 7 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"configurations": [
{
"name": "WSL",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/../libraries/**",
"${workspaceFolder}/../tools/**",
"${workspaceFolder}/../hardware/esp8266com/esp8266/**"
],
"name": "ESP8266",
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"ARDUINO_ARCH_ESP8266"
],
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/../hardware/esp8266com/esp8266/tools/sdk/**",
"${workspaceFolder}/../hardware/esp8266com/esp8266/**",
"${workspaceFolder}/../libraries/**"
],
"compilerPath": "${workspaceFolder}/../hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
Expand Down
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"**/node_modules": true,
"**/.doxygen": true
},
"javascript.implicitProjectConfig.checkJs": true,
"js/ts.implicitProjectConfig.checkJs": true,
"files.associations": {
"array": "cpp",
"atomic": "cpp",
Expand Down Expand Up @@ -44,6 +44,7 @@
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"typeinfo": "cpp"
"typeinfo": "cpp",
"*.inc": "cpp"
}
}
30 changes: 9 additions & 21 deletions ESPixelStick.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@
*
*/

/*****************************************/
/* BEGIN - Configuration */
/*****************************************/

/*****************************************/
/* END - Configuration */
/*****************************************/

// Core
#include "src/ESPixelStick.h"
#include "src/EFUpdate.h"
Expand Down Expand Up @@ -80,8 +72,6 @@ static void _u0_putc(char c){
//
/////////////////////////////////////////////////////////

// Configuration file

const String VERSION = "4.0-dev (NOT STABLE)";
const String BUILD_DATE = String(__DATE__) + " - " + String(__TIME__);
const String CurrentConfigVersion = "1";
Expand Down Expand Up @@ -146,14 +136,15 @@ void setup()
OutputMgr.Begin ();
// DEBUG_V ("");

WiFiMgr.Begin (& config);
// DEBUG_V ("");

// connect the input processing to the output processing.
InputMgr.Begin (OutputMgr.GetBufferAddress (), OutputMgr.GetBufferUsedSize ());

// Wifi will be reset in the main loop since we just booted and de-serialized the config
WiFiMgr.Begin (& config);
// DEBUG_V ("");

// DEBUG_V ("");

// Configure and start the web server
WebMgr.Begin(&config);

Expand Down Expand Up @@ -205,11 +196,11 @@ void validateConfig()
} // validateConfig

/// Deserialize device confiugration JSON to config structure - returns true if config change detected
boolean dsDevice(JsonObject & json)
bool dsDevice(JsonObject & json)
{
// DEBUG_START;

boolean ConfigChanged = false;
bool ConfigChanged = false;
if (json.containsKey(CN_device))
{
JsonObject JsonDeviceConfig = json[CN_device];
Expand Down Expand Up @@ -242,11 +233,11 @@ boolean dsDevice(JsonObject & json)
} // dsDevice

/// Deserialize network confiugration JSON to config structure - returns true if config change detected
boolean dsNetwork(JsonObject & json)
bool dsNetwork(JsonObject & json)
{
// DEBUG_START;

boolean ConfigChanged = false;
bool ConfigChanged = false;
if (json.containsKey(CN_network))
{
#ifdef ARDUINO_ARCH_ESP8266
Expand Down Expand Up @@ -334,10 +325,7 @@ bool deserializeCore (JsonObject & json)
dsDevice (json);
FileMgr.SetConfig (json);
ResetWiFi = dsNetwork (json);
ResetWiFi;

DataHasBeenAccepted = true;

} while (false);

// DEBUG_END;
Expand Down Expand Up @@ -429,7 +417,7 @@ void GetConfig (JsonObject & json)
} // GetConfig

// Serialize the current config into a JSON string
String serializeCore(boolean pretty)
String serializeCore(bool pretty)
{
// DEBUG_START;

Expand Down
7 changes: 4 additions & 3 deletions src/ESPixelStick.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ typedef struct {
bool RebootOnWiFiFailureToConnect = true;
} config_t;

String serializeCore (boolean pretty = false);
String serializeCore (bool pretty = false);
void deserializeCoreHandler (DynamicJsonDocument& jsonDoc);
bool deserializeCore (JsonObject & json);
boolean dsDevice (JsonObject & json);
boolean dsNetwork (JsonObject & json);
bool dsDevice (JsonObject & json);
bool dsNetwork (JsonObject & json);
extern bool reboot;
extern bool ResetWiFi;
static const String ConfigFileName = "/config.json";

template <typename T, typename J, typename N>
Expand Down
20 changes: 13 additions & 7 deletions src/FileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,24 @@ void c_FileMgr::Begin ()
else
{
LOG_PORT.println (F ("Flash File system initialized."));
listDir (LITTLEFS, String ("/"), 3);
//listDir (LITTLEFS, String ("/"), 3);
}

SetSpiIoPins ();
// SetSpiIoPins will be called via SetConfig when we boot and config.json is loaded.
// No need to call it yet.
//SetSpiIoPins ();

} while (false);

// DEBUG_END;
} // begin

//-----------------------------------------------------------------------------
boolean c_FileMgr::SetConfig (JsonObject & json)
bool c_FileMgr::SetConfig (JsonObject & json)
{
// DEBUG_START;

boolean ConfigChanged = false;
bool ConfigChanged = false;
if (json.containsKey (CN_device))
{
JsonObject JsonDeviceConfig = json[CN_device];
Expand Down Expand Up @@ -218,7 +220,7 @@ void c_FileMgr::listDir (fs::FS& fs, String dirname, uint8_t levels)
//-----------------------------------------------------------------------------
bool c_FileMgr::LoadConfigFile (const String& FileName, DeserializationHandler Handler)
{
boolean retval = false;
bool retval = false;

do // once
{
Expand Down Expand Up @@ -353,7 +355,8 @@ bool c_FileMgr::ReadConfigFile (const String& FileName, String& FileData)
fs::File file = LITTLEFS.open (FileName.c_str (), CN_r);
if (file)
{
LOG_PORT.println (CfgFileMessagePrefix + String (F ("reading ")) + String (file.size()) + F (" bytes."));
// Supress this for now, may add it back later
//LOG_PORT.println (CfgFileMessagePrefix + String (F ("reading ")) + String (file.size()) + F (" bytes."));

// DEBUG_V (String("File '") + FileName + "' is open.");
file.seek (0, SeekSet);
Expand Down Expand Up @@ -444,10 +447,13 @@ bool c_FileMgr::ReadConfigFile (const String & FileName, byte * FileData, size_t
break;
}

// Supress this for now, may add it back later
/*
LOG_PORT.print (FileName);
LOG_PORT.print (" reading ");
LOG_PORT.print (file.size ());
LOG_PORT.println (" bytes.");
*/

// DEBUG_V (String("File '") + FileName + "' is open.");
file.seek (0, SeekSet);
Expand Down Expand Up @@ -635,7 +641,7 @@ void c_FileMgr::GetListOfSdFiles (String & Response)
// DEBUG_V ("EntryName: " + EntryName);
// DEBUG_V ("EntryName.length(): " + String(EntryName.length ()));

if ((0 != EntryName.length ()) &&
if ((0 != EntryName.length ()) &&
(EntryName != String (F ("System Volume Information"))) &&
(0 != entry.size ())
)
Expand Down
2 changes: 1 addition & 1 deletion src/FileMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class c_FileMgr
void Begin ();
void Poll ();
void GetConfig (JsonObject& json);
boolean SetConfig (JsonObject& json);
bool SetConfig (JsonObject& json);

void handleFileUpload (const String & filename, size_t index, uint8_t * data, size_t len, bool final);

Expand Down
44 changes: 27 additions & 17 deletions src/WebMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ void c_WebMgr::init ()
// Static Handler
webServer.serveStatic ("/", LITTLEFS, "/www/").setDefaultFile ("index.html");

// FS Debugging Handler
webServer.serveStatic ("/fs", LITTLEFS, "/" );

// if the client posts to the upload page
webServer.on ("/upload", HTTP_POST | HTTP_PUT | HTTP_OPTIONS,
[](AsyncWebServerRequest * request)
Expand Down Expand Up @@ -294,7 +297,7 @@ void c_WebMgr::init ()
espalexa.addDevice (pAlexaDevice);
espalexa.setDiscoverable ((nullptr != pAlexaCallback) ? true : false);

LOG_PORT.println (String (F ("- Web Server started on port ")) + HTTP_PORT);
log (String (F ("Web server listening on port ")) + HTTP_PORT);

// DEBUG_END;
}
Expand Down Expand Up @@ -378,7 +381,7 @@ void c_WebMgr::GetDeviceOptions ()

if (0 == webJsonDoc.capacity ())
{
LOG_PORT.println (F ("ERROR: Failed to allocate memory for the GetDeviceOptions web request response."));
log (F ("ERROR: Failed to allocate memory for the GetDeviceOptions web request response."));
}

// DEBUG_V ("");
Expand Down Expand Up @@ -425,7 +428,7 @@ void c_WebMgr::onWsEvent (AsyncWebSocket* server, AsyncWebSocketClient * client,
// only process text messages
if (MessageInfo->opcode != WS_TEXT)
{
LOG_PORT.println (F ("-- Ignore binary message --"));
log (F ("-- Ignore binary message --"));
break;
}
// DEBUG_V ("");
Expand All @@ -443,7 +446,8 @@ void c_WebMgr::onWsEvent (AsyncWebSocket* server, AsyncWebSocketClient * client,
if (WebSocketFrameCollectionBufferSize < (MessageInfo->index + len))
{
// message wont fit. Dont save any of it
LOG_PORT.println (CN_stars + String (F (" WebIO::onWsEvent(): Error: Incoming message is TOO long.")));
log (String (F ("*** onWsEvent() error: Incoming message is too long.")));
log (CN_stars + String (F (" WebIO::onWsEvent(): Error: Incoming message is TOO long.")));
break;
}

Expand Down Expand Up @@ -499,8 +503,8 @@ void c_WebMgr::onWsEvent (AsyncWebSocket* server, AsyncWebSocketClient * client,
// DEBUG_V ("");
if (error)
{
LOG_PORT.println (CN_stars + String (F (" WebIO::onWsEvent(): Parse Error: ")) + error.c_str ());
LOG_PORT.println (WebSocketFrameCollectionBuffer);
log (CN_stars + String (F (" WebIO::onWsEvent(): Parse Error: ")) + error.c_str ());
log (WebSocketFrameCollectionBuffer);
break;
}
// DEBUG_V ("");
Expand All @@ -513,26 +517,26 @@ void c_WebMgr::onWsEvent (AsyncWebSocket* server, AsyncWebSocketClient * client,

case WS_EVT_CONNECT:
{
LOG_PORT.println (String (F ("* WS Connect - ")) + client->id ());
log (String (F ("WS client connect - ")) + client->id ());
break;
} // case WS_EVT_CONNECT:

case WS_EVT_DISCONNECT:
{
LOG_PORT.println (String (F ("* WS Disconnect - ")) + client->id ());
log (String (F ("WS client disconnect - ")) + client->id ());
break;
} // case WS_EVT_DISCONNECT:

case WS_EVT_PONG:
{
LOG_PORT.println (F ("* WS PONG *"));
log (F ("* WS PONG *"));
break;
} // case WS_EVT_PONG:

case WS_EVT_ERROR:
default:
{
LOG_PORT.println (F ("** WS ERROR **"));
log (F ("** WS ERROR **"));
break;
}
} // end switch (type)
Expand Down Expand Up @@ -589,7 +593,7 @@ void c_WebMgr::ProcessXseriesRequests (AsyncWebSocketClient * client)

default:
{
LOG_PORT.println (String (F ("ERROR: Unhandled request: ")) + WebSocketFrameCollectionBuffer);
log (String (F ("ERROR: Unhandled request: ")) + WebSocketFrameCollectionBuffer);
client->text ((String (F ("{\"Error\":Error"))).c_str());
break;
}
Expand Down Expand Up @@ -688,7 +692,7 @@ void c_WebMgr::ProcessVseriesRequests (AsyncWebSocketClient* client)
default:
{
client->text (F ("V Error"));
LOG_PORT.println (String(CN_stars) + F (" ERROR: Unsupported Web command V") + WebSocketFrameCollectionBuffer[1] + CN_stars);
log (String(CN_stars) + F ("ERROR: Unsupported Web command V") + WebSocketFrameCollectionBuffer[1] + CN_stars);
break;
}
} // end switch
Expand Down Expand Up @@ -717,7 +721,7 @@ void c_WebMgr::ProcessGseriesRequests (AsyncWebSocketClient* client)
default:
{
client->text (F ("G Error"));
LOG_PORT.println (String(CN_stars) + F (" ERROR: Unsupported Web command V") + WebSocketFrameCollectionBuffer[1] + CN_stars);
log (String(CN_stars) + F ("ERROR: Unsupported Web command V") + WebSocketFrameCollectionBuffer[1] + CN_stars);
break;
}
} // end switch
Expand Down Expand Up @@ -848,7 +852,7 @@ void c_WebMgr::processCmdGet (JsonObject & jsonCmd)
(jsonCmd[CN_get] == CN_network) )
{
// DEBUG_V ("device/network");
FileMgr.ReadConfigFile (ConfigFileName,
FileMgr.ReadConfigFile (ConfigFileName,
(byte*)&WebSocketFrameCollectionBuffer[bufferoffset],
BufferFreeSize);
// DEBUG_V ("");
Expand Down Expand Up @@ -1083,7 +1087,7 @@ void c_WebMgr::FirmwareUpload (AsyncWebServerRequest* request,
#else
// this is not supported for ESP32
#endif
LOG_PORT.println (String(F ("* Upload Started: ")) + filename);
log (String(F ("Upload Started: ")) + filename);
efupdate.begin ();
}

Expand All @@ -1093,7 +1097,7 @@ void c_WebMgr::FirmwareUpload (AsyncWebServerRequest* request,

if (!efupdate.process (data, len))
{
LOG_PORT.println (String(CN_stars) + F (" UPDATE ERROR: ") + String (efupdate.getError ()));
log (String(CN_stars) + F (" UPDATE ERROR: ") + String (efupdate.getError ()));
}
// DEBUG_V ("Packet has been processed");

Expand All @@ -1108,7 +1112,7 @@ void c_WebMgr::FirmwareUpload (AsyncWebServerRequest* request,
if (final)
{
request->send (200, CN_textSLASHplain, (String ( F ("Update Finished: ")) + String (efupdate.getError ())).c_str());
LOG_PORT.println (F ("* Upload Finished."));
log (F ("Upload Finished."));
efupdate.end ();
LITTLEFS.begin ();

Expand Down Expand Up @@ -1136,6 +1140,12 @@ void c_WebMgr::Process ()
}
} // Process

// Serial console logging
void c_WebMgr::log(String message) {
LOG_PORT.println("[WebMgr] " + message);
} // log


#ifdef USE_REST
void printRequest (AsyncWebServerRequest* request)
{
Expand Down
Loading

0 comments on commit d03710d

Please sign in to comment.