이 라이브러리는 Firmare 버전 1.7.14 이하에서만 작동합니다.
최신 펌웨어 버전에서는 Eon이 로컬 API를 비활성화하고 이 라이브러리를 더 이상 사용하지 않게 만들었습니다. Eon에게 큰 감사를 드립니다! ?
이슈 #1에서 더 읽어보세요
안녕하세요, 환영합니다! 이 라이브러리를 즐기고 내 작업을 지원하려면 아래 버튼을 클릭하세요. 소프트웨어 개발자로서 많은 커피를 소비한다는 사실을 알고 계시나요?
말할 필요도 없이 이는 전적으로 자발적인 것입니다.
Python 3으로 작성된 E.ON Elna 내장 API용 간단한 라이브러리입니다. Elna는 RJ12 커넥터를 사용하여 전력량계의 HAN(Home Area Network) 포트에 연결되는 스마트 전력량계 장치입니다.
이 라이브러리는 Elna 장치 내부에 내장된 API를 사용하여 장치 자체에서 직접 전력 소비 및/또는 생산 에 대한 정보를 수집합니다.
Elna는 Net2Grid의 하드웨어를 기반으로 하므로 Net2Grid 제품군의 더 많은 장치와도 호환될 수 있습니다. 어떤 피드백이라도 환영합니다.
다음은 장치에서 얻을 수 있는 정보를 보여주는 작은 명령줄 데모 애플리케이션입니다.
여기에서 데모의 소스 코드를 확인하세요: smartmeter-demo.py.
이것은 잘 알려진 CLI 애플리케이션과 많은 유사성을 지닌 보다 실제적인 데모 애플리케이션입니다. 순간 소비 전력(mpc)을 확인하여 콘솔에 출력합니다. CTRL+C를 누르면 계산된 최소, 최대 및 평균 전력 소비량과 Elna로 전송된 패킷의 왕복 시간 등이 표시됩니다.
소스 코드는 powerping-demo.py에서 확인할 수 있습니다.
가상 환경을 설정합니다.
virtualenv venv
source venv/bin/activate
pip
사용하여 최신 버전을 설치합니다.
pip install elnasmartmeter
라이브러리를 이용하기 위해서는 엘나 기기의 IP 주소를 알아야 합니다. 라우터의 DHCP 서버(또는 DHCP 서버를 실행하는 모든 곳)에서 찾을 수 있습니다. Elna의 MAC 주소는 장치 뒷면에 인쇄되어 있습니다.
from elna import smartmeter
# Connect the library to the Elna device
meter = smartmeter . Connect ( '192.168.0.10' )
# Get general information
info = meter . get_info ()
# Get power readings
electricity = meter . get_electricity ()
# Get WLAN information
wlan = meter . get_wlan_info ()
귀하 가구의 전력 소비/생산량을 가져오는 것만큼 간단합니다. 잠시 후 info
및 electricity
객체를 통해 정보에 접근하는 방법을 살펴보겠습니다.
라이브러리에서 호출할 수 있는 모든 메서드는 실패 시 예외를 발생시킵니다. 전체 예외 목록은 여기에서 확인할 수 있습니다.
from elna import smartmeter
from elna . exceptions import *
...
try :
info = meter . get_info ()
except NewConnectionError as e :
print ( e )
라이브러리의 다양한 엔터티를 나타내는 객체는 해당 속성을 쉽게 검사할 수 있도록 print()
메서드를 사용하여 출력할 수 있습니다.
예를 들어, Information
객체를 print()
메서드에 전달하여 해당 속성을 출력할 수 있습니다.
print ( info )
# Output: <class 'elna.classes.Information'>: {'id': '01ab:0200:00cd:03ef', 'manufacturer': 'NET2GRID', 'model': 'SBWF4602', 'firmware': '1.7.14', 'hardware': 1, 'batch': 'HMX-P0D-123456'}
Information
, Electricity
, Power
및 WLANInformation
등 라이브러리의 모든 클래스에도 동일하게 적용됩니다.
이 라이브러리로 가져올 수 있는 데이터에는 일반 장치 Information
와 Power
통계의 두 가지가 있습니다.
일반적인 장치 정보를 얻으려면 get_info()
메서드를 호출하면 됩니다.
info = meter . get_info ()
클래스 속성을 통해 값에 액세스합니다.
info . id # Returns the device ID : '01ab:0200:00cd:03ef' (for example).
info . manufacturer # Returns the manufacturer : 'NET2GRID'
info . model # Returns the model : 'SBWF4602'
info . firmware # Returns the firmware version : '1.7.14'
info . hardware # Returns the hardware version : 1
info . batch # Returns the batch number : 'HMX-P0D-123456'
전력 판독값을 얻으려면 get_electricity()
메서드를 호출합니다. Elna 장치에서 수집된 정보는 하위 클래스로 나누어져 있기 때문에 이러한 판독값은 좀 더 복잡하지만 그렇게 복잡하지는 않습니다.
electricity = meter . get_electricity ()
현재 전력 소비를 얻으십시오:
electricity . now . key # Returns the string : 'now'
electricity . now . value # Returns the power : 453 (for example).
electricity . now . unit # Returns the unit : 'W' (as in Watt)
electricity . now . timestamp # Returns a timestamp : '2022-12-24 13:37:00'
해당 기간의 최소 전력 소비를 얻으십시오.
electricity . minimum . key # Returns the string : 'minimum'
electricity . minimum . value # Returns the power : 202 (for example).
electricity . minimum . unit # Returns the unit : 'W' (as in Watt)
electricity . minimum . timestamp # Returns a timestamp : '2022-12-13 13:37:00'
해당 기간의 최대 전력 소비를 얻으십시오.
electricity . maximum . key # Returns the string : 'maximum'
electricity . maximum . value # Returns the power : 14320 (for example).
electricity . maximum . unit # Returns the unit : 'W' (as in Watt)
electricity . maximum . timestamp # Returns a timestamp : '2022-12-31 13:37:00'
최소값 과 최대 값이 기록된 기간(기간)은 알 수 없습니다.
수입된 힘을 얻으십시오. 이것은 가구 에 들어오는 총 전력입니다.
electricity . imported . key # Returns the string : 'imported'
electricity . imported . value # Returns the power : 12345678 (for example).
electricity . imported . unit # Returns the unit : 'Wh' (as in Watt hours)
electricity . imported . timestamp # Returns a timestamp : '2022-12-31 13:37:00'
수출된 힘을 얻으십시오. 이는 가구 에서 나오는 총 전력입니다.
electricity . exported . key # Returns the string : 'exported'
electricity . exported . value # Returns the power : 87654321 (for example).
electricity . exported . unit # Returns the unit : 'Wh' (as in Watt hours)
electricity . exported . timestamp # Returns a timestamp : '2022-12-31 13:37:00'
상단의 스마트미터 데모를 확인하여 사용해 보세요.
get_wlan_info()
메소드를 호출하여 장치의 WLAN 정보를 얻을 수도 있습니다. 장치는 WiFi 네트워크에 연결되었는지 여부에 따라 무선 클라이언트(스테이션)와 액세스 포인트(AP) 역할을 모두 수행할 수 있습니다.
wlan = meter . get_wlan_info ()
객체의 클래스 속성을 통해 WLAN 정보에 액세스합니다.
wlan . mode # Returns the current WLAN mode
wlan . ap_ssid # Returns the Access Point SSID
wlan . ap_key # Returns the Access Point Password
wlan . client_ssid # Returns the SSID of the AP Elna is connected to
wlan . join_status # Returns the number of clients joined to the Elna AP
wlan . mac # Returns the MAC address currently in use
wlan . ip # Returns the IP address
wlan . subnet # Returns the Subnet mask
wlan . gateway # Returns the Default gateway
wlan . dns # Returns the Primary DNS server
wlan . dnsalt # Returns the Secondary DNS server
wlan . n2g_id # Returns the Net2Grid ID number
wlan . sta_mac # Returns the MAC address of the WLAN Station
wlan . ap_mac # Returns the MAC address of the Access Point
wlan . eth_mac # Returns the Ethernet MAC address (?)
참고: 위의 WLAN 속성 다음에 나오는 설명은 추정된 추측입니다.
이 저장소의 제품 이름, 상표 및 등록 상표는 해당 소유자의 자산이며 작성자는 식별 목적으로만 사용됩니다. 이러한 이름, 상표 및 브랜드의 사용은 보증이나 제휴를 의미하지 않습니다.