Compare commits
No commits in common. "experimental" and "main" have entirely different histories.
experiment
...
main
1 changed files with 25 additions and 67 deletions
92
GrainOS.ino
92
GrainOS.ino
|
@ -1,14 +1,5 @@
|
||||||
#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;
|
||||||
|
@ -20,7 +11,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 scree n (again this is stupid)
|
Serial.println(); //function that clears your screen (again this is stupid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +73,6 @@ 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) {
|
||||||
|
@ -188,41 +178,32 @@ void loopCommand(String input) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setPinLow(String input) {
|
||||||
|
int pin = input.toInt();
|
||||||
void checkConnections(){ //tells what network the device Is connected to and prints the local IP of It
|
if (pin >= 0) {
|
||||||
Serial.print("Connected to...");
|
pinMode(pin, OUTPUT);
|
||||||
Serial.println(ssid);
|
digitalWrite(pin, LOW);
|
||||||
Serial.println("Address Is");
|
Serial.println("Pin " + String(pin) + " set to LOW");
|
||||||
Serial.println(WiFi.localIP());
|
} else {
|
||||||
|
Serial.println("Invalid pin number");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendUDP(String hostIp, String hostPort, String message){ //sends UDP message
|
void setPinHigh(String input) {
|
||||||
int port = hostPort.toInt();
|
int pin = input.toInt();
|
||||||
IPAddress ip;
|
if (pin >= 0){
|
||||||
|
pinMode(pin, OUTPUT);
|
||||||
|
digitalWrite(pin, HIGH);
|
||||||
|
Serial.println("Pin " + String(pin) + " set to HIGH");
|
||||||
|
|
||||||
if (port <= 0) {
|
} else {
|
||||||
Serial.println("Invalid port");
|
Serial.println("Invalid pin number");
|
||||||
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();
|
||||||
|
|
||||||
|
@ -276,50 +257,27 @@ 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 2) exclusive
|
else if (input.startsWith("send ")){ // sends UART messages (pin 1) 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(115200);
|
Serial.begin(9600);
|
||||||
delay(500);
|
delay(500);
|
||||||
Serial.println("Welcome to GrainOS ESP32 1.1.0, `help` for a list of commands");
|
Serial.println("Welcome to GrainOS 1.8.3, `help` for a list of commands");
|
||||||
Serial1.begin(9600, SERIAL_8N1, -1, 2);
|
Serial1.begin(9600, SERIAL_8N1, -1, 1);
|
||||||
WiFi.begin(ssid, pass);
|
|
||||||
server.begin();
|
|
||||||
udp.begin(12345);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() { //the script runner :)
|
void loop() { //the script runner :)
|
||||||
|
|
Loading…
Add table
Reference in a new issue