Upload files to "/"

This commit is contained in:
dangrain 2025-06-25 10:16:23 +02:00
parent b059500a70
commit 818e4d1c60

View file

@ -1,5 +1,14 @@
#include <WiFi.h> #include <WiFi.h>
// WiFi configuration
char ssid[] = "SSID"; // your network SSID (name)
char pass[] = "PASSWORD"; // your network password
//int status = WL_IDLE_STATUS;
WiFiUDP udp;
WiFiServer server(80);
struct File { struct File {
String name; String name;
String content; String content;
@ -11,7 +20,7 @@ File files[MAX_FILES];
void clearScreen() { void clearScreen() {
for (int i = 0; i < 50; i++) { for (int i = 0; i < 50; i++) {
Serial.println(); //function that clears your screen (again this is stupid) Serial.println(); //function that clears your scree n (again this is stupid)
} }
} }
@ -73,6 +82,7 @@ void showHelp() { //I think this is fairly self explanatory, but still, making s
Serial.println(" loop <number> <command> - Loops a command the inputted amout of times"); Serial.println(" loop <number> <command> - Loops a command the inputted amout of times");
Serial.println(" high <pin-number> - sets the inputted pin to high");// 12 Serial.println(" high <pin-number> - sets the inputted pin to high");// 12
Serial.println(" low <pin-number> - sets the inputted pin to low"); //13 Serial.println(" low <pin-number> - sets the inputted pin to low"); //13
Serial.println(" send <message> - Send a message using UART and pin 2");
} }
void calculate(String input) { void calculate(String input) {
@ -178,31 +188,40 @@ void loopCommand(String input) {
} }
} }
void setPinLow(String input) {
int pin = input.toInt();
if (pin >= 0) { void checkConnections(){ //tells what network the device Is connected to and prints the local IP of It
pinMode(pin, OUTPUT); Serial.print("Connected to...");
digitalWrite(pin, LOW); Serial.println(ssid);
Serial.println("Pin " + String(pin) + " set to LOW"); Serial.println("Address Is");
} else { Serial.println(WiFi.localIP());
Serial.println("Invalid pin number");
}
} }
void setPinHigh(String input) { void sendUDP(String hostIp, String hostPort, String message){ //sends UDP message
int pin = input.toInt(); int port = hostPort.toInt();
if (pin >= 0){ IPAddress ip;
pinMode(pin, OUTPUT);
digitalWrite(pin, HIGH);
Serial.println("Pin " + String(pin) + " set to HIGH");
} else { if (port <= 0) {
Serial.println("Invalid pin number"); Serial.println("Invalid port");
return;
} }
} if (!ip.fromString(hostIp)) {
Serial.println("Invalid IP address");
return;
}
else{
udp.beginPacket(ip, port);
udp.write((const uint8_t*)message.c_str(), message.length());
udp.endPacket();
Serial.println("Sent message to " + hostIp + " on port: " + port);
}
if (WiFi.status() != WL_CONNECTED) return;
}
void processCommand(String input) { void processCommand(String input) {
input.trim(); input.trim();
@ -257,27 +276,50 @@ void processCommand(String input) {
loopCommand(input.substring(5)); loopCommand(input.substring(5));
} }
else if (input.startsWith("high ")) { else if (input.startsWith("high ")) {
setPinHigh(input.substring(5)); //setPinHigh(input.substring(5));
} }
else if (input.startsWith("low ")){ else if (input.startsWith("low ")){
setPinLow(input.substring(4)); //setPinLow(input.substring(4));
} }
else if (input.startsWith("send ")){ // sends UART messages (pin 1) exclusive else if (input.startsWith("send ")){ // sends UART messages (pin 2) exclusive
String message = input.substring(5); String message = input.substring(5);
message.trim(); message.trim();
Serial1.println(message); Serial1.println(message);
Serial.println("Sent '" + message + "'"); Serial.println("Sent '" + message + "'");
} }
else if (input == "connt"){
checkConnections();
Serial.println(esp_reset_reason());
}
else if (input.startsWith("udp ")) {
int firstSpace = input.indexOf(' ', 4);
int secondSpace = input.indexOf(' ', firstSpace + 1);
if (firstSpace == -1 || secondSpace == -1) return;
String ip = input.substring(4, firstSpace);
String port = input.substring(firstSpace + 1, secondSpace);
String message = input.substring(secondSpace + 1);
if (message.length() > 512) return;
sendUDP(ip, port, message);
}
else { else {
Serial.println("Unknown command " + input); //changed this because I realized It makes more sense Serial.println("Unknown command " + input); //changed this because I realized It makes more sense
} }
} }
void setup() { void setup() {
Serial.begin(9600); Serial.begin(115200);
delay(500); delay(500);
Serial.println("Welcome to GrainOS 1.8.3, `help` for a list of commands"); Serial.println("Welcome to GrainOS ESP32 1.1.0, `help` for a list of commands");
Serial1.begin(9600, SERIAL_8N1, -1, 1); Serial1.begin(9600, SERIAL_8N1, -1, 2);
WiFi.begin(ssid, pass);
server.begin();
udp.begin(12345);
} }
void loop() { //the script runner :) void loop() { //the script runner :)