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
Pinon Gregory
Yes We Canne Supervision
Commits
1d2ab6ea
Commit
1d2ab6ea
authored
Mar 28, 2022
by
Pinon Gregory
🦉
Browse files
ajout localisation watchdogs et notif server .py
parent
213810ca
Changes
10
Hide whitespace changes
Inline
Side-by-side
docker-compose.yaml
View file @
1d2ab6ea
...
...
@@ -31,11 +31,13 @@ services:
-
"
socket"
-
"
backend"
# notification:
# build: notification-server
# image: gaetanbrmd/notification
# ports:
# - "3002:3000"
notification
:
build
:
notification-server
image
:
oemcywc/notification
ports
:
-
"
3002:3000"
depends_on
:
-
"
socket"
proxy
:
build
:
proxy-supervision
...
...
@@ -51,6 +53,13 @@ services:
depends_on
:
-
"
backend"
-
"
frontend"
localisation
:
build
:
localisation-watchdog
image
:
oemcywc/localisation
depends_on
:
-
"
socket"
# TODO : Database feeder sur chaque Raspi (arguments env)
secrets
:
...
...
localisation-watchdog/Database_feeder.py
0 → 100644
View file @
1d2ab6ea
import
serial
import
time
import
socket
import
os
import
sys
import
json
from
pyignite
import
Client
import
geojson
from
shapely.geometry
import
shape
,
Point
,
Polygon
listePieces
=
[]
try
:
with
open
(
"bat_info_v2.oemc"
)
as
f
:
plan
=
json
.
load
(
f
)
print
(
"GeoJSON found and opened"
)
except
Exception
:
print
(
"Unable to open any GeoJSON"
)
exit
(
1
)
for
piece
in
plan
[
"rooms"
][
"features"
]:
infoUn
=
str
(
list
(
piece
[
'properties'
].
values
())[
0
])
infoDeux
=
str
(
list
(
piece
[
'properties'
].
values
())[
1
])
listePieces
.
append
((
infoUn
+
" "
+
infoDeux
,
Polygon
(
piece
[
'geometry'
][
'coordinates'
])))
print
(
listePieces
)
try
:
serialDev
=
"/dev/serial/by-id/"
+
os
.
listdir
(
"/dev/serial/by-id"
)[
0
]
print
(
serialDev
)
except
Exception
:
type
,
value
,
traceback
=
sys
.
exc_info
()
print
(
'Error opening %s: %s'
%
(
value
.
filename
,
value
.
strerror
))
print
(
"Switching to GPIO"
)
serialDev
=
"/dev/serial0"
"""
try:
dbAdress = os.environ['DB_ADRESS']
except Exception:
dbAdress = "127.0.0.1"
try:
password = os.environ['DB_PASS']
except Exception:
print("Please set password for the db in DB_PASS env variable")
exit(1)
print("Current settings : "+dbAdress+" "+serialDev+" "+password)
client = Client(username='ignite', password=password, use_ssl=False)
client.connect(dbAdress,10800)
cachePositions = client.get_or_create_cache('positions')
cachePositions.clear()
print("DB Connected, connecting to DWM")
"""
hostname
=
socket
.
gethostname
()
try
:
DWM
=
serial
.
Serial
(
port
=
serialDev
,
baudrate
=
115200
)
except
Exception
:
type
,
value
,
traceback
=
sys
.
exc_info
()
print
(
'Error opening %s: %s'
%
(
value
.
filename
,
value
.
strerror
))
print
(
"No DWM detected ! Try to specify it with env. var :)"
)
exit
(
1
)
print
(
"Connecting to "
+
DWM
.
name
)
#DWM.write("reset\r".encode())
time
.
sleep
(
3
)
DWM
.
write
(
"
\r\r
"
.
encode
())
shellModeChar
=
DWM
.
read
().
decode
()
if
(
shellModeChar
==
"@"
):
while
(
shellModeChar
==
"@"
):
print
(
"Trying to get into shell mode..."
)
DWM
.
write
(
"
\r\r
"
.
encode
())
time
.
sleep
(
1
)
shellModeChar
=
DWM
.
read
().
decode
()
time
.
sleep
(
2
)
DWM
.
write
(
"les
\r
"
.
encode
())
try
:
print
(
"Beginning data parsing..."
)
while
True
:
data
=
DWM
.
readline
()
if
(
data
):
localisation
=
data
.
decode
()
stripped
=
localisation
.
strip
()
#print(localisation)
splited
=
stripped
.
split
(
")"
)
try
:
goodLine
=
splited
[
1
]
tagNo
=
goodLine
[
1
:
5
]
positions
=
goodLine
[
goodLine
.
find
(
"["
)
+
1
:
goodLine
.
find
(
"]"
)]
listPos
=
positions
.
split
(
","
)
stringPos
=
"{
\"
baliseID
\"
:
\"
"
+
tagNo
+
"
\"
,
\"
x
\"
:"
+
listPos
[
0
]
+
",
\"
y
\"
:"
+
listPos
[
1
]
+
"}"
#print(stringPos)
try
:
pStr
=
""
for
elem
in
listePieces
:
point
=
Point
(
float
(
listPos
[
0
]),
float
(
listPos
[
1
]))
if
elem
[
1
].
contains
(
point
):
pStr
=
elem
[
0
]
except
Exception
as
e
:
print
(
e
)
if
"nan"
not
in
(
listPos
[
0
],
listPos
[
1
]):
print
(
stringPos
)
cachePositions
.
put
(
tagNo
,
stringPos
,
pStr
)
except
Exception
as
e
:
pass
#DWM.write("\r".encode())
DWM
.
close
()
except
KeyboardInterrupt
:
#DWM.write("les\r".encode())
DWM
.
write
(
"reset
\r
"
.
encode
())
print
(
"Stop"
)
localisation-watchdog/Dockerfile
0 → 100644
View file @
1d2ab6ea
FROM
python:3
ADD
Database_feeder.py /
RUN
pip
install
pyserial
RUN
pip
install
pyignite
RUN
pip
install
geojson
RUN
pip
install
shapely
COPY
*.oemc /
CMD
["python","-u","/Database_feeder.py"]
localisation-watchdog/bat_info.oemc
0 → 100644
View file @
1d2ab6ea
{
"meters-per-pixels": [
1,
1
],
"balises": {
"type": "FeatureCollection",
"features": []
},
"doors": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
238.119846,
183.070634
],
[
267.564773,
183.070634
]
]
},
"properties": {
"exit-1": [
256.04284518828445,
157.46634979079494
],
"exit-2": [
252.20220251046018,
204.83427615062755
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
285.487772,
158.746564
],
[
285.487772,
133.782387
]
]
},
"properties": {
"exit-1": [
256.04284518828445,
147.22463598326354
],
"exit-2": [
307.891521338912,
149.14495732217569
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
97.936388,
183.070634
],
[
129.941744,
184.990956
]
]
},
"properties": {
"exit-1": [
112.01874476987444,
155.5460284518828
],
"exit-2": [
113.93906610878658,
197.15299079497902
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
298.289915,
183.070634
],
[
323.894199,
184.990956
]
]
},
"properties": {
"exit-1": [
318.7733422594141,
159.38667112970705
],
"exit-2": [
314.29259246861915,
206.7545974895397
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
438.473372,
184.990956
],
[
468.558407,
183.710741
]
]
},
"properties": {
"exit-1": [
449.9953004184099,
153.62570711297067
],
"exit-2": [
451.915621757322,
204.83427615062755
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
470.478728,
181.79042
],
[
500.563762,
183.070634
]
]
},
"properties": {
"exit-1": [
487.12151297071114,
153.62570711297067
],
"exit-2": [
485.201191631799,
197.15299079497902
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
533.209225,
184.990956
],
[
562.654152,
183.710741
]
]
},
"properties": {
"exit-1": [
559.4536167364015,
157.46634979079494
],
"exit-2": [
553.0525456066944,
202.91395481171543
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
754.046179,
184.990956
],
[
783.491106,
183.710741
]
]
},
"properties": {
"exit-1": [
770.0488569037655,
149.7850644351464
],
"exit-2": [
767.4884284518826,
200.99363347280328
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
784.131213,
183.070634
],
[
805.254748,
184.990956
]
]
},
"properties": {
"exit-1": [
803.9745338912131,
147.86474309623426
],
"exit-2": [
798.2135698744768,
199.07331213389116
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
944.798099,
183.070634
],
[
969.122169,
183.070634
]
]
},
"properties": {
"exit-1": [
954.3997054393302,
155.5460284518828
],
"exit-2": [
954.3997054393302,
206.7545974895397
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
972.962812,
185.631063
],
[
993.446239,
183.710741
]
]
},
"properties": {
"exit-1": [
983.2045255230123,
153.62570711297067
],
"exit-2": [
977.4435615062758,
199.07331213389116
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
1036.973523,
185.631063
],
[
1068.978879,
183.710741
]
]
},
"properties": {
"exit-1": [
1059.377271966527,
153.62570711297067
],
"exit-2": [
1052.9762008368198,
195.23266945606687
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
996.646775,
187.551384
],
[
997.286882,
222.757275
]
]
},
"properties": {
"exit-1": [
1024.8114878661086,
205.47438326359827
],
"exit-2": [
969.1221690376566,
205.47438326359827
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
282.287237,
183.070634
],
[
281.64713,
222.757275
]
]
},
"properties": {
"exit-1": [
305.9711999999999,
201.633740585774
],
"exit-2": [
257.96316652719656,
201.633740585774
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
1186.758587,
183.070634
],
[
1211.082658,
183.710741
]
]
},
"properties": {
"exit-1": [
1197.6404083682005,
155.5460284518828
],
"exit-2": [
1197.6404083682005,
195.23266945606687
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
1216.843622,
183.070634
],
[
1248.848977,
184.990956
]
]
},
"properties": {
"exit-1": [
1237.3270493723846,
156.8262426778242
],
"exit-2": [
1227.7254426778238,
204.83427615062755
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
1217.483729,
159.386671
],
[
1217.483729,
137.623029
]
]
},
"properties": {
"exit-1": [
1205.321693723849,
147.22463598326354
],
"exit-2": [
1246.9286560669452,
151.06527866108783
]
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
1397.993935,
182.430527
],
[
1373.669864,
184.350849
]
]
},
"properties": {