Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
董杰
/
SmartShelf-raspberry
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 68b0632a
由
刘韬
编写于
2026-03-18 09:56:10 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
优化API日志
1 个父辈
fcb25b7c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
116 行增加
和
43 行删除
smartshelf/app/routes.py
smartshelf/logs/smart.log
smartshelf/app/routes.py
查看文件 @
68b0632
...
...
@@ -589,83 +589,156 @@ def apiClose():
#posOn OK 或 posOn FAIL
@app.route
(
'/rest/api/v1/shelf/posOn'
,
methods
=
[
'Get'
])
def
rest_api_v1_shelf_posOn
():
"""
亮灯接口:
- 请求参数: posId=库位条码@颜色;库位条码@颜色
- 返回: 'posOn OK' / 'posOn FAIL'
"""
client_ip
=
request
.
remote_addr
posId
=
request
.
args
.
get
(
'posId'
,
''
)
.
strip
()
logging
.
info
(
f
'[posOn] request from {client_ip}, raw posId="{posId}"'
)
if
not
posId
:
logging
.
warning
(
'[posOn] missing posId parameter'
)
return
'posOn FAIL'
strip1
=
get_strip
(
SET_LED_CHANNEL
[
'1'
])
strip2
=
get_strip
(
SET_LED_CHANNEL
[
'2'
])
posId
=
request
.
args
.
get
(
'posId'
)
option_list
=
posId
.
split
(
';'
)
option_list
=
[
x
for
x
in
posId
.
split
(
';'
)
if
x
]
success
=
True
for
ol
in
option_list
:
ds
=
ol
.
split
(
'@'
)
posname
=
ds
[
0
]
color
=
ds
[
1
]
x
=
config_dict
.
get
(
posname
)
if
x
is
None
:
success
=
False
continue
channel
=
config_dict
.
get
(
posname
)
.
split
(
'@'
)[
1
]
led_index
=
int
(
config_dict
.
get
(
posname
)
.
split
(
'@'
)[
0
])
s
=
strip1
if
channel
==
'2'
:
s
=
strip2
s
.
setPixelColor
(
led_index
,
setcolor
(
color
))
try
:
if
'@'
not
in
ol
:
logging
.
warning
(
f
'[posOn] invalid format (missing @): "{ol}"'
)
success
=
False
continue
posname
,
color
=
ol
.
split
(
'@'
,
1
)
posname
=
posname
.
strip
()
color
=
color
.
strip
()
cfg
=
config_dict
.
get
(
posname
)
if
cfg
is
None
:
logging
.
warning
(
f
'[posOn] position not found in config: "{posname}"'
)
success
=
False
continue
led_index
=
int
(
cfg
.
split
(
'@'
)[
0
])
channel
=
cfg
.
split
(
'@'
)[
1
]
strip
=
strip1
if
channel
==
'2'
:
strip
=
strip2
strip
.
setPixelColor
(
led_index
,
setcolor
(
color
))
logging
.
info
(
f
'[posOn] turn on light pos="{posname}", color="{color}", channel={channel}, index={led_index}'
)
except
Exception
as
e
:
success
=
False
logging
.
error
(
f
'[posOn] error processing "{ol}": {e}'
)
strip1
.
show
()
strip2
.
show
()
if
success
:
logging
.
info
(
'[posOn] finished successfully'
)
return
'posOn OK'
else
:
logging
.
warning
(
'[posOn] finished with failure'
)
return
'posOn FAIL'
#/rest/api/v1/shelf/posOff?posId=1_3_1;1_3_2;1_3_4
#posOff OK 或 posOff FAIL
@app.route
(
'/rest/api/v1/shelf/posOff'
,
methods
=
[
'Get'
])
def
rest_api_v1_shelf_posOff
():
"""
灭灯接口:
- 请求参数: posId=库位条码;库位条码
- 返回: 'posOff OK' / 'posOff FAIL'
"""
client_ip
=
request
.
remote_addr
posId
=
request
.
args
.
get
(
'posId'
,
''
)
.
strip
()
logging
.
info
(
f
'[posOff] request from {client_ip}, raw posId="{posId}"'
)
if
not
posId
:
logging
.
warning
(
'[posOff] missing posId parameter'
)
return
'posOff FAIL'
strip1
=
get_strip
(
SET_LED_CHANNEL
[
'1'
])
strip2
=
get_strip
(
SET_LED_CHANNEL
[
'2'
])
posId
=
request
.
args
.
get
(
'posId'
)
option_list
=
posId
.
split
(
';'
)
option_list
=
[
x
for
x
in
posId
.
split
(
';'
)
if
x
]
success
=
True
for
posname
in
option_list
:
x
=
config_dict
.
get
(
posname
)
if
x
is
None
:
success
=
False
continue
channel
=
config_dict
.
get
(
posname
)
.
split
(
'@'
)[
1
]
led_index
=
int
(
config_dict
.
get
(
posname
)
.
split
(
'@'
)[
0
])
s
=
strip1
if
channel
==
'2'
:
s
=
strip2
s
.
setPixelColor
(
led_index
,
Color
(
0
,
0
,
0
))
try
:
posname
=
posname
.
strip
()
cfg
=
config_dict
.
get
(
posname
)
if
cfg
is
None
:
logging
.
warning
(
f
'[posOff] position not found in config: "{posname}"'
)
success
=
False
continue
led_index
=
int
(
cfg
.
split
(
'@'
)[
0
])
channel
=
cfg
.
split
(
'@'
)[
1
]
strip
=
strip1
if
channel
==
'2'
:
strip
=
strip2
strip
.
setPixelColor
(
led_index
,
Color
(
0
,
0
,
0
))
logging
.
info
(
f
'[posOff] turn off light pos="{posname}", channel={channel}, index={led_index}'
)
except
Exception
as
e
:
success
=
False
logging
.
error
(
f
'[posOff] error processing "{posname}": {e}'
)
strip1
.
show
()
strip2
.
show
()
if
success
:
logging
.
info
(
'[posOff] finished successfully'
)
return
'posOff OK'
else
:
logging
.
warning
(
'[posOff] finished with failure'
)
return
'posOff FAIL'
#/rest/api/v1/shelf/allPosOn
#allPosOn OK 或 allPosOn FAIL
@app.route
(
'/rest/api/v1/shelf/allPosOn'
,
methods
=
[
'Get'
])
def
rest_api_v1_shelf_allPosOn
():
logging
.
info
(
'开始打开所有灯'
)
for
pin
in
[
SET_LED_CHANNEL
[
'1'
],
SET_LED_CHANNEL
[
'2'
]]:
strip
=
get_strip
(
pin
)
for
i
in
range
(
0
,
strip
.
numPixels
()):
strip
.
setPixelColor
(
i
,
Color
(
255
,
255
,
255
))
strip
.
show
()
logging
.
info
(
'完成打开所有灯'
)
return
'allPosOn OK'
client_ip
=
request
.
remote_addr
logging
.
info
(
f
'[allPosOn] start turning on all lights, from {client_ip}'
)
try
:
for
pin
in
[
SET_LED_CHANNEL
[
'1'
],
SET_LED_CHANNEL
[
'2'
]]:
strip
=
get_strip
(
pin
)
for
i
in
range
(
0
,
strip
.
numPixels
()):
strip
.
setPixelColor
(
i
,
Color
(
255
,
255
,
255
))
strip
.
show
()
logging
.
info
(
'[allPosOn] finished turning on all lights'
)
return
'allPosOn OK'
except
Exception
as
e
:
logging
.
error
(
f
'[allPosOn] error: {e}'
)
return
'allPosOn FAIL'
#/rest/api/v1/shelf/allPosOff
#allPosOff OK allPosOff FAIL
@app.route
(
'/rest/api/v1/shelf/allPosOff'
,
methods
=
[
'Get'
])
def
rest_api_v1_shelf_allPosOff
():
logging
.
info
(
'开始关闭所有灯'
)
for
pin
in
[
SET_LED_CHANNEL
[
'1'
],
SET_LED_CHANNEL
[
'2'
]]:
strip
=
get_strip
(
pin
)
for
i
in
range
(
0
,
strip
.
numPixels
()):
strip
.
setPixelColor
(
i
,
Color
(
0
,
0
,
0
))
strip
.
show
()
logging
.
info
(
'完成关闭所有灯'
)
return
'allPosOff OK'
client_ip
=
request
.
remote_addr
logging
.
info
(
f
'[allPosOff] start turning off all lights, from {client_ip}'
)
try
:
for
pin
in
[
SET_LED_CHANNEL
[
'1'
],
SET_LED_CHANNEL
[
'2'
]]:
strip
=
get_strip
(
pin
)
for
i
in
range
(
0
,
strip
.
numPixels
()):
strip
.
setPixelColor
(
i
,
Color
(
0
,
0
,
0
))
strip
.
show
()
logging
.
info
(
'[allPosOff] finished turning off all lights'
)
return
'allPosOff OK'
except
Exception
as
e
:
logging
.
error
(
f
'[allPosOff] error: {e}'
)
return
'allPosOff FAIL'
@app.route
(
'/rest/api/v1/shelf/keepAlive'
)
def
rest_api_v1_shelf_keepAlive
():
return
'OK'
...
...
smartshelf/logs/smart.log
查看文件 @
68b0632
此文件的差异太大,无法显示。
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论