Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F66447588
restful_client.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jun 10, 14:37
Size
882 B
Mime Type
text/x-python
Expires
Wed, Jun 12, 14:37 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18223585
Attached To
R3852 EMS for Smart-Building
restful_client.py
View Options
from
conf_ems
import
*
import
bmsinterface.auxiliary.requests.api
as
requests
import
sys
def
get_bms_info
(
resource_type
=
'room'
,
resource_id
=
1
):
"""Returns the info for the given ID according to the docs in openBMS"""
geturl
=
'http://{0}:{1}/API/{2}/{3}'
.
format
(
OPENBMS_IP
,
OPENBMS_PORT
,
resource_type
,
resource_id
)
r
=
requests
.
get
(
geturl
)
# always check the return status code!
if
r
.
status_code
==
200
:
# Otherwise it means openBMS doesnt work
request_result
=
r
.
json
()
return
request_result
elif
r
.
status_code
==
404
and
r
.
content
:
# Server replied but not found the midid
print
(
'Failed to find in openBMS the {0}: {1}'
.
format
(
resource_type
,
resource_id
))
sys
.
exit
()
else
:
print
(
'Failed to connect to {0}:{1}, is openBMS running?'
.
format
(
OPENBMS_IP
,
OPENBMS_PORT
))
sys
.
exit
()
print
(
get_bms_info
())
Event Timeline
Log In to Comment