Initial commit
This commit is contained in:
commit
494429a6be
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
.vscode/
|
||||||
|
env/
|
||||||
81
print.py
Normal file
81
print.py
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import socket
|
||||||
|
import json
|
||||||
|
from flask import Flask, render_template
|
||||||
|
|
||||||
|
CheckPrinterOnline = '7e4d3630312053310d0a'
|
||||||
|
MachingInfo = "7e4d3131350d0a"
|
||||||
|
GetPrintPercent = "7e4d32370d0a"
|
||||||
|
GetPrinterTemp = "7e4d3130350d0a"
|
||||||
|
|
||||||
|
HOST = '10.1.1.83' # The server's hostname or IP address
|
||||||
|
PORT = 8899 # The port used by the server
|
||||||
|
|
||||||
|
application = Flask(__name__)
|
||||||
|
application.config["DEBUG"] = True
|
||||||
|
|
||||||
|
def checkPrinterOnline():
|
||||||
|
try:
|
||||||
|
data = sendCode(CheckPrinterOnline)
|
||||||
|
return data
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def sendCode(cmddata):
|
||||||
|
command = bytes.fromhex(cmddata)
|
||||||
|
try:
|
||||||
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||||
|
s.settimeout(1)
|
||||||
|
s.connect((HOST, PORT))
|
||||||
|
s.sendall(command)
|
||||||
|
data = s.recv(1024)
|
||||||
|
except Exception as E:
|
||||||
|
print(E)
|
||||||
|
data = "Connection Failed"
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
def actualPercent():
|
||||||
|
data = sendCode(GetPrintPercent)
|
||||||
|
if data == "Connection Failed":
|
||||||
|
return "COnnection Failed"
|
||||||
|
data = data.decode().split('\r\n')[1].split()[-1]
|
||||||
|
x, y = data.split('/')
|
||||||
|
return int(x) / int(y) * 100
|
||||||
|
|
||||||
|
def getTemp():
|
||||||
|
data = sendCode(GetPrinterTemp)
|
||||||
|
data = data.split()
|
||||||
|
try:
|
||||||
|
currTemp = data[3].decode().split(':')[1]
|
||||||
|
maxTemp = data[4].decode().split('/')[1]
|
||||||
|
except IndexError as E:
|
||||||
|
print(data)
|
||||||
|
return [currTemp, maxTemp]
|
||||||
|
|
||||||
|
# sendCode(CheckPrinterOnline)
|
||||||
|
# sendCode(MachingInfo)
|
||||||
|
# sendCode(GetPrintPercent)
|
||||||
|
|
||||||
|
# print(bytes.fromhex(MaybePacketStart).decode('utf-8'))
|
||||||
|
|
||||||
|
@application.route('/')
|
||||||
|
def index():
|
||||||
|
if checkPrinterOnline() != "Connection Failed":
|
||||||
|
try:
|
||||||
|
return render_template("index.html")
|
||||||
|
except Exception as E:
|
||||||
|
data = E
|
||||||
|
else:
|
||||||
|
data = ["The Printer is Offline"]
|
||||||
|
return render_template("error.html", data=data)
|
||||||
|
|
||||||
|
@application.route('/percent')
|
||||||
|
def percent():
|
||||||
|
data = {"percent": str(round(actualPercent(),3)), "temp": getTemp()}
|
||||||
|
# print()
|
||||||
|
return json.dumps(data)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
application.run(host='0.0.0.0', port=80)
|
||||||
25
static/css/index.css
Normal file
25
static/css/index.css
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
.parent {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
font-size: 80;
|
||||||
|
/* font-family: 'Comic Neue', cursive; */
|
||||||
|
font-family: "Comic Sans MS", "Comic Sans", cursive;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 800px) {
|
||||||
|
.parent {
|
||||||
|
font-size: 60;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 1000px) {
|
||||||
|
.parent {
|
||||||
|
font-size: 80;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
18
static/js/reload.js
Normal file
18
static/js/reload.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
function loadContent() {
|
||||||
|
let domain = "http://localhost/percent"
|
||||||
|
let xhttp = new XMLHttpRequest();
|
||||||
|
let ele = document.getElementById('number')
|
||||||
|
let temp = document.getElementById('temp')
|
||||||
|
xhttp.onreadystatechange = function() {
|
||||||
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
|
let obj = JSON.parse(this.responseText)
|
||||||
|
ele.innerHTML = obj.percent
|
||||||
|
temp.innerHTML = obj.temp[0] + "°C / " + obj.temp[1] + "°C"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhttp.open("GET", domain, true);
|
||||||
|
xhttp.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(loadContent, 4000)
|
||||||
|
loadContent()
|
||||||
14
templates/error.html
Normal file
14
templates/error.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="refresh" content="5">
|
||||||
|
<title>What percent is the printer at</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="static/css/index.css">
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Comic+Neue&display=swap" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body bgcolor="#2e2e2e">
|
||||||
|
<div class="parent" style="color: azure;">
|
||||||
|
The printer is offline
|
||||||
|
</div>
|
||||||
|
<!-- <script src="static/js/reload.js"></script> -->
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
16
templates/index.html
Normal file
16
templates/index.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<!-- <meta http-equiv="refresh" content="5"> -->
|
||||||
|
<title>What percent is the printer at</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="static/css/index.css?ver=2">
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Comic+Neue&display=swap" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body bgcolor="#2e2e2e">
|
||||||
|
<div class="parent" style="color: azure;">
|
||||||
|
<div>The print is: <section style="display: inline;" id='number'></section>% complete</div>
|
||||||
|
<div style="width: 5%;"></div>
|
||||||
|
<div>The Temp is <section style="display: inline;" id='temp'></section></div>
|
||||||
|
</div>
|
||||||
|
<script src="static/js/reload.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user