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

Mobile-friendly HTML and improved password display #89

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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: 3 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ platform = [email protected]
framework = arduino
build_flags = !echo "-DPIO_SRC_REV="$(git rev-parse HEAD) "-DPIO_BUILD_DATE="$(date +%%Y-%%m-%%d) "-DPIO_BUILD_TIME="$(date +%%H:%%M:%%S) ${version_env.version_flags}
extra_scripts = pre:platformio_prebuild.py
upload_speed = 921600

# Platform specific settings

Expand All @@ -41,5 +42,5 @@ build_flags = ${env.build_flags} -Wl,-Tesp8266.flash.4m.ld
[env:esp01_1m]
board = esp01_1m

[env:esp01]
board = esp01
[env:esp8285]
board = esp8285
110 changes: 96 additions & 14 deletions src/mavesp8266_httpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const char PROGMEM kTEXTPLAIN[] = "text/plain";
const char PROGMEM kTEXTHTML[] = "text/html";
const char PROGMEM kACCESSCTL[] = "Access-Control-Allow-Origin";
const char PROGMEM kUPLOADFORM[] = "<h1><a href='/'>MAVLink WiFi Bridge</a></h1><form method='POST' action='/upload' enctype='multipart/form-data'><input type='file' name='update'><br><input type='submit' value='Update'></form>";
const char PROGMEM kHEADER[] = "<!doctype html><html><head><title>MavLink Bridge</title></head><body><h1><a href='/'>MAVLink WiFi Bridge</a></h1>";
const char PROGMEM kHEADER[] = "<!doctype html><html><head><meta name = 'viewport' content = 'user-scalable=no, initial-scale=1.0, maximum-scale=1.0, width=device-width'><title>MavLink Bridge</title></head><body><h1><a href='/'>MAVLink WiFi Bridge</a></h1>";
const char PROGMEM kBADARG[] = "BAD ARGS";
const char PROGMEM kAPPJSON[] = "application/json";

Expand Down 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
12 changes: 11 additions & 1 deletion src/mavesp8266_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ uint32_t _wifi_ip_address;
char _wifi_ssid[16];
char _wifi_password[16];
char _wifi_ssidsta[16];
char _wifi_passwordsta[16];
char _wifi_passwordsta[32];
uint32_t _wifi_ipsta;
uint32_t _wifi_gatewaysta;
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 All @@ -91,6 +93,10 @@ uint32_t _flash_left;
{"WIFI_PWDSTA2", &_wifi_passwordsta[4], MavESP8266Parameters::ID_PASSSTA2, sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false},
{"WIFI_PWDSTA3", &_wifi_passwordsta[8], MavESP8266Parameters::ID_PASSSTA3, sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false},
{"WIFI_PWDSTA4", &_wifi_passwordsta[12], MavESP8266Parameters::ID_PASSSTA4, sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false},
{"WIFI_PWDSTA5", &_wifi_passwordsta[16], MavESP8266Parameters::ID_PASSSTA5, sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false},
{"WIFI_PWDSTA6", &_wifi_passwordsta[20], MavESP8266Parameters::ID_PASSSTA6, sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false},
{"WIFI_PWDSTA7", &_wifi_passwordsta[24], MavESP8266Parameters::ID_PASSSTA7, sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false},
{"WIFI_PWDSTA8", &_wifi_passwordsta[28], MavESP8266Parameters::ID_PASSSTA8, sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false},
{"WIFI_IPSTA", &_wifi_ipsta, MavESP8266Parameters::ID_IPSTA, sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false},
{"WIFI_GATEWAYSTA", &_wifi_gatewaysta, MavESP8266Parameters::ID_GATEWAYSTA,sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false},
{"WIFI_SUBNET_STA", &_wifi_subnetsta, MavESP8266Parameters::ID_SUBNETSTA, sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false},
Expand Down Expand Up @@ -152,6 +158,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
6 changes: 6 additions & 0 deletions src/mavesp8266_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class MavESP8266Parameters {
ID_PASSSTA2,
ID_PASSSTA3,
ID_PASSSTA4,
ID_PASSSTA5,
ID_PASSSTA6,
ID_PASSSTA7,
ID_PASSSTA8,
ID_IPSTA,
ID_GATEWAYSTA,
ID_SUBNETSTA,
Expand Down Expand Up @@ -113,6 +117,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