Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladislav Rykov
THSO.server
Commits
c36f04e9
Commit
c36f04e9
authored
Oct 27, 2020
by
Vladislav Rykov
Browse files
new gateway added & tested
parent
a8b4d9e1
Changes
4
Show whitespace changes
Inline
Side-by-side
app/app/__pycache__/views_admin.cpython-37.pyc
View file @
c36f04e9
No preview for this file type
app/app/dao/gateway/gateway.py
View file @
c36f04e9
...
@@ -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
,)
app/app/templates/views/admin/new-gateway.html
0 → 100644
View file @
c36f04e9
{% 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"
>
-
</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 %}
app/app/views_admin.py
View file @
c36f04e9
...
@@ -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'
))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment