kopia lustrzana https://github.com/dl9rdz/rdz_ttgo_sonde
+ config upload/download tool
rodzic
c41808ec18
commit
a86c10ccbf
|
@ -821,6 +821,26 @@ const char *handleControlPost(AsyncWebServerRequest *request) {
|
|||
return "";
|
||||
}
|
||||
|
||||
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
|
||||
static File file;
|
||||
if (!index) {
|
||||
Serial.printf("UploadStart: %s\n", filename.c_str());
|
||||
file = SPIFFS.open("/" + filename, "w");
|
||||
if (!file) {
|
||||
Serial.println("There was an error opening the file '/config.txt' for reading");
|
||||
}
|
||||
}
|
||||
if (!file) return;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
file.write(data[i]);
|
||||
}
|
||||
if (final) {
|
||||
Serial.printf("UploadEnd: %s, %u B\n", filename.c_str(), index + len);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int streamEditForm(int &state, File &file, String filename, char *buffer, size_t maxlen, size_t index) {
|
||||
Serial.printf("streamEdit: state=%d max:%d idx:%d\n", state, maxlen, index);
|
||||
int i = 0;
|
||||
|
@ -1126,6 +1146,19 @@ void SetupAsyncServer() {
|
|||
request->send(200, "text/html", createControlForm());
|
||||
});
|
||||
|
||||
server.on("/file", HTTP_GET, [](AsyncWebServerRequest * request) {
|
||||
String url = request->url();
|
||||
const char *filename = url.c_str() + 5;
|
||||
if (*filename == 0) {
|
||||
request->send(400, "error");
|
||||
return;
|
||||
}
|
||||
request->send(SPIFFS, filename, "text/plain");
|
||||
});
|
||||
server.on("/file", HTTP_POST, [](AsyncWebServerRequest * request) {
|
||||
request->send(200);
|
||||
}, handleUpload);
|
||||
|
||||
server.on("/edit.html", HTTP_GET, [](AsyncWebServerRequest * request) {
|
||||
// new version:
|
||||
// Open file
|
||||
|
@ -2950,8 +2983,10 @@ void sondehub_station_update(WiFiClient *client, struct st_sondehub *conf) {
|
|||
client->println(data);
|
||||
Serial.println(strlen(data));
|
||||
Serial.println(data);
|
||||
Serial.println("Waiting for response");
|
||||
String response = client->readString();
|
||||
Serial.println(response);
|
||||
Serial.println("Response done...");
|
||||
client->stop();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const char *version_name = "rdzTTGOsonde";
|
||||
const char *version_id = "devel20210524a";
|
||||
const char *version_id = "devel20210526";
|
||||
const int SPIFFS_MAJOR=2;
|
||||
const int SPIFFS_MINOR=11;
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
#!/usr/bin/python3
|
||||
import requests
|
||||
import sys
|
||||
import os
|
||||
|
||||
url = "http://192.168.42.69/";
|
||||
screens = ("screens1.txt", "screens2.txt", "screens3.txt")
|
||||
allfiles = ("config.txt", "qrg.txt", "networks.txt") + screens
|
||||
|
||||
optprint = False
|
||||
optdir = ""
|
||||
|
||||
def getfile(name):
|
||||
urlg = url+"file/"+name;
|
||||
print("Downloading: ",urlg);
|
||||
data = requests.get(urlg);
|
||||
if optprint:
|
||||
print(data.text)
|
||||
elif len(data.content)>0:
|
||||
f = open(optdir+name, "wb");
|
||||
f.write(data.content);
|
||||
f.close();
|
||||
else:
|
||||
print("Error: empty response")
|
||||
|
||||
def putfile(name):
|
||||
print("Uploading: ",optdir+name)
|
||||
files = { 'data': (name, open(optdir+name, "rb")), }
|
||||
response = requests.post(url+"file", files=files)
|
||||
|
||||
if len(sys.argv)>=2:
|
||||
if sys.argv[1]=="--print":
|
||||
del(sys.argv[1])
|
||||
optprint = True
|
||||
print("Printing file content on screen\n")
|
||||
if sys.argv[1].startswith("--dir="):
|
||||
optdir = sys.argv[1][6:]+"/"
|
||||
print("Using file directory ",optdir)
|
||||
os.makedirs(optdir, exist_ok=True)
|
||||
del(sys.argv[1])
|
||||
|
||||
if len(sys.argv)<=2:
|
||||
print("Usage: ",sys.argv[0]," [--print|--dir={dir}] <get|put> <all|config|qrg|networks|screens>");
|
||||
print("or: ",sys.argv[0]," <get|put> file {filename}");
|
||||
print("\n",
|
||||
" screens is screens1.txt, screens2.txt, screens3.txt");
|
||||
print(" networks is networks.txt (Wifi ssid and password)")
|
||||
print(" qrg is qrg.txt (List with scan frequencies)")
|
||||
print(" all is screens + network + qrg")
|
||||
sys.exit(1)
|
||||
|
||||
files=()
|
||||
|
||||
if sys.argv[2]=="file":
|
||||
if len(sys.argv)<=3:
|
||||
print("get/put file: missing filename\n");
|
||||
sys.exit(1);
|
||||
files=(sys.argv[3],)
|
||||
elif sys.argv[2]=="config":
|
||||
files=("config.txt",)
|
||||
elif sys.argv[2]=="qrg":
|
||||
files=("qrg.txt",)
|
||||
elif sys.argv[2]=="networks":
|
||||
files=("networks.txt",)
|
||||
elif sys.argv[2]=="screens":
|
||||
files=screens
|
||||
elif sys.argv[2]=="all":
|
||||
files=allfiles
|
||||
else:
|
||||
print("Invalid file specification: ",sys.argv[2])
|
||||
sys.exit(1)
|
||||
|
||||
if(sys.argv[1]=="get"):
|
||||
for f in files:
|
||||
getfile(f)
|
||||
elif(sys.argv[1]=="put"):
|
||||
for f in files:
|
||||
putfile(f)
|
||||
else:
|
||||
print("Invalid command ",sys.argv[1])
|
||||
|
Ładowanie…
Reference in New Issue