Compare commits
3 Commits
cdf195306e
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 12be29340b | |||
| 9d01ead120 | |||
| 5bac4c720b |
@@ -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")
|
||||
@@ -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,4 +1,5 @@
|
||||
flask==3.1.2
|
||||
flask-socketio
|
||||
python-dotenv
|
||||
psycopg2-binary
|
||||
pyjwt
|
||||
|
||||
Reference in New Issue
Block a user