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
ceec5053
Commit
ceec5053
authored
Sep 30, 2019
by
簡碩辰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete run.py
parent
9cc95b1c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
60 deletions
+0
-60
run.py
dvr/iot/run.py
+0
-60
No files found.
dvr/iot/run.py
deleted
100644 → 0
View file @
9cc95b1c
import
paho.mqtt.client
as
mqtt
,
os
,
json
,
requests
def
on_connect
(
client
,
userdata
,
flags
,
rc
):
# client: the client instance for this callback
# userdata: the private user data as set in Client()
# flags: response flags sent by the broker
# rc: the connection result
client
.
subscribe
(
"dvr/#"
)
# DVR
def
on_message
(
client
,
userdata
,
msg
):
payload
=
json
.
loads
(
str
(
msg
.
payload
.
decode
()))
host
=
os
.
getenv
(
"API_HOST"
)
or
"192.168.5.217"
port
=
os
.
getenv
(
"API_PORT"
)
or
"8001"
data
=
{
'account'
:
os
.
getenv
(
"API_USER"
)
or
"admin"
,
'password'
:
os
.
getenv
(
"API_PSWD"
)
or
"qL8oAGg8"
,
}
user
=
requests
.
post
(
'http://{0}:{1}/login'
.
format
(
host
,
port
),
data
=
data
)
if
user
.
status_code
==
requests
.
codes
.
ok
:
user
=
json
.
loads
(
user
.
text
)
if
'dvr'
in
msg
.
topic
and
payload
[
'status'
]
==
1
:
url
=
'http://{0}:{1}/{2}/insert/stream'
.
format
(
host
,
port
,
user
[
'EndPoint'
])
headers
=
{
'Authorization'
:
'Bearer {0}'
.
format
(
user
[
'AccessToken'
])
}
data
=
{
'host'
:
payload
[
'host'
],
'name'
:
payload
[
'name'
],
'ch'
:
payload
[
'ch'
],
}
stream
=
requests
.
post
(
url
,
headers
=
headers
,
data
=
data
)
stream
=
json
.
loads
(
stream
.
text
)
print
(
stream
)
else
:
print
(
"Do Something"
)
else
:
print
(
user
.
status_code
)
host
=
os
.
getenv
(
"MQTT_HOST"
)
or
"192.168.5.217"
port
=
os
.
getenv
(
"MQTT_PORT"
)
or
"1883"
client
=
mqtt
.
Client
()
client
.
on_connect
=
on_connect
client
.
on_message
=
on_message
client
.
connect
(
host
,
int
(
port
),
3600
)
client
.
loop_forever
()
\ 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