mirror of
https://github.com/lora-aprs/LoRa_APRS_iGate.git
synced 2025-12-06 07:42:00 +01:00
add ftp config
This commit is contained in:
parent
bc56f8af4a
commit
b4be3c5d6a
|
|
@ -47,5 +47,12 @@
|
|||
"always_on": true,
|
||||
"timeout":10,
|
||||
"overwrite_pin":0
|
||||
},
|
||||
"ftp":
|
||||
{
|
||||
"active":false,
|
||||
"user": [
|
||||
{ "name":"ftp", "password":"ftp" }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,11 +139,13 @@ void loop()
|
|||
beacon_digi = true;
|
||||
}
|
||||
|
||||
if(Config.ftp.active)
|
||||
{
|
||||
ftpServer.handle();
|
||||
static bool configWasOpen = false;
|
||||
if(configWasOpen && ftpServer.countConnections() == 0)
|
||||
{
|
||||
Serial.println("[WARN] Configuration maybe changed via FTP, will restart now...");
|
||||
Serial.println("[WARN] Maybe the config has been changed via FTP, lets restart now to get the new config...");
|
||||
Serial.println();
|
||||
ESP.restart();
|
||||
}
|
||||
|
|
@ -151,6 +153,7 @@ void loop()
|
|||
{
|
||||
configWasOpen = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(Config.wifi.active) ArduinoOTA.handle();
|
||||
if(Config.wifi.active && WiFiMulti.run() != WL_CONNECTED)
|
||||
|
|
@ -445,9 +448,16 @@ void setup_timer()
|
|||
|
||||
void setup_ftp()
|
||||
{
|
||||
#define FTP_USER "ftp"
|
||||
#define FTP_PASSWORD "ftp"
|
||||
ftpServer.addUser(FTP_USER, FTP_PASSWORD);
|
||||
if(!Config.ftp.active)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for(Configuration::Ftp::User user : Config.ftp.users)
|
||||
{
|
||||
Serial.print("[INFO] Adding user to FTP Server: ");
|
||||
Serial.println(user.name);
|
||||
ftpServer.addUser(user.name, user.password);
|
||||
}
|
||||
ftpServer.addFilesystem("SPIFFS", &SPIFFS);
|
||||
ftpServer.begin();
|
||||
Serial.println("[INFO] FTP Server init done!");
|
||||
|
|
|
|||
|
|
@ -31,8 +31,10 @@ Configuration ConfigurationManagement::readConfiguration()
|
|||
Serial.println("Failed to open file for reading...");
|
||||
return Configuration();
|
||||
}
|
||||
DynamicJsonDocument data(1024);
|
||||
DynamicJsonDocument data(2048);
|
||||
deserializeJson(data, file);
|
||||
//serializeJson(data, Serial);
|
||||
//Serial.println();
|
||||
file.close();
|
||||
|
||||
Configuration conf;
|
||||
|
|
@ -75,6 +77,18 @@ Configuration ConfigurationManagement::readConfiguration()
|
|||
conf.lora.signalBandwidth = data["lora"]["signal_bandwidth"];
|
||||
conf.lora.codingRate4 = data["lora"]["coding_rate4"];
|
||||
}
|
||||
if(data["version"] >= 4)
|
||||
{
|
||||
conf.ftp.active = data["ftp"]["active"];
|
||||
JsonArray users = data["ftp"]["user"].as<JsonArray>();
|
||||
for(JsonVariant u : users)
|
||||
{
|
||||
Configuration::Ftp::User us;
|
||||
us.name = u["name"].as<String>();
|
||||
us.password = u["password"].as<String>();
|
||||
conf.ftp.users.push_back(us);
|
||||
}
|
||||
}
|
||||
|
||||
// update config in memory to get the new fields:
|
||||
writeConfiguration(conf);
|
||||
|
|
@ -90,7 +104,7 @@ void ConfigurationManagement::writeConfiguration(Configuration conf)
|
|||
Serial.println("Failed to open file for writing...");
|
||||
return;
|
||||
}
|
||||
DynamicJsonDocument data(1024);
|
||||
DynamicJsonDocument data(2048);
|
||||
|
||||
data["version"] = conf.version;
|
||||
data["callsign"] = conf.callsign;
|
||||
|
|
@ -124,6 +138,14 @@ void ConfigurationManagement::writeConfiguration(Configuration conf)
|
|||
data["display"]["always_on"] = conf.display.alwaysOn;
|
||||
data["display"]["timeout"] = conf.display.timeout;
|
||||
data["display"]["overwrite_pin"] = conf.display.overwritePin;
|
||||
data["ftp"]["active"] = conf.ftp.active;
|
||||
JsonArray users = data["ftp"].createNestedArray("user");
|
||||
for(Configuration::Ftp::User u : conf.ftp.users)
|
||||
{
|
||||
JsonObject v = users.createNestedObject();
|
||||
v["name"] = u.name;
|
||||
v["password"] = u.password;
|
||||
}
|
||||
|
||||
serializeJson(data, file);
|
||||
//serializeJson(data, Serial);
|
||||
|
|
|
|||
|
|
@ -82,7 +82,23 @@ public:
|
|||
int overwritePin;
|
||||
};
|
||||
|
||||
Configuration() : version(3), callsign("NOCALL-10") {};
|
||||
class Ftp
|
||||
{
|
||||
public:
|
||||
class User
|
||||
{
|
||||
public:
|
||||
String name;
|
||||
String password;
|
||||
};
|
||||
|
||||
Ftp() : active(false) {}
|
||||
|
||||
bool active;
|
||||
std::list<User> users;
|
||||
};
|
||||
|
||||
Configuration() : version(4), callsign("NOCALL-10") {};
|
||||
|
||||
int version;
|
||||
String callsign;
|
||||
|
|
@ -92,6 +108,7 @@ public:
|
|||
Digi digi;
|
||||
LoRa lora;
|
||||
Display display;
|
||||
Ftp ftp;
|
||||
};
|
||||
|
||||
class ConfigurationManagement
|
||||
|
|
|
|||
Loading…
Reference in a new issue