Python을 사용하여 oBIX 프로토콜을 통해 Niagara 데이터에 액세스하는 예
프로젝트는 Python을 사용하여 Niagara 소프트웨어의 데이터를 읽고 제어해야 하기 때문에 이 프로토콜의 Python 버전 패키지를 썼습니다. 여기에 발표되었습니다https://pypi.org/project/oBIX/
pip 설치를 사용하면 다음을 수행할 수 있습니다.
pip install oBIX
본고는 주로 Python을 사용하여 oBIX 프로토콜을 통해 나이아가라 소프트웨어의 점을 읽기, 쓰기 조작하는 것을 소개한다.1. 준비 작업
1. 나이아가라 소프트웨어에 oBIX 프로토콜을 설정하여 정상적으로 접근할 수 있도록 한다.
(1) Palette 검색 BIX, Obix Network를 Drivers에 추가
(2) Palette 검색baja, AuthenticationSchemes/WebServicesSchemes/의 HTTPBasicScheme를 Services/AuthenticationService/Authentication Schemes/
(3) UserServices에서 View를 마우스 오른쪽 버튼으로 클릭하면 AX User Manager에서 다음 사용자로 구성됩니다.
* 사용자 이름: oBIX
* 암호: oBIX.12345
* Authentication Schemes Name 선택: HTTPBasicScheme
* Admin 권한
2. Niagara에 새로 생성된 수치 형식의 읽기와 쓰기 가능한 점은:temp1이고 전체 경로는:/config/AHU/temp1/입니다. 다음에 접근합니다.
3.python의 oBIX 패키지 설치:
pip install oBIX
2. 빠른 시작
from oBIX.common import Point, DataType
from oBIX import Client
if __name__ == '__main__':
# ip, userName, password
# :
# port: , :8080
# https: https, :True
client = Client("127.0.0.1", "oBIX", "oBIX.12345")
#
point_path = "/config/AHU/temp1/"
#
point_value = client.read_point_value(point_path)
print("point value is {0}".format(point_value))
3. 기본 실례3.1 읽기 포인트
#
point_path = "/config/AHU/temp1/"
#
point_value = client.read_point_value(point_path)
print("point value is {0}".format(point_value))
#
#
# :name, val, status, display, href, in1, in2 ... in16, fallback, out
point_obj = client.read_point(point_path)
print("name is {0}".format(point_obj.name))
print("fallback is {0}".format(point_obj.fallback))
print("in10 is {0}".format(point_obj.in10))
#
point_in10_value = client.read_point_slot(point_path, "in10")
print("in10 is {0}".format(point_in10_value))
3.2 쓰기 포인트
#
point_path = "/config/AHU/temp1/"
# set
client.write_point(point_path, 15.2, DataType.real)
# set point auto
client.set_point_auto(point_path, DataType.real)
# override a point
client.override_point(point_path, 14, DataType.real)
# emergency override a point
client.emergency_override_point(point_path, 15, DataType.real)
# set a point emergency auto
client.set_point_emergency_auto(point_path, DataType.real)
4. 고급 어플리케이션4.1 기록 데이터 읽기
#
start_time = datetime.now(tz=timezone(timedelta(hours=8))) - timedelta(minutes=10)
#
end_time = datetime.now(tz=timezone(timedelta(hours=8)))
#
history = client.read_history("Station01", "OutDoorTemp", start_time, end_time)
#
limit_num = 1
history = client.read_history("Station01", "OutDoorTemp", start_time=start_time, limit=limit_num)
4.2 경고 데이터 읽기
#
start_time = datetime.now(tz=timezone(timedelta(hours=8))) - timedelta(minutes=10)
#
end_time = datetime.now(tz=timezone(timedelta(hours=8)))
#
alarms = client.read_alarms("Station01", "OutDoorTemp", start_time, end_time)
#
limit_num = 1
alarms = client.read_alarms("Station01", "OutDoorTemp", start_time=start_time, limit=limit_num)
4.3 감시점의 데이터 변화감시점의 데이터 변화 시 oBIX 프로토콜의 일부분.모니터링하려는 점을 추가한 다음 Niagara 중점의 값이 변경되면 해당 함수가 자동으로 트리거됩니다.
from oBIX.common import Point, DataType
from oBIX import Client
def init_watch():
global client, point_path
#
point_path_list = [point_path] #
result = client.add_watch_points(point_path_list)
client.watch_changed_handler.on_change += on_watch_changed
# Niagara ,
def on_watch_changed(points: [Point]):
for point in points:
val = point.val
print(f"on_watch_changed: {val}")
if __name__ == '__main__':
# ip, userName, password
# :
# port: , :8080
# https: https, :True
client = Client("127.0.0.1", "oBIX", "oBIX.12345")
#
point_path = "/config/AHU/temp1/"
init_watch()
client.start_watch()
while True:
i = 0
4.4 모든 점에 대한 정보 내보내기만약 한 항목에 대량의 디렉터리와 점이 있다면, 수동으로 하나씩 쓰는 것이 비교적 번거롭기 때문에, 여기에 점 정보를 내보내는 함수를 제공하였다.점의 정보를 파일에 저장한 후에 파일에서 점의 정보를 직접 읽으면 매우 편리하다.
#
export_result = client.export_points()
# folder_path [optional]: , : "/config/xxx/",
# export_file_name [optional]: , : "all_points.json"
# export_type [optional]:
# 0: JSON ,
# 1: JSON , ,
# 2: ,
export_result = client.export_points(folder_path="/config/AHU/", export_file_name="output.json", export_type=1)
이상은 Python을 사용하여 oBIX 프로토콜을 통해 나이아가라 데이터에 접근하는 예시의 상세한 내용입니다. 더 많은 Python이 oBIX 프로토콜을 통해 나이아가라 데이터에 접근하는 것에 관한 자료는 저희 기타 관련 글을 참고하세요!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
로마 숫자를 정수로 또는 그 반대로 변환그 중 하나는 로마 숫자를 정수로 변환하는 함수를 만드는 것이었고 두 번째는 그 반대를 수행하는 함수를 만드는 것이었습니다. 문자만 포함합니다'I', 'V', 'X', 'L', 'C', 'D', 'M' ; 문자열이 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.