Skip to content

3. Backend description

Eleftheria edited this page Sep 10, 2022 · 5 revisions

Backend description

For the bi-directional communication between the client and the server we use sockets. When using SocketIO, messages are received by both parties as events. On the client side Javascript callbacks are used. With Flask-SocketIO the server needs to register handlers for these events, similarly to how routes are handled by view functions. In the file : app.py under /blockly_server directory, you can find the server file. This file contains all the registered handlers for these events.

  • @socketio.on('connection') : To dispatch connection events
  • @socketio.on('disconnection') : To dispatch disconnection events
  • @socketio.on_error() : Handles the default namespace
  • @socketio.on('get-all-projects') : To dispatch all saved projects in the raspberry pi of the robot
  • @socketio.on('get_sound_effects') : To dispatch all sound effects saved in the directory: ~/data/sound_effects
  • @socketio.on('get_admin_panel_parameters') : To dispatch all admin parameters
  • @socketio.on('save_parameters') : Receives the parameters and saves them into the yaml file
  • @socketio.on('new_project') : To save a new project (title, info)
  • @socketio.on('delete_project') : To delete a saved project based on its id
  • @socketio.on('edit_project') : To edit a saved project based on its id
  • @socketio.on('execute_script') : To execute a script based on its id
  • @socketio.on('script_status') : To dispatch script status e.g. running or completed
  • @socketio.on('stop_script') : To stop script execution
  • @socketio.on('manual_control_command') : To execute one of the four commands( up, down, left, right )
  • @socketio.on('execute_blockly') : To execute a blockly script based on the id of the project
  • @socketio.on('send_xml') : To dispatch xml code, based on the project id
  • @socketio.on('save_xml') : To save xml code, which is the form that the blockly scripts are saved in the raspberry pi

Apart from the sockets, we haved laso used Flask App Routing, mapping the URLs to a specific function that will handle the logic for that URL.

  • @app.route('/') : Returns the main html page
  • @app.route('/admin_panel') : Returns the admin html page
  • @app.route('/blockly') : Returns the blockly html page
  • @app.route('/manual_control'): Returns the manual control html page
Clone this wiki locally