created project, added code, added library
created project, added code from phantomix, which got slightly changed to talk to the parallelport library
This commit is contained in:
parent
48b8dfb101
commit
1b86ce5eed
|
@ -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
|
|
@ -0,0 +1,109 @@
|
|||
#include <ParallelPrinter.h>
|
||||
#include <WiFi.h>
|
||||
#include <WebServer.h>
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue