3 Commits

Author SHA1 Message Date
Kirill 12be29340b feat(api/ws.py): WebSoket 2025-10-31 13:47:55 +03:00
Kirill 9d01ead120 feat(dependencies.txt): Update libs
Added Libs for work with webSockets
2025-10-31 13:46:23 +03:00
Kirill 5bac4c720b feat(api/robots.py): Robots Api 2025-10-31 13:45:30 +03:00
3 changed files with 51 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
from flask import Blueprint, request, jsonify
from model.user import User
#from module.db.repositories.robot_reposytory import update_robot get_by_id
from loguru import logger as log
robots = Blueprint("robots", __name__)
robots.route('/data', methods = ['POST'])
def data():
if request.headers.get("Authorization"):
if request.is_json:
req = request.json
id = req.get('robot_id')
tms = req.get('timestamp')
loc = req.get('location')
scanRes = req.get('scan_results')
battery = req.get('battery_level')
if update_robot(id, "received", battery, loc["zone"], loc["row"], loc["self"]):
res = {"status": "received", "message_id": "123"} #for that moment i don`t now what is message
return jsonify(res)
else:
log.error('failed to update robot data')
return("Server error")
+26
View File
@@ -0,0 +1,26 @@
from app import app
from flask_socketio import SocketIO, emit
from loguru import logger as log
#from module.db.repositories.robot_reposytory import update_robot get_by_id get_all
#from module.db.repositories.inventory_repository import get_all as getRecords
ws = socketIO(app)
@ws.on('connect')
def is_connect():
log.info('client is connected')
@ws.on('disconnect')
def is_disconnect():
log.info('client is disconnected')
@ws.on('robot_update')
def robotUpdate():
robots = get_all()
emit('response', jsonify({"type": "robot_update", "data": {robots.toJSON()}})
@ws.on('inventory_alert')
def robotUpdate():
records = getRecords()
emit('response', jsonify({"type": "inventory_alert", "data": {records.toJSON()}})
+1
View File
@@ -1,4 +1,5 @@
flask==3.1.2
flask-socketio
python-dotenv
psycopg2-binary
pyjwt