Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
RaspberryNode
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
簡碩辰
RaspberryNode
Commits
32e5694d
Commit
32e5694d
authored
Oct 03, 2019
by
簡碩辰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update run.py
parent
2b42ecaa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
8 deletions
+6
-8
run.py
dvr/ffmpeg/run.py
+6
-8
No files found.
dvr/ffmpeg/run.py
View file @
32e5694d
import
json
,
os
,
socket
,
time
,
datetime
,
pytz
,
subprocess
as
SP
import
json
,
os
,
socket
,
time
,
datetime
,
pytz
,
subprocess
as
SP
from
paho.mqtt.client
import
Client
as
MQTT
from
paho.mqtt.client
import
Client
as
MQTT
def
TryConnect
(
host
,
port
):
def
TryConnect
(
tag
,
host
,
port
):
now
=
datetime
.
datetime
.
now
(
tz
=
pytz
.
timezone
(
'Asia/Taipei'
))
now
=
datetime
.
datetime
.
now
(
tz
=
pytz
.
timezone
(
'Asia/Taipei'
))
now
=
now
.
strftime
(
'
%
Y/
%
m/
%
d
%
H:
%
M:
%
S'
)
now
=
now
.
strftime
(
'
%
Y/
%
m/
%
d
%
H:
%
M:
%
S'
)
...
@@ -12,11 +12,13 @@ def TryConnect(host, port):
...
@@ -12,11 +12,13 @@ def TryConnect(host, port):
s
.
shutdown
(
socket
.
SHUT_RDWR
)
s
.
shutdown
(
socket
.
SHUT_RDWR
)
print
(
"[{0}][{1}][{2}:{3}]: Connected"
.
format
(
now
,
tag
,
host
,
port
))
return
True
return
True
except
ConnectionRefusedError
:
except
ConnectionRefusedError
:
print
(
"[{0}][
Connect][{1}:{2}]: is refused"
.
format
(
now
,
host
,
port
))
print
(
"[{0}][
{1}][{2}:{3}]: Connection Refused Error"
.
format
(
now
,
tag
,
host
,
port
))
except
:
except
:
print
(
"[{0}][
Connect][{1}:{2}]: unknown error"
.
format
(
now
,
host
,
port
))
print
(
"[{0}][
{1}][{2}:{3}]: Unknown Error"
.
format
(
now
,
tag
,
host
,
port
))
return
False
return
False
user
=
os
.
getenv
(
"DVR_USER"
)
user
=
os
.
getenv
(
"DVR_USER"
)
...
@@ -38,8 +40,6 @@ while True:
...
@@ -38,8 +40,6 @@ while True:
port
=
os
.
getenv
(
"MQTT_PORT"
)
port
=
os
.
getenv
(
"MQTT_PORT"
)
print
(
"Connect to MQTT"
)
if
TryConnect
(
host
,
port
):
# 測試連線到 MQTT
if
TryConnect
(
host
,
port
):
# 測試連線到 MQTT
client
=
MQTT
()
client
=
MQTT
()
...
@@ -115,6 +115,4 @@ while True:
...
@@ -115,6 +115,4 @@ while True:
payload
[
'msg'
]
=
"Connect to EasyDarwin is refused."
payload
[
'msg'
]
=
"Connect to EasyDarwin is refused."
client
.
publish
(
topic
,
json
.
dumps
(
payload
),
1
)
client
.
publish
(
topic
,
json
.
dumps
(
payload
),
1
)
else
:
\ No newline at end of file
print
(
"Connect to MQTT is refused."
)
\ No newline at end of file
Write
Preview
Markdown
is supported
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