Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FPP discovery to work better with FPP7 and xLights 2023.* #642

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ESPixelStick/src/WebMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ void c_WebMgr::init ()
{
FPPDiscovery.ProcessGET(request);
});
webServer.on ("/api/system", HTTP_GET,
[](AsyncWebServerRequest* request)
{
FPPDiscovery.ProcessGET(request);
});

webServer.on ("/fpp", HTTP_POST | HTTP_PUT,
[](AsyncWebServerRequest* request)
Expand Down
164 changes: 95 additions & 69 deletions ESPixelStick/src/service/FPPDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,16 +621,16 @@ void c_FPPDiscovery::ProcessGET (AsyncWebServerRequest* request)

do // once
{
if (!request->hasParam (ulrPath))
String path = request->url();
if (path.startsWith("/fpp/"))
{
request->send (404);
// DEBUG_V ("");
break;
path = path.substring(4);
}

// DEBUG_V ("");

String path = request->getParam (ulrPath)->value ();
if (request->hasParam (ulrPath))
{
path = request->getParam (ulrPath)->value ();
}

// DEBUG_V (String ("Path: ") + path);

Expand Down Expand Up @@ -662,7 +662,27 @@ void c_FPPDiscovery::ProcessGET (AsyncWebServerRequest* request)
}
}
logcon (String (F ("Could not open: ")) + seq);
}
}
}
else if (path.startsWith (F ("/api/system/status")))
{
String Response;
DynamicJsonDocument JsonDoc (2048);
JsonObject JsonData = JsonDoc.to<JsonObject> ();
GetStatusJSON(JsonData, true);
serializeJson (JsonDoc, Response);
// DEBUG_V (String ("JsonDoc: ") + Response);
request->send (200, F ("application/json"), Response);
}
else if (path.startsWith (F ("/api/system/info")))
{
String Response;
DynamicJsonDocument JsonDoc (2048);
JsonObject JsonData = JsonDoc.to<JsonObject> ();
GetSysInfoJSON(JsonData);
serializeJson (JsonDoc, Response);
// DEBUG_V (String ("JsonDoc: ") + Response);
request->send (200, F ("application/json"), Response);
}
request->send (404);

Expand Down Expand Up @@ -858,6 +878,72 @@ void c_FPPDiscovery::GetSysInfoJSON (JsonObject & jsonResponse)

} // GetSysInfoJSON

void c_FPPDiscovery::GetStatusJSON (JsonObject & JsonData, bool adv)
{
JsonObject JsonDataMqtt = JsonData.createNestedObject(F ("MQTT"));

JsonDataMqtt[F ("configured")] = false;
JsonDataMqtt[F ("connected")] = false;

JsonObject JsonDataCurrentPlaylist = JsonData.createNestedObject (F ("current_playlist"));

JsonDataCurrentPlaylist[CN_count] = "0";
JsonDataCurrentPlaylist[F ("description")] = "";
JsonDataCurrentPlaylist[F ("index")] = "0";
JsonDataCurrentPlaylist[CN_playlist] = "";
JsonDataCurrentPlaylist[CN_type] = "";

JsonData[F ("volume")] = 70;
JsonData[F ("media_filename")] = "";
JsonData[F ("fppd")] = F ("running");
JsonData[F ("current_song")] = "";

if (false == PlayingFile())
{
JsonData[CN_current_sequence] = "";
JsonData[CN_playlist] = "";
JsonData[CN_seconds_elapsed] = String (0);
JsonData[CN_seconds_played] = String (0);
JsonData[CN_seconds_remaining] = String (0);
JsonData[CN_sequence_filename] = "";
JsonData[CN_time_elapsed] = String("00:00");
JsonData[CN_time_remaining] = String ("00:00");

JsonData[CN_status] = 0;
JsonData[CN_status_name] = F ("idle");

if (IsEnabled)
{
JsonData[CN_mode] = 8;
JsonData[CN_mode_name] = CN_remote;
}
else
{
JsonData[CN_mode] = 1;
JsonData[CN_mode_name] = CN_bridge;
}
}
else
{
if (InputFPPRemotePlayFile)
{
InputFPPRemotePlayFile->GetStatus (JsonData);
}
JsonData[CN_status] = 1;
JsonData[CN_status_name] = F ("playing");

JsonData[CN_mode] = 8;
JsonData[CN_mode_name] = CN_remote;
}

if (adv)
{
JsonObject JsonDataAdvancedView = JsonData.createNestedObject (F ("advancedView"));
GetSysInfoJSON (JsonDataAdvancedView);
}

}

//-----------------------------------------------------------------------------
void c_FPPDiscovery::ProcessFPPJson (AsyncWebServerRequest* request)
{
Expand Down Expand Up @@ -888,67 +974,7 @@ void c_FPPDiscovery::ProcessFPPJson (AsyncWebServerRequest* request)
adv = request->getParam (CN_advancedView)->value ();
}

JsonObject JsonDataMqtt = JsonData.createNestedObject(F ("MQTT"));

JsonDataMqtt[F ("configured")] = false;
JsonDataMqtt[F ("connected")] = false;

JsonObject JsonDataCurrentPlaylist = JsonData.createNestedObject (F ("current_playlist"));

JsonDataCurrentPlaylist[CN_count] = "0";
JsonDataCurrentPlaylist[F ("description")] = "";
JsonDataCurrentPlaylist[F ("index")] = "0";
JsonDataCurrentPlaylist[CN_playlist] = "";
JsonDataCurrentPlaylist[CN_type] = "";

JsonData[F ("volume")] = 70;
JsonData[F ("media_filename")] = "";
JsonData[F ("fppd")] = F ("running");
JsonData[F ("current_song")] = "";

if (false == PlayingFile())
{
JsonData[CN_current_sequence] = "";
JsonData[CN_playlist] = "";
JsonData[CN_seconds_elapsed] = String (0);
JsonData[CN_seconds_played] = String (0);
JsonData[CN_seconds_remaining] = String (0);
JsonData[CN_sequence_filename] = "";
JsonData[CN_time_elapsed] = String("00:00");
JsonData[CN_time_remaining] = String ("00:00");

JsonData[CN_status] = 0;
JsonData[CN_status_name] = F ("idle");

if (IsEnabled)
{
JsonData[CN_mode] = 8;
JsonData[CN_mode_name] = CN_remote;
}
else
{
JsonData[CN_mode] = 1;
JsonData[CN_mode_name] = CN_bridge;
}
}
else
{
if (InputFPPRemotePlayFile)
{
InputFPPRemotePlayFile->GetStatus (JsonData);
}
JsonData[CN_status] = 1;
JsonData[CN_status_name] = F ("playing");

JsonData[CN_mode] = 8;
JsonData[CN_mode_name] = CN_remote;
}

if (adv == CN_true)
{
JsonObject JsonDataAdvancedView = JsonData.createNestedObject (F ("advancedView"));
GetSysInfoJSON (JsonDataAdvancedView);
}
GetStatusJSON(JsonData, adv == CN_true);

String Response;
serializeJson (JsonDoc, Response);
Expand Down
1 change: 1 addition & 0 deletions ESPixelStick/src/service/FPPDiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class c_FPPDiscovery
const IPAddress MulticastAddress = IPAddress (239, 70, 80, 80);

void GetSysInfoJSON (JsonObject& jsonResponse);
void GetStatusJSON (JsonObject& jsonResponse, bool advanced);
void BuildFseqResponse (String fname, c_FileMgr::FileId fseq, String & resp);
void StopPlaying ();
void StartPlaying (String & FileName, float SecondsElapsed);
Expand Down