Skip to content
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
2 changes: 1 addition & 1 deletion Firmware/RTK_Everywhere/Developer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ bool webServerStart(int httpPort = 80)
systemPrintln("**AP not compiled**");
return false;
}
bool parseIncomingSettings() {return false;}
bool webSocketsParseIncomingSettings() {return false;}
void sendStringToWebsocket(const char* stringToSend) {}
void stopWebServer() {}
bool webServerSettingsCheckAndFree() {return false;}
Expand Down
2 changes: 1 addition & 1 deletion Firmware/RTK_Everywhere/States.ino
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ void stateUpdate()
// Useful for detecting when we need to change WiFi station settings
wifiSettingsClone();

parseIncomingSettings();
webSocketsParseIncomingSettings();

gnssConfigureDefaults(); // Set all bits in the request bitfield to cause the GNSS receiver to go
// through a full (re)configuration
Expand Down
88 changes: 1 addition & 87 deletions Firmware/RTK_Everywhere/WebServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,6 @@ static const int webServerTaskStackSize = 1024 * 4; // Needs to be large enoug
// https://www.youtube.com/watch?v=15X0WvGaVg8
// https://github.com/espressif/arduino-esp32/blob/master/libraries/WebServer/examples/WebServer/WebServer.ino

//----------------------------------------
// When called, responds with the RTCM/Base messages supported on this platform
// Message name and current rate are formatted in CSV, formatted to html by JS
//----------------------------------------
void createMessageListBase(String &returnText)
{
returnText = "";
gnss->createMessageListBase(returnText);
if (settings.debugWebServer == true)
systemPrintf("returnText (%d bytes): %s\r\n", returnText.length(), returnText.c_str());
}

//----------------------------------------
// Handler for firmware file downloads
//----------------------------------------
Expand Down Expand Up @@ -453,80 +441,6 @@ bool knownCaptiveUrl(String uri)
return false;
}

//----------------------------------------
// Break CSV into setting constituents
// Can't use strtok because we may have two commas next to each other, ie
// measurementRateHz,4.00,measurementRateSec,,dynamicModel,0,
//----------------------------------------
bool parseIncomingSettings()
{
char settingName[100] = {'\0'};
char valueStr[150] = {'\0'}; // stationGeodetic1,ANameThatIsTooLongToBeDisplayed 40.09029479 -105.18505761 1560.089

bool stationGeodeticSeen = false;
bool stationECEFSeen = false;

char *commaPtr = incomingSettings;
char *headPtr = incomingSettings;

int counter = 0;
int maxAttempts = 500;
while (*headPtr) // Check if we've reached the end of the string
{
// Spin to first comma
commaPtr = strstr(headPtr, ",");
if (commaPtr != nullptr)
{
*commaPtr = '\0';
strcpy(settingName, headPtr);
headPtr = commaPtr + 1;
}

commaPtr = strstr(headPtr, ",");
if (commaPtr != nullptr)
{
*commaPtr = '\0';
strcpy(valueStr, headPtr);
headPtr = commaPtr + 1;
}

if (settings.debugWebServer == true)
systemPrintf("settingName: %s value: %s\r\n", settingName, valueStr);

// Check for first stationGeodetic
if ((strstr(settingName, "stationGeodetic") != nullptr) && (!stationGeodeticSeen))
{
stationGeodeticSeen = true;
removeFile(stationCoordinateGeodeticFileName);
if (settings.debugWebServer == true)
systemPrintln("Station geodetic coordinate file removed");
}

// Check for first stationECEF
if ((strstr(settingName, "stationECEF") != nullptr) && (!stationECEFSeen))
{
stationECEFSeen = true;
removeFile(stationCoordinateECEFFileName);
if (settings.debugWebServer == true)
systemPrintln("Station ECEF coordinate file removed");
}

updateSettingWithValue(false, settingName, valueStr);

// Avoid infinite loop if response is malformed
counter++;
if (counter == maxAttempts)
{
systemPrintln("Error: Incoming settings malformed.");
break;
}
}

systemPrintln("Parsing complete");

return (true);
}

//----------------------------------------
// Stop the web server
//----------------------------------------
Expand Down Expand Up @@ -719,7 +633,7 @@ bool webServerAssignResources(int httpPort = 80)
if (settings.debugWebServer == true)
systemPrintln(logmessage);
String messageList;
createMessageListBase(messageList);
webSocketsCreateMessageListBase(messageList);
if (settings.debugWebServer == true)
systemPrintln(messageList);
webServer->send(200, "text/plain", messageList);
Expand Down
113 changes: 112 additions & 1 deletion Firmware/RTK_Everywhere/WebSockets.ino
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static SemaphoreHandle_t webSocketsMutex;

esp_err_t webSocketsHandlerFileList(httpd_req_t *req);
esp_err_t webSocketsHandlerGetPage(httpd_req_t *req);
esp_err_t webSocketsHandlerListBaseMessages(httpd_req_t *req);
esp_err_t webSocketsHandlerListMessages(httpd_req_t *req);

//----------------------------------------
Expand Down Expand Up @@ -134,9 +135,10 @@ const GET_PAGE_HANDLER webSocketsPages[] =

// Message handlers
PAGE_HANDLER(23, "/listMessages", HTTP_GET, text_plain, webSocketsHandlerListMessages),
PAGE_HANDLER(24, "/listMessagesBase", HTTP_GET, text_plain, webSocketsHandlerListBaseMessages),

// Add pages above this line
WEB_PAGE(24, "/", text_html, index_html),
WEB_PAGE(25, "/", text_html, index_html),
};

#define WEB_SOCKETS_SPECIAL_PAGES 2
Expand Down Expand Up @@ -253,6 +255,18 @@ void webSocketsCreateMessageList(String &returnText)
systemPrintf("returnText (%d bytes): %s\r\n", returnText.length(), returnText.c_str());
}

//----------------------------------------
// When called, responds with the RTCM/Base messages supported on this platform
// Message name and current rate are formatted in CSV, formatted to html by JS
//----------------------------------------
void webSocketsCreateMessageListBase(String &returnText)
{
returnText = "";
gnss->createMessageListBase(returnText);
if (settings.debugWebServer == true)
systemPrintf("returnText (%d bytes): %s\r\n", returnText.length(), returnText.c_str());
}

//----------------------------------------
// Display the request
//----------------------------------------
Expand Down Expand Up @@ -625,6 +639,29 @@ esp_err_t webSocketsHandlerGetPage(httpd_req_t *req)
return httpd_resp_send(req, (const char *)webpage->_data, webpage->_length);
}

//----------------------------------------
// Handler for supported RTCM/Base messages list
//----------------------------------------
esp_err_t webSocketsHandlerListBaseMessages(httpd_req_t *req)
{
size_t bytes;
const char * data;
char ipAddress[80];
String messageList;

// Get the messages list
webSocketsCreateMessageListBase(messageList);
data = messageList.c_str();
bytes = messageList.length();

// Display the request and response
webSocketsDisplayRequestAndData(req, data, bytes);

// Send the response
httpd_resp_set_type(req, text_plain);
return httpd_resp_send(req, data, bytes);
}

//----------------------------------------
// Handler for supported messages list
//----------------------------------------
Expand Down Expand Up @@ -706,6 +743,80 @@ bool webSocketsIsConnected()
return (webSocketsClientListHead != nullptr);
}

//----------------------------------------
// Break CSV into setting constituents
// Can't use strtok because we may have two commas next to each other, ie
// measurementRateHz,4.00,measurementRateSec,,dynamicModel,0,
//----------------------------------------
bool webSocketsParseIncomingSettings()
{
char settingName[100] = {'\0'};
char valueStr[150] = {'\0'}; // stationGeodetic1,ANameThatIsTooLongToBeDisplayed 40.09029479 -105.18505761 1560.089

bool stationGeodeticSeen = false;
bool stationECEFSeen = false;

char *commaPtr = incomingSettings;
char *headPtr = incomingSettings;

int counter = 0;
int maxAttempts = 500;
while (*headPtr) // Check if we've reached the end of the string
{
// Spin to first comma
commaPtr = strstr(headPtr, ",");
if (commaPtr != nullptr)
{
*commaPtr = '\0';
strcpy(settingName, headPtr);
headPtr = commaPtr + 1;
}

commaPtr = strstr(headPtr, ",");
if (commaPtr != nullptr)
{
*commaPtr = '\0';
strcpy(valueStr, headPtr);
headPtr = commaPtr + 1;
}

if (settings.debugWebServer == true)
systemPrintf("settingName: %s value: %s\r\n", settingName, valueStr);

// Check for first stationGeodetic
if ((strstr(settingName, "stationGeodetic") != nullptr) && (!stationGeodeticSeen))
{
stationGeodeticSeen = true;
removeFile(stationCoordinateGeodeticFileName);
if (settings.debugWebServer == true)
systemPrintln("Station geodetic coordinate file removed");
}

// Check for first stationECEF
if ((strstr(settingName, "stationECEF") != nullptr) && (!stationECEFSeen))
{
stationECEFSeen = true;
removeFile(stationCoordinateECEFFileName);
if (settings.debugWebServer == true)
systemPrintln("Station ECEF coordinate file removed");
}

updateSettingWithValue(false, settingName, valueStr);

// Avoid infinite loop if response is malformed
counter++;
if (counter == maxAttempts)
{
systemPrintln("Error: Incoming settings malformed.");
break;
}
}

systemPrintln("Parsing complete");

return (true);
}

//----------------------------------------
// Register an error handler
//----------------------------------------
Expand Down