Skip to content

Commit

Permalink
change handle_getParameters() to show parameters in a valid format NO…
Browse files Browse the repository at this point in the history
…T RAW!
  • Loading branch information
masoudir committed Oct 23, 2020
1 parent 3c8c130 commit 82aac08
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 13 deletions.
108 changes: 95 additions & 13 deletions src/mavesp8266_httpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,101 @@ void handle_getParameters()
String message = FPSTR(kHEADER);
message += "<p>Parameters</p><table><tr><td width=\"240\">Name</td><td>Value</td></tr>";
for(int i = 0; i < MavESP8266Parameters::ID_COUNT; i++) {
message += "<tr><td>";
message += getWorld()->getParameters()->getAt(i)->id;
message += "</td>";
unsigned long val = 0;
if(getWorld()->getParameters()->getAt(i)->type == MAV_PARAM_TYPE_UINT32)
val = (unsigned long)*((uint32_t*)getWorld()->getParameters()->getAt(i)->value);
else if(getWorld()->getParameters()->getAt(i)->type == MAV_PARAM_TYPE_UINT16)
val = (unsigned long)*((uint16_t*)getWorld()->getParameters()->getAt(i)->value);
else
val = (unsigned long)*((int8_t*)getWorld()->getParameters()->getAt(i)->value);
message += "<td>";
message += val;
message += "</td></tr>";
if(i == getWorld()->getParameters()->ID_FWVER)
{
message += "<tr><td>";
message += getWorld()->getParameters()->getAt(i)->id;
message += "</td>";
message += "<td>";
message += MAVESP8266_VERSION_MAJOR;
message += ".";
message += MAVESP8266_VERSION_MINOR;
message += ".";
message += MAVESP8266_VERSION_BUILD;
message += "</td></tr>";
}
else if(i == getWorld()->getParameters()->ID_MODE)
{
message += "<tr><td>";
message += getWorld()->getParameters()->getAt(i)->id;
message += "</td>";
message += "<td>";
if(getWorld()->getParameters()->getWifiMode() == WIFI_MODE_AP)
{
message += "AP";
}
else
{
message += "STA";
}
message += "</td></tr>";
}
else if(i == getWorld()->getParameters()->ID_IPADDRESS)
{
message += "<tr><td>";
message += getWorld()->getParameters()->getAt(i)->id;
message += "</td>";
message += "<td>";
message += getWorld()->getParameters()->getLocalIPAddressInString();
message += "</td></tr>";
}
else if(i == getWorld()->getParameters()->ID_SSID1)
{
message += "<tr><td>";
message += getWorld()->getParameters()->getAt(i)->id;
message += "</td>";
message += "<td>";
message += getWorld()->getParameters()->getWifiSsid();
message += "</td></tr>";
}
else if(i > getWorld()->getParameters()->ID_SSID1 && i <= getWorld()->getParameters()->ID_SSID4) {}
else if(i == getWorld()->getParameters()->ID_PASS1)
{
message += "<tr><td>";
message += getWorld()->getParameters()->getAt(i)->id;
message += "</td>";
message += "<td>";
message += getWorld()->getParameters()->getWifiPassword();
message += "</td></tr>";
}
else if(i > getWorld()->getParameters()->ID_PASS1 && i <= getWorld()->getParameters()->ID_PASS4) {}
else if(i == getWorld()->getParameters()->ID_SSIDSTA1)
{
message += "<tr><td>";
message += getWorld()->getParameters()->getAt(i)->id;
message += "</td>";
message += "<td>";
message += getWorld()->getParameters()->getWifiStaSsid();
message += "</td></tr>";
}
else if(i > getWorld()->getParameters()->ID_SSIDSTA1 && i <= getWorld()->getParameters()->ID_SSIDSTA4) {}
else if(i == getWorld()->getParameters()->ID_PASSSTA1)
{
message += "<tr><td>";
message += getWorld()->getParameters()->getAt(i)->id;
message += "</td>";
message += "<td>";
message += getWorld()->getParameters()->getWifiStaPassword();
message += "</td></tr>";
}
else if(i > getWorld()->getParameters()->ID_PASSSTA1 && i <= getWorld()->getParameters()->ID_PASSSTA4) {}
else // integer values
{
message += "<tr><td>";
message += getWorld()->getParameters()->getAt(i)->id;
message += "</td>";
unsigned long val = 0;
if(getWorld()->getParameters()->getAt(i)->type == MAV_PARAM_TYPE_UINT32)
val = (unsigned long)*((uint32_t*)getWorld()->getParameters()->getAt(i)->value);
else if(getWorld()->getParameters()->getAt(i)->type == MAV_PARAM_TYPE_UINT16)
val = (unsigned long)*((uint16_t*)getWorld()->getParameters()->getAt(i)->value);
else
val = (unsigned long)*((int8_t*)getWorld()->getParameters()->getAt(i)->value);

message += "<td>";
message += val;
message += "</td></tr>";
}
}
message += "</table>";
message += "</body>";
Expand Down
6 changes: 6 additions & 0 deletions src/mavesp8266_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ uint32_t _wifi_subnetsta;
uint32_t _uart_baud_rate;
uint32_t _flash_left;

String _wifi_ip_addr_string;

//-- Parameters
// No string support in parameters so we stash a char[16] into 4 uint32_t
struct stMavEspParameters mavParameters[] = {
Expand Down Expand Up @@ -152,6 +154,10 @@ uint32_t MavESP8266Parameters::getWifiStaGateway () { return _wifi_gatewaysta
uint32_t MavESP8266Parameters::getWifiStaSubnet () { return _wifi_subnetsta; }
uint32_t MavESP8266Parameters::getUartBaudRate () { return _uart_baud_rate; }

String MavESP8266Parameters::getLocalIPAddressInString()
{
return(_wifi_ip_addr_string);
}
//---------------------------------------------------------------------------------
//-- Reset all to defaults
void
Expand Down
2 changes: 2 additions & 0 deletions src/mavesp8266_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class MavESP8266Parameters {
uint32_t getWifiStaSubnet ();
uint32_t getUartBaudRate ();

String getLocalIPAddressInString ();

void setDebugEnabled (int8_t enabled);
void setWifiMode (int8_t mode);
void setWifiChannel (uint32_t channel);
Expand Down

0 comments on commit 82aac08

Please sign in to comment.