Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-WIC-Opencpc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenXG
OpenXG-WIC-Opencpc
Commits
4697b8ec
Commit
4697b8ec
authored
Apr 21, 2018
by
joliu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复由于启动太快导致数据库没有建立而运行出错的bug
parent
321b8085
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
111 additions
and
10 deletions
+111
-10
hfv/getData.py
hfv/getData.py
+61
-8
hfv/workProcess.py
hfv/workProcess.py
+50
-2
No files found.
hfv/getData.py
View file @
4697b8ec
from
controllMatrix
import
*
from
listenSer
import
sendBySocket
import
os
import
time
import
socket
# 发送控制指令到传感器设备,参数cmd,控制命令
def
sendCommandToDevice
(
cmd
):
response
=
'error'
# 通过容器的环境变量HOST获取绑定传感器的IP地址
ip
,
port
=
os
.
getenv
(
'HOST'
),
8085
try
:
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
except
socket
.
error
as
err_msg
:
print
(
"Error creating socket:%s"
%
err_msg
)
s
.
close
()
return
(
-
1
,
err_msg
)
try
:
s
.
connect
((
ip
,
port
))
except
socket
.
gaierror
as
err_msg
:
print
(
'Address-related error connecting to server: %s'
%
err_msg
)
s
.
close
()
return
(
-
1
,
err_msg
)
print
(
updateDeviceTask
(
'25'
,
'192.168.12.1'
,
25
))
try
:
s
.
sendall
(
cmd
.
encode
())
except
socket
.
error
as
err_msg
:
print
(
"Error sending data: %s"
%
err_msg
)
s
.
close
()
return
(
-
1
,
err_msg
)
try
:
response
=
s
.
recv
(
1024
).
decode
()
except
socket
.
error
as
err_msg
:
print
(
'Error receiving data: %s'
%
err_msg
)
s
.
close
()
return
(
-
1
,
err_msg
)
s
.
close
()
# 程序运行正常,返回传感器传递的值
return
(
1
,
str
(
response
))
while
True
:
if
getDeviceTask
()[
0
]
==
-
1
:
ctime
=
5
(
status
,
output
)
=
getDeviceTask
()
if
status
==
-
1
:
print
(
output
)
continue
(
id
,
data
,
dstIP
,
ctime
)
=
getDeviceTask
()[
1
]
print
(
data
)
if
data
==
25
:
print
(
'success'
)
for
data
in
getDeviceTask
()[
1
]:
(
id
,
data
,
dstIP
,
ctime
)
=
data
(
ip
,
port
)
=
dstIP
.
split
(
':'
)
print
(
data
)
(
status
,
deviceValue
)
=
sendCommandToDevice
(
'on'
)
if
status
==
-
1
:
print
(
deviceValue
)
continue
time
.
sleep
(
2
)
try
:
deviceValue
=
float
(
deviceValue
.
split
(
'&'
)[
0
])
except
Exception
as
err
:
print
(
err
,
deviceValue
)
if
deviceValue
>
data
:
print
(
'1'
)
msg
=
'device&%s&1'
%
os
.
getenv
(
'HOSTNAME'
)
else
:
print
(
'0'
)
msg
=
'device&%s&0'
%
os
.
getenv
(
'HOSTNAME'
)
(
status
,
recvdata
)
=
sendBySocket
(
ip
,
int
(
port
),
method
)
time
.
sleep
(
ctime
)
hfv/workProcess.py
View file @
4697b8ec
from
controllMatrix
import
*
from
resolveMatrix
import
runTask
import
os
# 发送控制指令到传感器设备,参数cmd,控制命令
def
sendCommandToDevice
(
cmd
):
response
=
'error'
# 通过容器的环境变量HOST获取绑定传感器的IP地址
ip
,
port
=
os
.
getenv
(
'HOST'
),
8085
try
:
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
except
socket
.
error
as
err_msg
:
print
(
"Error creating socket:%s"
%
err_msg
)
s
.
close
()
return
(
-
1
,
err_msg
)
try
:
s
.
connect
((
ip
,
port
))
except
socket
.
gaierror
as
err_msg
:
print
(
'Address-related error connecting to server: %s'
%
err_msg
)
s
.
close
()
return
(
-
1
,
err_msg
)
while
True
:
try
:
s
.
sendall
(
cmd
.
encode
())
except
socket
.
error
as
err_msg
:
print
(
"Error sending data: %s"
%
err_msg
)
s
.
close
()
return
(
-
1
,
err_msg
)
try
:
response
=
s
.
recv
(
1024
).
decode
()
except
socket
.
error
as
err_msg
:
print
(
'Error receiving data: %s'
%
err_msg
)
s
.
close
()
return
(
-
1
,
err_msg
)
s
.
close
()
# 程序运行正常,返回传感器传递的值
return
(
1
,
str
(
response
))
if
__name__
==
'__main__'
:
time
.
sleep
(
10
)
while
True
:
(
status
,
output
)
=
runTask
()
if
status
==
-
1
:
print
(
output
)
time
.
sleep
(
20
)
continue
else
:
if
output
==
1
:
msg
=
'on'
print
(
'on'
)
else
:
msg
=
'off'
print
(
'off'
)
print
(
sendCommandToDevice
(
msg
))
ctime
=
getCircleTime
()
print
(
runTask
())
time
.
sleep
(
ctime
)
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