Upload files to "/"
This commit is contained in:
parent
b059500a70
commit
818e4d1c60
1 changed files with 67 additions and 25 deletions
92
GrainOS.ino
92
GrainOS.ino
|
@ -1,5 +1,14 @@
|
|||
#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 {
|
||||
String name;
|
||||
String content;
|
||||
|
@ -11,7 +20,7 @@ File files[MAX_FILES];
|
|||
|
||||
void clearScreen() {
|
||||
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(" high <pin-number> - sets the inputted pin to high");// 12
|
||||
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) {
|
||||
|
@ -178,30 +188,39 @@ void loopCommand(String input) {
|
|||
}
|
||||
}
|
||||
|
||||
void setPinLow(String input) {
|
||||
int pin = input.toInt();
|
||||
if (pin >= 0) {
|
||||
pinMode(pin, OUTPUT);
|
||||
digitalWrite(pin, LOW);
|
||||
Serial.println("Pin " + String(pin) + " set to LOW");
|
||||
} else {
|
||||
Serial.println("Invalid pin number");
|
||||
}
|
||||
|
||||
|
||||
void checkConnections(){ //tells what network the device Is connected to and prints the local IP of It
|
||||
Serial.print("Connected to...");
|
||||
Serial.println(ssid);
|
||||
Serial.println("Address Is");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
void setPinHigh(String input) {
|
||||
int pin = input.toInt();
|
||||
if (pin >= 0){
|
||||
pinMode(pin, OUTPUT);
|
||||
digitalWrite(pin, HIGH);
|
||||
Serial.println("Pin " + String(pin) + " set to HIGH");
|
||||
void sendUDP(String hostIp, String hostPort, String message){ //sends UDP message
|
||||
int port = hostPort.toInt();
|
||||
IPAddress ip;
|
||||
|
||||
} else {
|
||||
Serial.println("Invalid pin number");
|
||||
if (port <= 0) {
|
||||
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) {
|
||||
|
@ -257,27 +276,50 @@ void processCommand(String input) {
|
|||
loopCommand(input.substring(5));
|
||||
}
|
||||
else if (input.startsWith("high ")) {
|
||||
setPinHigh(input.substring(5));
|
||||
//setPinHigh(input.substring(5));
|
||||
}
|
||||
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);
|
||||
message.trim();
|
||||
Serial1.println(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 {
|
||||
Serial.println("Unknown command " + input); //changed this because I realized It makes more sense
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.begin(115200);
|
||||
delay(500);
|
||||
Serial.println("Welcome to GrainOS 1.8.3, `help` for a list of commands");
|
||||
Serial1.begin(9600, SERIAL_8N1, -1, 1);
|
||||
Serial.println("Welcome to GrainOS ESP32 1.1.0, `help` for a list of commands");
|
||||
Serial1.begin(9600, SERIAL_8N1, -1, 2);
|
||||
WiFi.begin(ssid, pass);
|
||||
server.begin();
|
||||
udp.begin(12345);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() { //the script runner :)
|
||||
|
|
Loading…
Add table
Reference in a new issue