-
Notifications
You must be signed in to change notification settings - Fork 0
/
bacnet_gateway_requests.py
39 lines (27 loc) · 1.05 KB
/
bacnet_gateway_requests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import requests
import json
# Request present value and units for the supplied instance
def get_value_and_units( facility, instance, gateway_hostname, gateway_port ):
value = None
units = None
if str( instance ).isdigit() and int( instance ) > 0:
# Instance appears to be valid
# Set up request arguments
args = {
'facility': facility,
'instance': instance
}
# Issue request to HTTP service
url = 'http://' + gateway_hostname + ':' + str( gateway_port )
gateway_rsp = requests.post( url, data=args )
# Convert JSON response to Python dictionary
dc_rsp = json.loads( gateway_rsp.text )
# Extract BACnet response from the dictionary
dc_bn_rsp = dc_rsp['bacnet_response']
# Extract result from BACnet response
if ( dc_bn_rsp['success'] ):
dc_data = dc_bn_rsp['data']
if dc_data['success']:
value = dc_data['presentValue']
units = dc_data['units']
return value, units