From 1b86ce5eed358b5672e0634cf04ea2ae533765d7 Mon Sep 17 00:00:00 2001 From: Moritz Kempe Date: Fri, 20 May 2022 23:43:52 +0200 Subject: [PATCH] created project, added code, added library created project, added code from phantomix, which got slightly changed to talk to the parallelport library --- platformio.ini | 18 ++++++++ src/main.cpp | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 platformio.ini create mode 100644 src/main.cpp diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..7f9f563 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,18 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:az-delivery-devkit-v4] +platform = espressif32 +board = az-delivery-devkit-v4 +framework = arduino +monitor_speed = 9600 + +; Libraries +lib_deps = robtillaart/ParallelPrinter@^0.2.4 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..12a2b5c --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,109 @@ +#include +#include +#include + +WiFiServer server(21); +WiFiClient client; + +#define wifi_ssid "dezentrale-2.4" +#define wifi_password "dezentrale" + +ParallelPrinter PP; + +bool wifi_connect() +{ + delay(5000); + Serial.print("Connecting to "); + Serial.println(wifi_ssid); + + WiFi.begin(wifi_ssid, wifi_password); + static int timeout = 20; + while (WiFi.status() != WL_CONNECTED) + { + Serial.print("."); + if(timeout == 0) + { + Serial.println("Failed to connect: Timeout"); + return false; + } + timeout--; + delay(500); + } + + Serial.println(""); + Serial.println("WiFi connected"); + Serial.println("Local IP address: "); + Serial.println(WiFi.localIP()); + return true; +} + +void setup() +{ +// put your setup code here, to run once: + Serial.begin(9600); + Serial.println(); + + if(wifi_connect()) + { + server.begin(); + Serial.println("Telnet port = 21"); + Serial.println("Password: drucker"); + } else + { + Serial.println("Failed to connect."); + } + Serial.println(); + Serial.println(); + + PP.begin(); // create connection to printer +} + +bool clientAuthorized = false; +void loop() +{ +// put your main code here, to run repeatedly: + + size_t bytes = 0; + if (client.connected()) + { + bytes = client.available(); + if (bytes) + { + if (clientAuthorized) + { + char buf[32]; + if (bytes > 32) bytes = 32; + client.readBytes(buf,bytes); + String line = client.readStringUntil('\n'); + //PP.println(buf,bytes); + PP.println(line); + Serial.write(buf,bytes); + //Serial.print('\n'); + } else + { + String line = client.readStringUntil('\n'); + if(!strcmp("drucker",line.c_str())) // Passwordcheck + { + clientAuthorized = true; + client.println("You are now logged in."); + } + } + } + size_t bytes = Serial.available(); + if(bytes) + { + char buf[32]; + if(bytes > 32) bytes = 32; + Serial.readBytes(buf, bytes); + //String s = Serial.readString(); + //client.print(s); + client.write(buf,bytes); + } + } else + { + clientAuthorized = false; + client = server.available(); + //send out password info + client.println("Please enter password."); + } +}