Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Astreos_Arduino
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hicham Brahimi
Astreos_Arduino
Commits
896d5b7b
Commit
896d5b7b
authored
6 years ago
by
hichbra
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of
https://git.litislab.fr/hicham.brahimi/astreos_arduino
parents
43d98161
3569c5fa
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Raspberry/Module_4G/processusEnvoi4G.py
+105
-10
105 additions, 10 deletions
Raspberry/Module_4G/processusEnvoi4G.py
Raspberry/Module_4G/server.py
+5
-1
5 additions, 1 deletion
Raspberry/Module_4G/server.py
with
110 additions
and
11 deletions
Raspberry/Module_4G/processusEnvoi4G.py
100644 → 100755
+
105
−
10
View file @
896d5b7b
#Python 3.5
# A executer avec SUDO
# PYTHON 3.5+
import
subprocess
import
time
import
socket
import
sys
import
os
import
os.path
from
datetime
import
datetime
import
psutil
def
check_pid
(
pid
):
# Verifie l'existence d'un pid
if
psutil
.
pid_exists
(
pid
):
p
=
psutil
.
Process
(
pid
)
if
p
.
status
()
!=
psutil
.
STATUS_ZOMBIE
:
return
True
return
False
# Verifie qu'il n'y a pas d'autres processus d'envoi en verifiant le fichier lock
if
os
.
path
.
isfile
(
"
./.lockprocess
"
):
print
(
"
Locked
"
)
while
os
.
path
.
isfile
(
"
./.lockprocess
"
):
time
.
sleep
(
1
)
# Creer un nouveau fichier lock pour verrouiller les autres processus
if
not
os
.
path
.
isfile
(
"
./.lockprocess
"
):
open
(
"
.lockprocess
"
,
"
a
"
).
close
()
subprocess
.
Popen
([
"
chmod
"
,
"
777
"
,
"
.lockprocess
"
])
else
:
# Si un processus s'est activée entre la 1ere boucle et la condition
while
os
.
path
.
isfile
(
"
./.lockprocess
"
):
time
.
sleep
(
1
)
open
(
"
.lockprocess
"
,
"
a
"
).
close
()
subprocess
.
Popen
([
"
chmod
"
,
"
777
"
,
"
.lockprocess
"
])
IP_PC
=
"
91.162.19.165
"
PORT
=
20000
nomFichier
=
sys
.
argv
[
1
]
print
(
nomFichier
)
sock
=
socket
.
socket
()
sock
.
connect
((
'
localhost
'
,
3400
))
print
(
"
Debut processus envoi
"
)
with
open
(
nomFichier
,
'
rb
'
)
as
f
:
print
(
"
SEND
"
)
sock
.
sendfile
(
f
,
0
)
sock
.
close
()
print
(
"
Fin processus emvoi
"
)
chemin
=
nomFichier
.
split
(
"
/
"
)
log
=
open
(
"
log/
"
+
chemin
[
1
]
+
"
.log
"
,
"
w
"
)
f
=
None
try
:
pid
=
subprocess
.
Popen
([
"
wvdial
"
])
print
(
"
============ WVDIAL LANCE ==============
"
)
print
(
"
PID =
"
,
pid
.
pid
)
time
.
sleep
(
10
)
print
(
"
============ CORRECTION ROUTE ==============
"
)
subprocess
.
Popen
([
"
route
"
,
"
add
"
,
"
default
"
,
"
dev
"
,
"
ppp0
"
])
# Corrige la 4G au demarrage du raspberry
print
(
"
============ CONNEXION ==============
"
)
server
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
server
.
connect
((
IP_PC
,
PORT
))
f
=
open
(
nomFichier
,
"
rb
"
)
print
(
"
======== CALCUL TAILLE ========
"
)
taille
=
os
.
path
.
getsize
(
nomFichier
)
print
(
"
============ ENVOI FICHIER ==============
"
)
totalEnvoyee
=
0
with
open
(
nomFichier
,
"
rb
"
)
as
f
:
totalEnvoyee
+=
server
.
sendfile
(
f
,
0
)
print
(
"
=> chunk %d/%d
"
%
(
totalEnvoyee
,
taille
))
log
.
write
(
"
=> chunk
"
+
str
(
totalEnvoyee
)
+
"
/
"
+
str
(
taille
)
+
"
\n
"
)
server
.
close
()
except
KeyboardInterrupt
:
print
(
"
============= LIBERATION =============
"
)
os
.
remove
(
"
.lockprocess
"
)
print
(
"
============ WVDIAL ARRET ==============
"
)
subprocess
.
Popen
([
"
kill
"
,
"
-1
"
,
pid
.
pid
])
except
Exception
as
ex
:
print
(
"
Exception, voir log
"
)
log
.
write
(
str
(
datetime
.
now
())
+
"
=> Exception
"
+
str
(
type
(
ex
))
+
"
(
"
+
str
(
ex
.
args
)
+
"
)
\n
"
)
time
.
sleep
(
1
)
print
(
"
============= LIBERATION =============
"
)
os
.
remove
(
"
.lockprocess
"
)
print
(
"
============ WVDIAL ARRET ==============
"
)
subprocess
.
Popen
([
"
kill
"
,
"
-1
"
,
pid
.
pid
])
print
(
"
================ FIN =================
"
)
if
f
is
not
None
:
f
.
close
()
server
.
close
()
log
.
close
()
if
check_pid
(
pid
.
pid
):
print
(
"
============ WVDIAL ARRET ==============
"
)
subprocess
.
Popen
([
"
kill
"
,
"
-1
"
,
str
(
pid
.
pid
)])
time
.
sleep
(
1
)
if
os
.
path
.
isfile
(
"
./.lockprocess
"
):
print
(
"
=========== LIBERATION ============
"
)
os
.
remove
(
"
.lockprocess
"
)
This diff is collapsed.
Click to expand it.
Raspberry/Module_4G/server.py
+
5
−
1
View file @
896d5b7b
# PYTHON 3.5+
import
socket
import
sys
import
time
from
datetime
import
datetime
CHUNK_SIZE
=
2048
PORT
=
12345
log
=
open
(
"
log.txt
"
,
"
w
"
)
file
=
None
...
...
@@ -11,7 +13,7 @@ while True:
try
:
print
(
"
Attente Client
"
)
server
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
server
.
bind
((
""
,
12345
))
server
.
bind
((
""
,
PORT
))
server
.
listen
(
10
)
client
,
addr
=
server
.
accept
()
...
...
@@ -31,6 +33,8 @@ while True:
file
.
close
()
client
.
close
()
server
.
close
()
time
.
sleep
(
1
)
# Laisse le temps au port de se liberer
break
print
(
"
-> chunk
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment