mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-05-19 10:32:56 +00:00
added subnet and gateway input
This commit is contained in:
parent
d3e405c35c
commit
f07cf0db61
4 changed files with 65 additions and 14 deletions
|
@ -28,12 +28,30 @@
|
|||
</label>
|
||||
<div data-field="input-ip-method" data-values="static">
|
||||
<label>
|
||||
IP-Adresse/CIDR:
|
||||
IP-Adresse:
|
||||
<input
|
||||
type="text"
|
||||
name="ip"
|
||||
id="input-ip"
|
||||
placeholder="IP-Adresse/CIDR"
|
||||
placeholder="IP-Adresse"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Subnetzmaske:
|
||||
<input
|
||||
type="text"
|
||||
name="subnet"
|
||||
id="input-subnet"
|
||||
placeholder="Subnetzmaske"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Gateway:
|
||||
<input
|
||||
type="text"
|
||||
name="gateway"
|
||||
id="input-gateway"
|
||||
placeholder="Gateway"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
|
14
src/main.cpp
14
src/main.cpp
|
@ -29,12 +29,10 @@ void setup()
|
|||
String pwd = config.getString("password", "mbgmbgmbg");
|
||||
IPAddress defaultIp(192, 168, 1, 201);
|
||||
IPAddress ip = config.getUInt("ip", defaultIp);
|
||||
|
||||
IPAddress cidr = config.getUChar("cidr", 24);
|
||||
|
||||
// TODO: \/ Herleiten \/ @psxde
|
||||
const IPAddress gateway(192, 168, 1, 1);
|
||||
const IPAddress subnet(255, 255, 255, 0);
|
||||
IPAddress defaultSubnet(255, 255, 255, 0);
|
||||
IPAddress subnet = config.getUInt("subnet", defaultSubnet);
|
||||
IPAddress defaultGateway(192, 168, 1, 1);
|
||||
IPAddress gateway = config.getUInt("gateway", defaultGateway);
|
||||
|
||||
// WiFi stuff
|
||||
// WiFi.begin(ssid, pwd);
|
||||
|
@ -75,8 +73,8 @@ void setup()
|
|||
|
||||
server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html");
|
||||
|
||||
server.on("/config", HTTP_GET, [&, defaultIp, ssid, pwd, direction1, universe1, direction2, universe2](AsyncWebServerRequest *request)
|
||||
{ onGetConfig(ssid, pwd, defaultIp, universe1, direction1, universe2, direction2, request); });
|
||||
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.onRequestBody([](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total)
|
||||
{
|
||||
|
|
|
@ -87,16 +87,34 @@ Direction parseDirection(uint8_t direction)
|
|||
|
||||
#pragma endregion
|
||||
|
||||
void onGetConfig(String ssid, String pwd, uint32_t ip, uint8_t universe1, Direction direction1, uint8_t universe2, Direction direction2, AsyncWebServerRequest *request)
|
||||
void onGetConfig(
|
||||
String ssid,
|
||||
String pwd,
|
||||
uint32_t ip,
|
||||
uint32_t subnet,
|
||||
uint32_t gateway,
|
||||
uint8_t universe1,
|
||||
Direction direction1,
|
||||
uint8_t universe2,
|
||||
Direction direction2,
|
||||
AsyncWebServerRequest *request)
|
||||
{
|
||||
JsonDocument doc;
|
||||
|
||||
IPAddress ipAddr = ip;
|
||||
String ipString = ipAddr.toString();
|
||||
|
||||
ipAddr = subnet;
|
||||
String subnetString = ipAddr.toString();
|
||||
|
||||
ipAddr = gateway;
|
||||
String gatewayString = ipAddr.toString();
|
||||
|
||||
doc["ssid"] = ssid;
|
||||
doc["password"] = pwd;
|
||||
doc["ip"] = ipString;
|
||||
doc["subnet"] = subnetString;
|
||||
doc["gateway"] = gatewayString;
|
||||
doc["universe-1"] = universe1;
|
||||
doc["direction-1"] = direction1;
|
||||
doc["universe-2"] = universe2;
|
||||
|
@ -122,10 +140,17 @@ void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size
|
|||
|
||||
if (ipMethod == Static)
|
||||
{
|
||||
String ipString = doc["ip"].as<String>();
|
||||
IPAddress ipAddress;
|
||||
ipAddress.fromString(ipString);
|
||||
ipAddress.fromString(doc["ip"].as<String>());
|
||||
config.putUInt("ip", ipAddress);
|
||||
|
||||
IPAddress subnet;
|
||||
subnet.fromString(doc["subnet"].as<String>());
|
||||
config.putUInt("subnet", subnet);
|
||||
|
||||
IPAddress gateway;
|
||||
gateway.fromString(doc["gateway"].as<String>());
|
||||
config.putUInt("gateway", gateway);
|
||||
}
|
||||
|
||||
Connection connection = parseConnection(doc["connection"].as<String>());
|
||||
|
|
|
@ -28,7 +28,17 @@ enum Direction
|
|||
Output
|
||||
};
|
||||
|
||||
void onGetConfig(String ssid, String pwd, uint32_t ip, uint8_t universe1, Direction direction1, uint8_t universe2, Direction direction2, AsyncWebServerRequest *request);
|
||||
void onGetConfig(
|
||||
String ssid,
|
||||
String pwd,
|
||||
uint32_t ip,
|
||||
uint32_t subnet,
|
||||
uint32_t gateway,
|
||||
uint8_t universe1,
|
||||
Direction direction1,
|
||||
uint8_t universe2,
|
||||
Direction direction2,
|
||||
AsyncWebServerRequest *request);
|
||||
|
||||
void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue