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"
|
||||
title="IP-"
|
||||
>
|
||||
<option value="static">Statisch</option>
|
||||
<option value="dhcp">DHCP</option>
|
||||
<option value="0">Statisch</option>
|
||||
<option value="1">DHCP</option>
|
||||
</select>
|
||||
</label>
|
||||
<div data-field="input-ip-method" data-values="static">
|
||||
<div data-field="input-ip-method" data-values="0">
|
||||
<label>
|
||||
IP-Adresse:
|
||||
<input
|
||||
|
@ -62,12 +62,12 @@
|
|||
id="input-connection"
|
||||
title="Verbindung"
|
||||
>
|
||||
<option value="wifi-sta">WiFi-Station</option>
|
||||
<option value="wifi-ap">WiFi-AccessPoint</option>
|
||||
<option value="ethernet">Ethernet</option>
|
||||
<option value="0">WiFi-Station</option>
|
||||
<option value="1">WiFi-AccessPoint</option>
|
||||
<option value="2">Ethernet</option>
|
||||
</select>
|
||||
</label>
|
||||
<div data-field="input-connection" data-values="wifi-sta">
|
||||
<div data-field="input-connection" data-values="0">
|
||||
<label>
|
||||
SSID:
|
||||
<input
|
||||
|
@ -78,7 +78,7 @@
|
|||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div data-field="input-connection" data-values="wifi-ap">
|
||||
<div data-field="input-connection" data-values="1">
|
||||
<label>
|
||||
Netzwerk:
|
||||
<select
|
||||
|
@ -88,10 +88,7 @@
|
|||
></select>
|
||||
</label>
|
||||
</div>
|
||||
<div
|
||||
data-field="input-connection"
|
||||
data-values="wifi-sta|wifi-ap"
|
||||
>
|
||||
<div data-field="input-connection" data-values="0|1">
|
||||
<label>
|
||||
Password:
|
||||
<input
|
||||
|
|
|
@ -28,6 +28,9 @@ void setup()
|
|||
Direction direction1 = static_cast<Direction>(config.getUInt("direction-1", 0));
|
||||
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 pwd = config.getString("password", "mbgmbgmbg");
|
||||
IPAddress defaultIp(192, 168, 1, 201);
|
||||
|
@ -76,8 +79,8 @@ void setup()
|
|||
|
||||
server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html");
|
||||
|
||||
server.on("/config", HTTP_GET, [&, defaultIp, subnet, gateway, ssid, pwd, direction1, universe1, direction2, universe2](AsyncWebServerRequest *request)
|
||||
{ onGetConfig(ssid, pwd, defaultIp, subnet, gateway, universe1, direction1, universe2, direction2, request); });
|
||||
server.on("/config", HTTP_GET, [&, ipMethod, defaultIp, subnet, connection, gateway, ssid, pwd, direction1, universe1, direction2, universe2](AsyncWebServerRequest *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)
|
||||
{
|
||||
|
|
|
@ -38,48 +38,31 @@ uint32_t parseIp(String 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")
|
||||
{
|
||||
return DHCP;
|
||||
}
|
||||
|
||||
throw ::std::invalid_argument("Invalid IP method value");
|
||||
throw ::std::invalid_argument("Invalid IP method value" + ipMethod);
|
||||
}
|
||||
|
||||
Connection parseConnection(String connection)
|
||||
Connection parseConnection(uint8_t connection)
|
||||
{
|
||||
if (connection == "wifi-sta")
|
||||
if (connection > 0 || connection < CONNECTION_SIZE)
|
||||
{
|
||||
return WiFiSta;
|
||||
}
|
||||
if (connection == "wifi-ap")
|
||||
{
|
||||
return WiFiAP;
|
||||
}
|
||||
if (connection == "ethernet")
|
||||
{
|
||||
return Ethernet;
|
||||
return static_cast<Connection>(connection);
|
||||
}
|
||||
|
||||
throw ::std::invalid_argument("Invalid connection value");
|
||||
throw ::std::invalid_argument("Invalid connection value: " + connection);
|
||||
}
|
||||
|
||||
Direction parseDirection(uint8_t direction)
|
||||
{
|
||||
if (direction == 0)
|
||||
if (direction > 0 || direction < DIRECTION_SIZE)
|
||||
{
|
||||
return Output;
|
||||
}
|
||||
if (direction == 1)
|
||||
{
|
||||
return Input;
|
||||
return static_cast<Direction>(direction);
|
||||
}
|
||||
|
||||
throw ::std::invalid_argument("Invalid direction value: " + direction);
|
||||
|
@ -88,8 +71,10 @@ Direction parseDirection(uint8_t direction)
|
|||
#pragma endregion
|
||||
|
||||
void onGetConfig(
|
||||
Connection connection,
|
||||
String ssid,
|
||||
String pwd,
|
||||
IpMethod ipMethod,
|
||||
uint32_t ip,
|
||||
uint32_t subnet,
|
||||
uint32_t gateway,
|
||||
|
@ -110,8 +95,10 @@ void onGetConfig(
|
|||
ipAddr = gateway;
|
||||
String gatewayString = ipAddr.toString();
|
||||
|
||||
doc["connection"] = connection;
|
||||
doc["ssid"] = ssid;
|
||||
doc["password"] = pwd;
|
||||
doc["ip-method"] = ipMethod;
|
||||
doc["ip"] = ipString;
|
||||
doc["subnet"] = subnetString;
|
||||
doc["gateway"] = gatewayString;
|
||||
|
@ -135,7 +122,7 @@ void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size
|
|||
|
||||
try
|
||||
{
|
||||
IpMethod ipMethod = parseIpMethod(doc["ip-method"].as<String>());
|
||||
IpMethod ipMethod = parseIpMethod(doc["ip-method"].as<uint8_t>());
|
||||
config.putUInt("ip-method", ipMethod);
|
||||
|
||||
if (ipMethod == Static)
|
||||
|
@ -153,8 +140,9 @@ void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size
|
|||
config.putUInt("gateway", gateway);
|
||||
}
|
||||
|
||||
Connection connection = parseConnection(doc["connection"].as<String>());
|
||||
Connection connection = parseConnection(doc["connection"].as<uint8_t>());
|
||||
config.putUInt("connection", connection);
|
||||
|
||||
if (connection == WiFiSta || connection == WiFiAP)
|
||||
{
|
||||
config.putString("ssid", doc["ssid"].as<String>());
|
||||
|
|
|
@ -14,6 +14,7 @@ enum IpMethod
|
|||
Static,
|
||||
DHCP
|
||||
};
|
||||
const uint8_t IP_METHOD_SIZE = 2;
|
||||
|
||||
enum Connection
|
||||
{
|
||||
|
@ -21,16 +22,20 @@ enum Connection
|
|||
WiFiAP,
|
||||
Ethernet
|
||||
};
|
||||
const uint8_t CONNECTION_SIZE = 3;
|
||||
|
||||
enum Direction
|
||||
{
|
||||
Input,
|
||||
Output
|
||||
Output,
|
||||
Input
|
||||
};
|
||||
const uint8_t DIRECTION_SIZE = 2;
|
||||
|
||||
void onGetConfig(
|
||||
Connection connection,
|
||||
String ssid,
|
||||
String pwd,
|
||||
IpMethod ipMethod,
|
||||
uint32_t ip,
|
||||
uint32_t subnet,
|
||||
uint32_t gateway,
|
||||
|
|
Loading…
Add table
Reference in a new issue