diff --git a/controllerApp/Net.pde b/controllerApp/Net.pde index e01d344efc9e4a44ea9b47a023033f1fb7daa1a6..94214bcc83fc6d27875fcbe9f3df02db3202074a 100644 --- a/controllerApp/Net.pde +++ b/controllerApp/Net.pde @@ -1,11 +1,15 @@ import java.io.*; import java.net.*; +import java.util.UUID; class Net { JSONObject jsonParam; + String uuid; + public Net() { + this.uuid = UUID.randomUUID().toString(); } public void sendTap(float x, float y){ jsonParam = new JSONObject(); @@ -76,7 +80,7 @@ class Net @Override public void run() { try { - URL url = new URL("http://mathboard.cs-campus.fr/multicast/a1b2c3"); + URL url = new URL("http://controller.viarezo.fr/multicast?code="+code+"&id="+uuid); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); diff --git a/controllerApp/controllerApp.pde b/controllerApp/controllerApp.pde index 4d6e5882998cdde7daa7fee1f7461b8ce0688e7f..91c57d22a6a79b205a39ef75deb0741be6512fa0 100644 --- a/controllerApp/controllerApp.pde +++ b/controllerApp/controllerApp.pde @@ -14,6 +14,7 @@ float cx, cy, cz; float Size = 10; float Angle = 0; PImage img; +String code = "a1b2c3"; Boolean keyboard_flag = false; ArrayList<Thing> things = new ArrayList<Thing>(); ArrayList<BallWave> ball_waves = new ArrayList<BallWave>(); diff --git a/controllerSite/controllerSite.py b/controllerSite/controllerSite.py index 8e0c4cdb59fbc756ede2b566d915d2622dcd0595..7f421738956c75911c4da66771089065e779dd76 100644 --- a/controllerSite/controllerSite.py +++ b/controllerSite/controllerSite.py @@ -1,9 +1,12 @@ import os from flask import Flask, flash, request, jsonify, redirect, url_for, render_template +from flask_socketio import SocketIO from flask_bootstrap import Bootstrap from werkzeug.utils import secure_filename app = Flask(__name__) +socketio = SocketIO(app) +clients = {} queue = [] @@ -23,32 +26,29 @@ def allowed_file(filename): return '.' in filename and \ filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS -@app.route('/multicast/<string:id>', methods=['GET', 'POST']) -def upload_file(id): +@app.route('/multicast', methods=['GET', 'POST']) +def multicast(): if request.method == 'POST': + code = request.form['code'] + id = request.form['id'] content = request.json - print(content) - return jsonify({"id":id}) + print(code,id,content) + socketio.emit('multicast', content, callback=confirmReception,namespace='/'+code) + return jsonify({"code":code,"id":id}) return ''' <!doctype html> - <title>Upload new File</title> - <h1>Upload new File</h1> - <form method=post enctype=multipart/form-data> - <input type=file name=file> - <input type=submit value=Upload> - </form> + <title>Use a HTTP POST Request</title> ''' +def confirmReception(): + print('Message Received.') -@app.route('/verify/<string:id>/') -def items(id): - - if id in queue: - return 'False' - else: - return 'True' +@socketio.on('code') +def handle_code(json, methods=['GET', 'POST']): + print('code received: ' + str(json)) + socketio.emit('message', json, callback=confirmReception,namespace='/a1b2c3') if __name__ == '__main__': - app.run(debug = True,host = "0.0.0.0",port = 80) + socketio.run(app,debug = True,host = "0.0.0.0",port = 80)