Compare commits
No commits in common. "2d581f9499cba17bef2ac3765e94dec50f45e6a2" and "4d141d6a12e6507c20c7bcbde535a57b4d68dd87" have entirely different histories.
2d581f9499
...
4d141d6a12
5 changed files with 5 additions and 102 deletions
|
|
@ -33,9 +33,9 @@ def bitmap():
|
||||||
|
|
||||||
payload = ''.join([chr(i) for i in bitmap_data])
|
payload = ''.join([chr(i) for i in bitmap_data])
|
||||||
print(payload)
|
print(payload)
|
||||||
# req = requests.post('http://10.141.142.75/api/tag', data=payload)
|
req = requests.post('http://10.141.142.75/api/tag', data=payload)
|
||||||
return jsonify({'payload': payload})
|
|
||||||
# return jsonify({'code': req.status_code})
|
return jsonify({'code': req.status_code})
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"error": e}), 500
|
return jsonify({"error": e}), 500
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,8 @@ services:
|
||||||
container_name: backend_service
|
container_name: backend_service
|
||||||
ports:
|
ports:
|
||||||
- "12001:80"
|
- "12001:80"
|
||||||
# bitmap_service:
|
|
||||||
# build: ./bitmap_service
|
|
||||||
# container_name: bitmap_service
|
|
||||||
# ports:
|
|
||||||
# - "12002:80"
|
|
||||||
bitmap_service:
|
bitmap_service:
|
||||||
build: ./trash
|
build: ./bitmap_service
|
||||||
container_name: trash
|
container_name: bitmap_service
|
||||||
ports:
|
ports:
|
||||||
- "12002:80"
|
- "12002:80"
|
||||||
55
trash/app.py
55
trash/app.py
|
|
@ -1,55 +0,0 @@
|
||||||
from flask import Flask, request, jsonify
|
|
||||||
from flask_cors import CORS
|
|
||||||
from PIL import Image
|
|
||||||
import io
|
|
||||||
from tcp import send_request
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
CORS(app)
|
|
||||||
|
|
||||||
@app.route('/')
|
|
||||||
def root():
|
|
||||||
return 'ok'
|
|
||||||
|
|
||||||
@app.route('/api/bitmap', methods=['POST'])
|
|
||||||
def bitmap():
|
|
||||||
|
|
||||||
if 'file' not in request.files:
|
|
||||||
return jsonify({"error": "no file"}), 400
|
|
||||||
|
|
||||||
file = request.files['file']
|
|
||||||
|
|
||||||
if file.filename == '':
|
|
||||||
return jsonify({"error": "no file"}), 400
|
|
||||||
|
|
||||||
if not file.filename.lower().endswith('.png'):
|
|
||||||
return jsonify({"error": "invalid file format"}), 400
|
|
||||||
|
|
||||||
try:
|
|
||||||
image_stream = io.BytesIO(file.read())
|
|
||||||
img = Image.open(image_stream)
|
|
||||||
grayscale_img = img.convert('L')
|
|
||||||
bitmap_data = list(grayscale_img.getdata())
|
|
||||||
|
|
||||||
payload = ''.join([chr(i) for i in bitmap_data])
|
|
||||||
print(payload)
|
|
||||||
|
|
||||||
chunk_size = 2048
|
|
||||||
for i in range(0, len(payload), chunk_size):
|
|
||||||
data = {
|
|
||||||
"command": "update_image",
|
|
||||||
"index": i,
|
|
||||||
"data": bytes(payload[i:i+chunk_size])
|
|
||||||
}
|
|
||||||
send_request(data)
|
|
||||||
send_request({"command":"push_image"})
|
|
||||||
|
|
||||||
# req = requests.post('http://10.141.142.75/api/tag', data=payload)
|
|
||||||
return jsonify({'payload': payload})
|
|
||||||
# return jsonify({'code': req.status_code})
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
return jsonify({"error": e}), 500
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
app.run('0.0.0.0', port=80)
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
FROM python:3.9
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
RUN pip3 install pillow flask flask-cors requests
|
|
||||||
|
|
||||||
CMD ["python3", "app.py"]
|
|
||||||
28
trash/tcp.py
28
trash/tcp.py
|
|
@ -1,28 +0,0 @@
|
||||||
from typing import Dict, Any
|
|
||||||
import socket
|
|
||||||
|
|
||||||
import msgpack
|
|
||||||
|
|
||||||
SERVER_ADDRESS = ('172.16.0.249', 8888)
|
|
||||||
|
|
||||||
def send_request(data:Dict[str, Any]):
|
|
||||||
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
||||||
client_socket.connect(SERVER_ADDRESS)
|
|
||||||
|
|
||||||
try:
|
|
||||||
message:bytes = msgpack.packb(data)
|
|
||||||
|
|
||||||
client_socket.sendall(message)
|
|
||||||
|
|
||||||
rx = client_socket.recv(1024)
|
|
||||||
if data:
|
|
||||||
print(f"Received message: {rx.decode('utf-8').strip()}")
|
|
||||||
else:
|
|
||||||
print("Connection closed")
|
|
||||||
return
|
|
||||||
except ConnectionResetError:
|
|
||||||
print("Connection reset")
|
|
||||||
finally:
|
|
||||||
client_socket.close()
|
|
||||||
print("Connection closed")
|
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue