Skip to content

Commit 4c71192

Browse files
committed
* add parameter for static IP config
1 parent fab7f0a commit 4c71192

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

src/project_configuration.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,31 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen
88
if (data.containsKey("callsign"))
99
conf.callsign = data["callsign"].as<String>();
1010

11+
if (data.containsKey("eth") && data["eth"].containsKey("DHCP")) {
12+
conf.eth.DHCP = data["eth"]["DHCP"];
13+
conf.eth.IP = data["eth"]["IP"].as<String>();
14+
conf.eth.Netmask = data["eth"]["Netmask"].as<String>();
15+
conf.eth.Gateway = data["eth"]["Gateway"].as<String>();
16+
conf.eth.DNS1 = data["eth"]["DNS1"].as<String>();
17+
conf.eth.DNS2 = data["eth"]["DNS2"].as<String>();
18+
}
19+
1120
JsonArray aps = data["wifi"]["AP"].as<JsonArray>();
1221
for (JsonVariant v : aps) {
1322
Configuration::Wifi::AP ap;
1423
ap.SSID = v["SSID"].as<String>();
1524
ap.password = v["password"].as<String>();
25+
if (v.containsKey("DHCP")) {
26+
ap.DHCP = v["DHCP"];
27+
ap.IP = v["IP"].as<String>();
28+
ap.Netmask = v["Netmask"].as<String>();
29+
ap.Gateway = v["Gateway"].as<String>();
30+
ap.DNS1 = v["DNS1"].as<String>();
31+
ap.DNS2 = v["DNS2"].as<String>();
32+
}
1633
conf.wifi.APs.push_back(ap);
1734
}
35+
1836
if (data.containsKey("beacon") && data["beacon"].containsKey("message"))
1937
conf.beacon.message = data["beacon"]["message"].as<String>();
2038
conf.beacon.positionLatitude = data["beacon"]["position"]["latitude"] | 0.0;
@@ -63,12 +81,31 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen
6381

6482
void ProjectConfigurationManagement::writeProjectConfiguration(Configuration &conf, DynamicJsonDocument &data) {
6583
data["callsign"] = conf.callsign;
66-
JsonArray aps = data["wifi"].createNestedArray("AP");
84+
85+
if (conf.eth.DHCP == false) {
86+
data["eth"]["DHCP"] = conf.eth.DHCP;
87+
data["eth"]["IP"] = conf.eth.IP;
88+
data["eth"]["Netmask"] = conf.eth.Netmask;
89+
data["eth"]["Gateway"] = conf.eth.Gateway;
90+
data["eth"]["DNS1"] = conf.eth.DNS1;
91+
data["eth"]["DNS2"] = conf.eth.DNS2;
92+
}
93+
94+
JsonArray aps = data["wifi"].createNestedArray("AP");
6795
for (Configuration::Wifi::AP ap : conf.wifi.APs) {
6896
JsonObject v = aps.createNestedObject();
6997
v["SSID"] = ap.SSID;
7098
v["password"] = ap.password;
99+
if (ap.DHCP == false) {
100+
v["DHCP"] = ap.DHCP;
101+
v["IP"] = ap.IP;
102+
v["Netmask"] = ap.Netmask;
103+
v["Gateway"] = ap.Gateway;
104+
v["DNS1"] = ap.DNS1;
105+
v["DNS2"] = ap.DNS2;
106+
}
71107
}
108+
72109
data["beacon"]["message"] = conf.beacon.message;
73110
data["beacon"]["position"]["latitude"] = conf.beacon.positionLatitude;
74111
data["beacon"]["position"]["longitude"] = conf.beacon.positionLongitude;

src/project_configuration.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,34 @@
66

77
class Configuration {
88
public:
9+
class ETH {
10+
public:
11+
ETH() : DHCP(true) {
12+
}
13+
14+
bool DHCP;
15+
String IP;
16+
String Netmask;
17+
String Gateway;
18+
String DNS1;
19+
String DNS2;
20+
};
21+
922
class Wifi {
1023
public:
1124
class AP {
1225
public:
26+
AP() : DHCP(true) {
27+
}
28+
1329
String SSID;
1430
String password;
31+
bool DHCP;
32+
String IP;
33+
String Netmask;
34+
String Gateway;
35+
String DNS1;
36+
String DNS2;
1537
};
1638

1739
Wifi() {
@@ -93,6 +115,7 @@ class Configuration {
93115
Configuration() : callsign("NOCALL-10"), board(""), ntpServer("pool.ntp.org"){};
94116

95117
String callsign;
118+
ETH eth;
96119
Wifi wifi;
97120
Beacon beacon;
98121
APRS_IS aprs_is;

0 commit comments

Comments
 (0)