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,
|
"always_on": true,
|
||||||
"timeout":10,
|
"timeout":10,
|
||||||
"overwrite_pin":0
|
"overwrite_pin":0
|
||||||
|
},
|
||||||
|
"ftp":
|
||||||
|
{
|
||||||
|
"active":false,
|
||||||
|
"user": [
|
||||||
|
{ "name":"ftp", "password":"ftp" }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -139,11 +139,13 @@ void loop()
|
||||||
beacon_digi = true;
|
beacon_digi = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Config.ftp.active)
|
||||||
|
{
|
||||||
ftpServer.handle();
|
ftpServer.handle();
|
||||||
static bool configWasOpen = false;
|
static bool configWasOpen = false;
|
||||||
if(configWasOpen && ftpServer.countConnections() == 0)
|
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();
|
Serial.println();
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
@ -151,6 +153,7 @@ void loop()
|
||||||
{
|
{
|
||||||
configWasOpen = true;
|
configWasOpen = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(Config.wifi.active) ArduinoOTA.handle();
|
if(Config.wifi.active) ArduinoOTA.handle();
|
||||||
if(Config.wifi.active && WiFiMulti.run() != WL_CONNECTED)
|
if(Config.wifi.active && WiFiMulti.run() != WL_CONNECTED)
|
||||||
|
|
@ -445,9 +448,16 @@ void setup_timer()
|
||||||
|
|
||||||
void setup_ftp()
|
void setup_ftp()
|
||||||
{
|
{
|
||||||
#define FTP_USER "ftp"
|
if(!Config.ftp.active)
|
||||||
#define FTP_PASSWORD "ftp"
|
{
|
||||||
ftpServer.addUser(FTP_USER, FTP_PASSWORD);
|
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.addFilesystem("SPIFFS", &SPIFFS);
|
||||||
ftpServer.begin();
|
ftpServer.begin();
|
||||||
Serial.println("[INFO] FTP Server init done!");
|
Serial.println("[INFO] FTP Server init done!");
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,10 @@ Configuration ConfigurationManagement::readConfiguration()
|
||||||
Serial.println("Failed to open file for reading...");
|
Serial.println("Failed to open file for reading...");
|
||||||
return Configuration();
|
return Configuration();
|
||||||
}
|
}
|
||||||
DynamicJsonDocument data(1024);
|
DynamicJsonDocument data(2048);
|
||||||
deserializeJson(data, file);
|
deserializeJson(data, file);
|
||||||
|
//serializeJson(data, Serial);
|
||||||
|
//Serial.println();
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
Configuration conf;
|
Configuration conf;
|
||||||
|
|
@ -75,6 +77,18 @@ Configuration ConfigurationManagement::readConfiguration()
|
||||||
conf.lora.signalBandwidth = data["lora"]["signal_bandwidth"];
|
conf.lora.signalBandwidth = data["lora"]["signal_bandwidth"];
|
||||||
conf.lora.codingRate4 = data["lora"]["coding_rate4"];
|
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:
|
// update config in memory to get the new fields:
|
||||||
writeConfiguration(conf);
|
writeConfiguration(conf);
|
||||||
|
|
@ -90,7 +104,7 @@ void ConfigurationManagement::writeConfiguration(Configuration conf)
|
||||||
Serial.println("Failed to open file for writing...");
|
Serial.println("Failed to open file for writing...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DynamicJsonDocument data(1024);
|
DynamicJsonDocument data(2048);
|
||||||
|
|
||||||
data["version"] = conf.version;
|
data["version"] = conf.version;
|
||||||
data["callsign"] = conf.callsign;
|
data["callsign"] = conf.callsign;
|
||||||
|
|
@ -124,6 +138,14 @@ void ConfigurationManagement::writeConfiguration(Configuration conf)
|
||||||
data["display"]["always_on"] = conf.display.alwaysOn;
|
data["display"]["always_on"] = conf.display.alwaysOn;
|
||||||
data["display"]["timeout"] = conf.display.timeout;
|
data["display"]["timeout"] = conf.display.timeout;
|
||||||
data["display"]["overwrite_pin"] = conf.display.overwritePin;
|
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, file);
|
||||||
//serializeJson(data, Serial);
|
//serializeJson(data, Serial);
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,23 @@ public:
|
||||||
int overwritePin;
|
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;
|
int version;
|
||||||
String callsign;
|
String callsign;
|
||||||
|
|
@ -92,6 +108,7 @@ public:
|
||||||
Digi digi;
|
Digi digi;
|
||||||
LoRa lora;
|
LoRa lora;
|
||||||
Display display;
|
Display display;
|
||||||
|
Ftp ftp;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConfigurationManagement
|
class ConfigurationManagement
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue