|
@@ -4,38 +4,34 @@ from .utils.app_modes import AppMode
|
|
|
|
|
|
bp = Blueprint('main', __name__)
|
|
|
|
|
|
-# @bp.route('/')
|
|
|
-# def index():
|
|
|
-# mode = current_app.config['MODE']
|
|
|
-# mqtt_handler = current_app.config['mqtt_handler']
|
|
|
-
|
|
|
-# # If the app is in TEST mode, start publishing mock data in a separate thread.
|
|
|
-# if mode == AppMode.TEST:
|
|
|
-# threading.Thread(target=mqtt_handler.publish_mock_data).start()
|
|
|
-
|
|
|
-# return render_template('dashboard.html', mode=mode, host=current_app.config['MQTT_HOST'])
|
|
|
-
|
|
|
@bp.route('/')
|
|
|
def root():
|
|
|
return redirect(url_for('main.sim_dashboard'))
|
|
|
|
|
|
@bp.route('/dashboard/sim')
|
|
|
def sim_dashboard():
|
|
|
- return render_template("dashboards/sim.html", mode=AppMode.SIM.value, host=current_app.config['MQTT_HOST_SIM'])
|
|
|
+ return render_template("dashboards/sim.html", mode=AppMode.SIM.value, config=current_app.config)
|
|
|
|
|
|
@bp.route('/dashboard/monitor')
|
|
|
def monitor_dashboard():
|
|
|
- return render_template("dashboards/monitor.html", mode=AppMode.REAL.value, host=current_app.config['MQTT_HOST_REAL'])
|
|
|
+ return render_template("dashboards/monitor.html", mode=AppMode.REAL.value, config=current_app.config)
|
|
|
|
|
|
@bp.route('/dashboard/hybrid')
|
|
|
def hybrid_dashboard():
|
|
|
- return render_template("dashboards/hybrid.html", mode=AppMode.HYBRID.value, host='?')
|
|
|
+ return render_template("dashboards/hybrid.html", mode=AppMode.HYBRID.value, config=current_app.config)
|
|
|
|
|
|
|
|
|
@bp.route('/api/publish', methods=['POST'])
|
|
|
def publish():
|
|
|
- mqtt_handler = current_app.config['mqtt_handler_sim'] # TODO: Change to real handler when needed
|
|
|
topic = request.form['topic']
|
|
|
message = request.form['message']
|
|
|
+ target = request.form.get('target', 'sim')
|
|
|
+
|
|
|
+ if target == 'real':
|
|
|
+ mqtt_handler = current_app.config['mqtt_handler_real']
|
|
|
+ elif target == 'sim':
|
|
|
+ mqtt_handler = current_app.config['mqtt_handler_sim']
|
|
|
+ else:
|
|
|
+ return 'Invalid target specified', 400
|
|
|
mqtt_handler.publish(topic, message)
|
|
|
return 'Message Sent!'
|