kopia lustrzana https://github.com/lora-aprs/LoRa_APRS_iGate
commit
21da478f2c
|
@ -47,5 +47,12 @@
|
|||
"always_on": true,
|
||||
"timeout":10,
|
||||
"overwrite_pin":0
|
||||
},
|
||||
"ftp":
|
||||
{
|
||||
"active":false,
|
||||
"user": [
|
||||
{ "name":"ftp", "password":"ftp" }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ lib_deps =
|
|||
sandeepmistry/LoRa @ 0.7.2
|
||||
peterus/APRS-Decoder-Lib @ 0.0.5
|
||||
peterus/APRS-IS-Lib @ 0.0.7
|
||||
https://github.com/peterus/ESP-FTP-Server-Lib @ 0.9.3
|
||||
peterus/LoRa-APRS-Lib @ 0.0.5
|
||||
check_tool = cppcheck
|
||||
check_flags =
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
#include <WiFiUdp.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <APRS-IS.h>
|
||||
#include <SPIFFS.h>
|
||||
#include <ESP-FTP-Server-Lib.h>
|
||||
#include <FTPFilesystem.h>
|
||||
|
||||
#include "LoRa_APRS.h"
|
||||
|
||||
|
@ -28,6 +31,7 @@ volatile uint secondsSinceDisplay = 0;
|
|||
WiFiMulti WiFiMulti;
|
||||
WiFiUDP ntpUDP;
|
||||
NTPClient timeClient(ntpUDP, 60*60);
|
||||
FTPServer ftpServer;
|
||||
Configuration Config;
|
||||
APRS_IS * aprs_is = 0;
|
||||
LoRa_APRS lora_aprs;
|
||||
|
@ -43,6 +47,7 @@ void setup_lora();
|
|||
void setup_ntp();
|
||||
void setup_aprs_is();
|
||||
void setup_timer();
|
||||
void setup_ftp();
|
||||
|
||||
std::map<uint, std::shared_ptr<APRSMessage>> lastMessages;
|
||||
|
||||
|
@ -77,6 +82,7 @@ void setup()
|
|||
setup_wifi();
|
||||
setup_ota();
|
||||
setup_ntp();
|
||||
setup_ftp();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -133,6 +139,22 @@ void loop()
|
|||
beacon_digi = true;
|
||||
}
|
||||
|
||||
if(Config.ftp.active)
|
||||
{
|
||||
ftpServer.handle();
|
||||
static bool configWasOpen = false;
|
||||
if(configWasOpen && ftpServer.countConnections() == 0)
|
||||
{
|
||||
Serial.println("[WARN] Maybe the config has been changed via FTP, lets restart now to get the new config...");
|
||||
Serial.println();
|
||||
ESP.restart();
|
||||
}
|
||||
if(ftpServer.countConnections() > 0)
|
||||
{
|
||||
configWasOpen = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(Config.wifi.active) ArduinoOTA.handle();
|
||||
if(Config.wifi.active && WiFiMulti.run() != WL_CONNECTED)
|
||||
{
|
||||
|
@ -424,6 +446,23 @@ void setup_timer()
|
|||
timerAlarmEnable(timer);
|
||||
}
|
||||
|
||||
void setup_ftp()
|
||||
{
|
||||
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!");
|
||||
}
|
||||
|
||||
String create_lat_aprs(double lat)
|
||||
{
|
||||
char str[20];
|
||||
|
|
|
@ -31,19 +31,21 @@ 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;
|
||||
conf.callsign = data["callsign"].as<String>();
|
||||
conf.wifi.active = data["wifi"]["active"];
|
||||
JsonArray aps = data["wifi"]["AP"].as<JsonArray>();
|
||||
JsonArray aps = data["wifi"]["AP"].as<JsonArray>();
|
||||
for(JsonVariant v : aps)
|
||||
{
|
||||
Configuration::Wifi::AP ap;
|
||||
ap.SSID = v["SSID"].as<String>();
|
||||
ap.password = v["password"].as<String>();
|
||||
ap.SSID = v["SSID"].as<String>();
|
||||
ap.password = v["password"].as<String>();
|
||||
conf.wifi.APs.push_back(ap);
|
||||
}
|
||||
conf.beacon.message = data["beacon"]["message"].as<String>();
|
||||
|
@ -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
|
||||
|
|
Ładowanie…
Reference in New Issue