Compare commits
No commits in common. "experimental" and "main" have entirely different histories.
experiment
...
main
1 changed files with 25 additions and 67 deletions
88
GrainOS.ino
88
GrainOS.ino
|
@ -1,14 +1,5 @@
|
|||
#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;
|
||||
|
@ -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(" 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) {
|
||||
|
@ -188,40 +178,31 @@ void loopCommand(String input) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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 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 sendUDP(String hostIp, String hostPort, String message){ //sends UDP message
|
||||
int port = hostPort.toInt();
|
||||
IPAddress ip;
|
||||
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");
|
||||
|
||||
if (port <= 0) {
|
||||
Serial.println("Invalid port");
|
||||
return;
|
||||
} else {
|
||||
Serial.println("Invalid pin number");
|
||||
}
|
||||
|
||||
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) {
|
||||
input.trim();
|
||||
|
@ -276,50 +257,27 @@ 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 2) exclusive
|
||||
else if (input.startsWith("send ")){ // sends UART messages (pin 1) 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(115200);
|
||||
Serial.begin(9600);
|
||||
delay(500);
|
||||
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);
|
||||
|
||||
|
||||
Serial.println("Welcome to GrainOS 1.8.3, `help` for a list of commands");
|
||||
Serial1.begin(9600, SERIAL_8N1, -1, 1);
|
||||
}
|
||||
|
||||
void loop() { //the script runner :)
|
||||
|
|
Loading…
Add table
Reference in a new issue