Skip to content
GitLab
Explore
Sign in
Davide Ricci
software-di-controllo
Compare revisions
a65809bf1dee7d101dbc6766a8749f5b2639c61d to 8511fefd58f98e256e3452fedf1e42fbba996bef
Commits on Source (3)
webcam works
· 861b29ad
Davide Ricci
authored
Mar 14, 2024
861b29ad
new_lines works
· e173afa7
Davide Ricci
authored
Mar 14, 2024
e173afa7
mor int_url vs ext_url
· 8511fefd
Davide Ricci
authored
Mar 14, 2024
8511fefd
Hide whitespace changes
Inline
Side-by-side
web/pages/index.html
View file @
8511fefd
...
...
@@ -17,7 +17,7 @@
<!-- internal resources -->
<script
type=
"text/javascript"
>
var
api_base_url
=
"
{{
api
_base_url|safe }}
"
var
api_base_url
=
"
{{
ext
_base_url|safe }}
"
</script>
<script
src=
"/static/js/ansi_up.js"
></script>
<script
src=
"/static/form-crud.js"
></script>
...
...
web/server/instance.py
View file @
8511fefd
...
...
@@ -35,12 +35,12 @@ def enable(app):
connected_clients
=
{}
ws_names
=
[
#
base_url["int_base_url"]+"/all/dome",
#
base_url["int_base_url"]+"/all/telescope",
base_url
[
"
int_base_url
"
]
+
"
/all/dome
"
,
base_url
[
"
int_base_url
"
]
+
"
/all/telescope
"
,
base_url
[
"
int_base_url
"
]
+
"
/all/camera?wait=0.2
"
,
#
base_url["int_base_url"]+"/api/sequencer/run",
base_url
[
"
int_base_url
"
]
+
"
/api/sequencer/run
"
,
base_url
[
"
int_base_url
"
]
+
"
/api/webcam/snapshot
"
,
#
base_url["int_base_url"]+"new_lines",
base_url
[
"
int_base_url
"
]
+
"
new_lines
"
,
]
@socketio.on
(
'
connect
'
)
...
...
@@ -86,14 +86,14 @@ def enable(app):
url
=
base_url
[
"
int_base_url
"
]
+
"
/all/telescope
"
)
socketio
.
start_background_task
(
stream
.
send_status
,
socketio
=
socketio
,
url
=
base_url
[
"
int_base_url
"
]
+
"
/all/camera?wait=0.2
"
)
#
socketio.start_background_task(stream.send_status, socketio=socketio,
#
url=base_url["int_base_url"]+"/api/sequencer/run")
socketio
.
start_background_task
(
stream
.
send_status
,
socketio
=
socketio
,
url
=
base_url
[
"
int_base_url
"
]
+
"
/api/sequencer/run
"
)
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.tail_f, socketio=socketio)
socketio
.
start_background_task
(
stream
.
tail_f
,
socketio
=
socketio
)
return
socketio
web/server/stream.py
View file @
8511fefd
...
...
@@ -19,7 +19,7 @@ class Status:
def
initial
(
self
,
socketio
,
urls
):
for
url
in
urls
:
name
=
url
.
split
(
"
?
"
)[
0
]
# maybe different?
name
=
name
.
split
(
"
5533
"
)[
1
]
# maybe different?
name
=
name
.
split
(
"
5533
"
)[
1
]
# maybe different?
socketio
.
emit
(
name
,
self
.
last
[
name
])
status
=
Status
()
...
...
@@ -34,12 +34,13 @@ def send_timestamp(socketio):
def
send_status
(
socketio
,
url
,
sleep
=
2
,
once
=
False
):
name
=
url
.
split
(
"
?
"
)[
0
]
# maybe different?
name
=
name
.
split
(
"
5533
"
)[
1
]
# maybe different?
# 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
)
...
...
@@ -52,18 +53,18 @@ def send_status(socketio, url, sleep=2, once=False):
def
send_webcam
(
socketio
,
url
,
sleep
=
1
):
name
=
url
# maybe different?
name
=
url
.
split
(
"
?
"
)[
0
]
# maybe different?
name
=
name
.
split
(
"
5533
"
)[
1
]
# maybe different?
#print(name, url)
while
True
:
socketio
.
sleep
(
sleep
)
res
=
requests
.
get
(
url
).
json
()
img
=
res
[
"
response
"
].
encode
(
"
ISO-8859-1
"
)
status
.
last
[
name
]
=
bytes
(
img
)
socketio
.
emit
(
url
,
bytes
(
img
))
#print(status.last[name])
socketio
.
emit
(
name
,
bytes
(
img
))
def
tail_f
(
socketio
,
num_lines
=
30
,
sleep
=
0.25
,
once
=
False
):
today
=
datetime
.
utcnow
().
isoformat
().
split
(
"
T
"
)[
0
]
...
...
@@ -120,7 +121,7 @@ def send_binary(socketio):
def
send_fits
(
socketio
):
"""
download a fits
"""
with
fits
.
open
(
"
./temp.fits
"
)
as
hdul
:
matrix
=
hdul
[
0
].
data
header
=
hdul
[
0
].
header
...
...
@@ -135,4 +136,3 @@ def send_fits(socketio):
socketio
.
emit
(
'
data_fits
'
,
data_bundle
)
print
((
datetime
.
utcnow
().
timestamp
()
-
unix
),
"
emitted
"
)
print
(
f
"
bin
{
len
(
matrix
)
}
"
)
web/static/status-streams.js
View file @
8511fefd
...
...
@@ -180,12 +180,11 @@ socket.on("/api/environment/status", function(e) {
///////////////////////
socket
.
on
(
"
/api/webcam/snapshot
"
,
function
(
e
)
{
var
res
=
e
//JSON.parse(e.data)
const
elem
=
$
(
"
[data-status=webcam-snapshot
"
)
//console.log(
res
)
//console.log(
e
)
if
(
res
)
{
const
url
=
btoa
(
String
.
fromCharCode
(...
new
Uint8Array
(
res
)));
if
(
e
)
{
const
url
=
btoa
(
String
.
fromCharCode
(...
new
Uint8Array
(
e
)));
elem
.
attr
(
"
src
"
,
'
data:image/jpeg;base64,
'
+
url
)
}
else
{
console
.
log
(
"
no image?
"
)
...
...