mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-05-19 10:32:56 +00:00
included ip method and connection in config
This commit is contained in:
parent
04b605b7d4
commit
fb142d0491
4 changed files with 38 additions and 45 deletions
|
@ -22,11 +22,11 @@
|
||||||
id="input-ip-method"
|
id="input-ip-method"
|
||||||
title="IP-"
|
title="IP-"
|
||||||
>
|
>
|
||||||
<option value="static">Statisch</option>
|
<option value="0">Statisch</option>
|
||||||
<option value="dhcp">DHCP</option>
|
<option value="1">DHCP</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<div data-field="input-ip-method" data-values="static">
|
<div data-field="input-ip-method" data-values="0">
|
||||||
<label>
|
<label>
|
||||||
IP-Adresse:
|
IP-Adresse:
|
||||||
<input
|
<input
|
||||||
|
@ -62,12 +62,12 @@
|
||||||
id="input-connection"
|
id="input-connection"
|
||||||
title="Verbindung"
|
title="Verbindung"
|
||||||
>
|
>
|
||||||
<option value="wifi-sta">WiFi-Station</option>
|
<option value="0">WiFi-Station</option>
|
||||||
<option value="wifi-ap">WiFi-AccessPoint</option>
|
<option value="1">WiFi-AccessPoint</option>
|
||||||
<option value="ethernet">Ethernet</option>
|
<option value="2">Ethernet</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<div data-field="input-connection" data-values="wifi-sta">
|
<div data-field="input-connection" data-values="0">
|
||||||
<label>
|
<label>
|
||||||
SSID:
|
SSID:
|
||||||
<input
|
<input
|
||||||
|
@ -78,7 +78,7 @@
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div data-field="input-connection" data-values="wifi-ap">
|
<div data-field="input-connection" data-values="1">
|
||||||
<label>
|
<label>
|
||||||
Netzwerk:
|
Netzwerk:
|
||||||
<select
|
<select
|
||||||
|
@ -88,10 +88,7 @@
|
||||||
></select>
|
></select>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div data-field="input-connection" data-values="0|1">
|
||||||
data-field="input-connection"
|
|
||||||
data-values="wifi-sta|wifi-ap"
|
|
||||||
>
|
|
||||||
<label>
|
<label>
|
||||||
Password:
|
Password:
|
||||||
<input
|
<input
|
||||||
|
|
|
@ -28,6 +28,9 @@ void setup()
|
||||||
Direction direction1 = static_cast<Direction>(config.getUInt("direction-1", 0));
|
Direction direction1 = static_cast<Direction>(config.getUInt("direction-1", 0));
|
||||||
Direction direction2 = static_cast<Direction>(config.getUInt("direction-2", 1));
|
Direction direction2 = static_cast<Direction>(config.getUInt("direction-2", 1));
|
||||||
|
|
||||||
|
Connection connection = static_cast<Connection>(config.getUInt("connection", WiFiSta));
|
||||||
|
IpMethod ipMethod = static_cast<IpMethod>(config.getUInt("ip-method"), Static);
|
||||||
|
|
||||||
String ssid = config.getString("ssid", "artnet");
|
String ssid = config.getString("ssid", "artnet");
|
||||||
String pwd = config.getString("password", "mbgmbgmbg");
|
String pwd = config.getString("password", "mbgmbgmbg");
|
||||||
IPAddress defaultIp(192, 168, 1, 201);
|
IPAddress defaultIp(192, 168, 1, 201);
|
||||||
|
@ -76,8 +79,8 @@ void setup()
|
||||||
|
|
||||||
server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html");
|
server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html");
|
||||||
|
|
||||||
server.on("/config", HTTP_GET, [&, defaultIp, subnet, gateway, ssid, pwd, direction1, universe1, direction2, universe2](AsyncWebServerRequest *request)
|
server.on("/config", HTTP_GET, [&, ipMethod, defaultIp, subnet, connection, gateway, ssid, pwd, direction1, universe1, direction2, universe2](AsyncWebServerRequest *request)
|
||||||
{ onGetConfig(ssid, pwd, defaultIp, subnet, gateway, universe1, direction1, universe2, direction2, request); });
|
{ onGetConfig(connection, ssid, pwd, ipMethod, defaultIp, subnet, gateway, universe1, direction1, universe2, direction2, request); });
|
||||||
|
|
||||||
server.onRequestBody([](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total)
|
server.onRequestBody([](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total)
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,48 +38,31 @@ uint32_t parseIp(String str)
|
||||||
return atoi(ip.c_str());
|
return atoi(ip.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
IpMethod parseIpMethod(String ipMethod)
|
IpMethod parseIpMethod(uint8_t ipMethod)
|
||||||
{
|
{
|
||||||
if (ipMethod == "static")
|
if (ipMethod > 0 || ipMethod < IP_METHOD_SIZE)
|
||||||
{
|
{
|
||||||
return Static;
|
return static_cast<IpMethod>(ipMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ipMethod == "dhcp")
|
throw ::std::invalid_argument("Invalid IP method value" + ipMethod);
|
||||||
{
|
|
||||||
return DHCP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw ::std::invalid_argument("Invalid IP method value");
|
Connection parseConnection(uint8_t connection)
|
||||||
|
{
|
||||||
|
if (connection > 0 || connection < CONNECTION_SIZE)
|
||||||
|
{
|
||||||
|
return static_cast<Connection>(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection parseConnection(String connection)
|
throw ::std::invalid_argument("Invalid connection value: " + connection);
|
||||||
{
|
|
||||||
if (connection == "wifi-sta")
|
|
||||||
{
|
|
||||||
return WiFiSta;
|
|
||||||
}
|
|
||||||
if (connection == "wifi-ap")
|
|
||||||
{
|
|
||||||
return WiFiAP;
|
|
||||||
}
|
|
||||||
if (connection == "ethernet")
|
|
||||||
{
|
|
||||||
return Ethernet;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw ::std::invalid_argument("Invalid connection value");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Direction parseDirection(uint8_t direction)
|
Direction parseDirection(uint8_t direction)
|
||||||
{
|
{
|
||||||
if (direction == 0)
|
if (direction > 0 || direction < DIRECTION_SIZE)
|
||||||
{
|
{
|
||||||
return Output;
|
return static_cast<Direction>(direction);
|
||||||
}
|
|
||||||
if (direction == 1)
|
|
||||||
{
|
|
||||||
return Input;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw ::std::invalid_argument("Invalid direction value: " + direction);
|
throw ::std::invalid_argument("Invalid direction value: " + direction);
|
||||||
|
@ -88,8 +71,10 @@ Direction parseDirection(uint8_t direction)
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
void onGetConfig(
|
void onGetConfig(
|
||||||
|
Connection connection,
|
||||||
String ssid,
|
String ssid,
|
||||||
String pwd,
|
String pwd,
|
||||||
|
IpMethod ipMethod,
|
||||||
uint32_t ip,
|
uint32_t ip,
|
||||||
uint32_t subnet,
|
uint32_t subnet,
|
||||||
uint32_t gateway,
|
uint32_t gateway,
|
||||||
|
@ -110,8 +95,10 @@ void onGetConfig(
|
||||||
ipAddr = gateway;
|
ipAddr = gateway;
|
||||||
String gatewayString = ipAddr.toString();
|
String gatewayString = ipAddr.toString();
|
||||||
|
|
||||||
|
doc["connection"] = connection;
|
||||||
doc["ssid"] = ssid;
|
doc["ssid"] = ssid;
|
||||||
doc["password"] = pwd;
|
doc["password"] = pwd;
|
||||||
|
doc["ip-method"] = ipMethod;
|
||||||
doc["ip"] = ipString;
|
doc["ip"] = ipString;
|
||||||
doc["subnet"] = subnetString;
|
doc["subnet"] = subnetString;
|
||||||
doc["gateway"] = gatewayString;
|
doc["gateway"] = gatewayString;
|
||||||
|
@ -135,7 +122,7 @@ void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IpMethod ipMethod = parseIpMethod(doc["ip-method"].as<String>());
|
IpMethod ipMethod = parseIpMethod(doc["ip-method"].as<uint8_t>());
|
||||||
config.putUInt("ip-method", ipMethod);
|
config.putUInt("ip-method", ipMethod);
|
||||||
|
|
||||||
if (ipMethod == Static)
|
if (ipMethod == Static)
|
||||||
|
@ -153,8 +140,9 @@ void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size
|
||||||
config.putUInt("gateway", gateway);
|
config.putUInt("gateway", gateway);
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection connection = parseConnection(doc["connection"].as<String>());
|
Connection connection = parseConnection(doc["connection"].as<uint8_t>());
|
||||||
config.putUInt("connection", connection);
|
config.putUInt("connection", connection);
|
||||||
|
|
||||||
if (connection == WiFiSta || connection == WiFiAP)
|
if (connection == WiFiSta || connection == WiFiAP)
|
||||||
{
|
{
|
||||||
config.putString("ssid", doc["ssid"].as<String>());
|
config.putString("ssid", doc["ssid"].as<String>());
|
||||||
|
|
|
@ -14,6 +14,7 @@ enum IpMethod
|
||||||
Static,
|
Static,
|
||||||
DHCP
|
DHCP
|
||||||
};
|
};
|
||||||
|
const uint8_t IP_METHOD_SIZE = 2;
|
||||||
|
|
||||||
enum Connection
|
enum Connection
|
||||||
{
|
{
|
||||||
|
@ -21,16 +22,20 @@ enum Connection
|
||||||
WiFiAP,
|
WiFiAP,
|
||||||
Ethernet
|
Ethernet
|
||||||
};
|
};
|
||||||
|
const uint8_t CONNECTION_SIZE = 3;
|
||||||
|
|
||||||
enum Direction
|
enum Direction
|
||||||
{
|
{
|
||||||
Input,
|
Output,
|
||||||
Output
|
Input
|
||||||
};
|
};
|
||||||
|
const uint8_t DIRECTION_SIZE = 2;
|
||||||
|
|
||||||
void onGetConfig(
|
void onGetConfig(
|
||||||
|
Connection connection,
|
||||||
String ssid,
|
String ssid,
|
||||||
String pwd,
|
String pwd,
|
||||||
|
IpMethod ipMethod,
|
||||||
uint32_t ip,
|
uint32_t ip,
|
||||||
uint32_t subnet,
|
uint32_t subnet,
|
||||||
uint32_t gateway,
|
uint32_t gateway,
|
||||||
|
|
Loading…
Add table
Reference in a new issue