Skip to content
GitLab
Explore
Sign in
Davide Ricci
software-di-controllo
Compare revisions
5bb6953753befd632bb809015c83f3512aac45d5 to db87632336b9b988f6b006c0dd6934b9b7addb9d
Commits on Source (2)
mor int_url vs ext_url
· f7e17a90
Davide Ricci
authored
Mar 14, 2024
f7e17a90
Merge branch 'dev' of
https://www.ict.inaf.it/gitlab/davide.ricci/software-di-controllo
into dev
· db876323
Davide Ricci
authored
Mar 14, 2024
db876323
Show whitespace changes
Inline
Side-by-side
app.py
View file @
db876323
...
...
@@ -5,6 +5,7 @@
# System modules
import
time
import
logging
# Third-party modules
from
flask
import
Flask
,
request
...
...
@@ -20,6 +21,7 @@ app.threaded = True
cors
=
CORS
(
app
)
@app.route
(
'
/all/<string:namespace>
'
)
def
get_status
(
namespace
):
'''
Build a global status for a given namespace
'''
...
...
@@ -46,6 +48,7 @@ def get_status(namespace):
return
endpoints
if
__name__
==
"
__main__
"
:
# System modules
...
...
@@ -66,6 +69,10 @@ if __name__ == "__main__":
print
(
f
"
hostname
{
hostname
}
"
)
if
with_web
:
socketio
=
instance
.
enable
(
app
)
socketio
.
run
(
app
,
host
=
hostname
,
port
=
port
)
...
...
web/server/instance.py
View file @
db876323
...
...
@@ -20,18 +20,21 @@ def enable(app):
app
.
register_blueprint
(
routes
.
web
,
url_prefix
=
'
/web
'
)
base_url
=
{
"
ext_base_url
"
:
"
http://fork.orsa.unige.net:5533
"
,
"
int_base_url
"
:
"
http://10.185.119.108:5533
"
}
base_url
=
{
"
ext_base_url
"
:
"
http://fork.orsa.unige.net:5533
"
,
# what form-crud needs
"
int_base_url
"
:
"
http://10.185.119.108:5533
"
}
# what instance needs
# "int_base_url": "http://130.251.19.108:5533"} # from outside
@app.context_processor
def
inject_variables
():
return
base_url
socketio
=
SocketIO
(
app
,
path
=
"
/web/socket
"
,
async_mode
=
'
threading
'
,
threaded
=
True
)
connected_clients
=
{}
ws_names
=
[
...
...
@@ -91,8 +94,8 @@ def enable(app):
socketio
.
start_background_task
(
stream
.
send_webcam
,
socketio
=
socketio
,
url
=
base_url
[
"
int_base_url
"
]
+
"
/api/webcam/snapshot
"
)
#
socketio.start_background_task(stream.send_status, socketio=socketio,
#
url=base_url["int_base_url"]+"/api/environment/status", sleep=40)
socketio
.
start_background_task
(
stream
.
send_status
,
socketio
=
socketio
,
url
=
base_url
[
"
int_base_url
"
]
+
"
/api/environment/status
"
,
sleep
=
40
)
socketio
.
start_background_task
(
stream
.
tail_f
,
socketio
=
socketio
)
...
...
web/server/stream.py
View file @
db876323
...
...
@@ -37,10 +37,8 @@ def send_status(socketio, url, sleep=2, once=False):
# First time
socketio
.
sleep
(
sleep
)
print
(
url
)
old
=
requests
.
get
(
url
).
json
()
status
.
last
[
name
]
=
old
#socketio.emit(name, old)
while
not
once
:
socketio
.
sleep
(
sleep
)
...
...
@@ -78,6 +76,7 @@ def tail_f(socketio, num_lines=30, sleep=0.25, once=False):
status
.
last
[
'
new_lines
'
]
=
lines
while
not
once
:
socketio
.
sleep
(
sleep
)
# Sleep before checking again
current_size
=
os
.
path
.
getsize
(
filename
)
if
current_size
<
file_size
:
file_size
=
0
...
...
@@ -91,7 +90,6 @@ def tail_f(socketio, num_lines=30, sleep=0.25, once=False):
socketio
.
emit
(
'
new_lines
'
,
new_lines
)
status
.
last
[
'
new_lines
'
]
=
new_lines
socketio
.
sleep
(
sleep
)
# Sleep before checking again
def
send_binary
(
socketio
):
...
...