Commit c36f04e9 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

new gateway added & tested

parent a8b4d9e1
...@@ -2,10 +2,10 @@ from app.helpers.misc import with_psql ...@@ -2,10 +2,10 @@ from app.helpers.misc import with_psql
from psycopg2 import Binary from psycopg2 import Binary
@with_psql @with_psql
def create(cur, name, gwid, desc, secure_key, telemetry_send_freq): def create(cur, name, gwid, protocol, desc, secure_key, telemetry_send_freq):
cur.execute( cur.execute(
'INSERT INTO gateways VALUES (%s, %s, %s, %s, %s)', 'INSERT INTO gateways VALUES (%s, %s, %s, %s, %s, %s)',
(name, gwid, desc, Binary(secure_key), telemetry_send_freq) (name, gwid, protocol, desc, secure_key, telemetry_send_freq)
) )
return (True,) return (True,)
...@@ -35,19 +35,20 @@ def delete(cur, gwid): ...@@ -35,19 +35,20 @@ def delete(cur, gwid):
@with_psql @with_psql
def update(cur, name, gwid, desc, telemetry_send_freq): def update(cur, name, gwid, protocol, desc, telemetry_send_freq):
cur.execute( cur.execute(
""" """
UPDATE UPDATE
gateways gateways
SET SET
name = %s, name = %s,
protocol = %s,
desc = %s, desc = %s,
telemetry_send_freq = %s telemetry_send_freq = %s
WHERE WHERE
id = %s id = %s
""", """,
(name, desc, telemetry_send_freq, gwid) (name, protocol, desc, telemetry_send_freq, gwid)
) )
return (True,) return (True,)
{% extends 'logged_layout.html' %}
{% block title %} Administration - New Gateway - HPC&A IoT {% endblock %}
{% block location %}
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/administration">Administration</a>
<p class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"> &nbsp;-&nbsp; </p>
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/administration/gateways">Gateways</a>
{% endblock %}
{% block body %}
<!-- Page content -->
<div class="container-fluid mt--7">
<!-- Table -->
<div class="row">
<div class="col">
<div class="card shadow">
<div class="card-header bg-transparent">
<h3 class="mb-0">New Gateway</h3>
</div>
<div class="card-body">
<form action="/administration/new-gateway" method="post">
<div class="form-group">
<label>Name:</label><br>
<input type="text" maxlength="30" class="form-control" id="gwname" name="gwname" required><br>
</div>
<div class="form-group">
<label>ID:</label><br>
<input type="text" maxlength="20" class="form-control" id="gwid" name="gwid" required><br>
</div>
<div class="form-group">
<label>Protocol:</label><br>
<select class="form-control" id="gwprotocol" name="gwprotocol">
<option value="liteiot">LightIoT</option>
<option value="mqtt">MQTT</option>
<option value="rest">HTTP REST</option>
</select>
</div>
<div class="form-group">
<label>Description:</label><br>
<textarea id="gwdesc" maxlength="200" class="form-control" name="gwdesc" rows="5"></textarea>
</div>
<div class="form-group">
<label>Telemetry Send Frequency (seconds):</label><br>
<input type="number" min="1" class="form-control" id="gwtelemetry" name="gwtelemetry" required><br>
</div>
<br>
<div class="form-group">
<button type="submit" class="btn btn-primary">Create Gateway</button>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
...@@ -674,3 +674,19 @@ def administration_gateway(gwid): ...@@ -674,3 +674,19 @@ def administration_gateway(gwid):
return render_template('views/admin/gateway.html', utcnow=misc.get_utc(), info=info, gw=gw) return render_template('views/admin/gateway.html', utcnow=misc.get_utc(), info=info, gw=gw)
@app.route('/administration/new-gateway', methods=['GET', 'POST'])
@restricted('admin')
def administration_new_gateway():
if request.method == 'GET':
return render_template('views/admin/new-gateway.html', administration="active")
elif request.method == 'POST':
secure_key = misc.gen_skey_b64(16)
res = gd.create(request.form['gwname'], request.form['gwid'], request.form['gwprotocol'], request.form['gwdesc'], secure_key, request.form['gwtelemetry'])
if not res[0]:
app.logger.error('Administrator %s failed to create new gateway - %s', res[1])
flash('Error: {}'.format(res[1]), 'danger')
return redirect(request.url)
return redirect(url_for('administration_gateways'))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment