EN
energyclient energyclient
  • LED Control System
  • Video Processor
  • XiaoHui Cloud
  • LCD Controller
  • Accessories
  • Solution

~upd~ | Energyclient

def _init_db(self): self.conn = sqlite3.connect("energy_cache.db") self.conn.execute(""" CREATE TABLE IF NOT EXISTS readings ( ts TEXT PRIMARY KEY, power_w REAL, cumulative_wh REAL ) """)

"timestamp": "2025-03-15T10:00:00Z", "device_id": "meter_001", "measurements": "power_w": 1243.5, "energy_wh_cumulative": 1203400, "voltage_v": 239.2, "current_a": 5.2, "frequency_hz": 50.02 , "tariff": "off_peak"

def fetch_latest(self): resp = self.session.get(f"self.api_root/meters/self.meter_id/reading") resp.raise_for_status() data = resp.json() # Cache it self.conn.execute( "INSERT OR REPLACE INTO readings (ts, power_w, cumulative_wh) VALUES (?, ?, ?)", (datetime.now(timezone.utc).isoformat(), data["power_w"], data["cumulative_wh"]) ) self.conn.commit() return data

def control_load(self, state: bool): """Turn load on/off (demand response)""" resp = self.session.post( f"self.api_root/meters/self.meter_id/control", json="load_control": state ) return resp.status_code == 200

from oauthlib.oauth2 import BackendApplicationClient from requests_oauthlib import OAuth2Session client = BackendApplicationClient(client_id=CLIENT_ID) oauth = OAuth2Session(client=client) token = oauth.fetch_token(token_url=TOKEN_URL, client_secret=CLIENT_SECRET) Typical core entities:

import requests import sqlite3 import time from dataclasses import dataclass from datetime import datetime, timezone @dataclass class EnergyClient: api_root: str meter_id: str token: str

def __post_init__(self): self._init_db() self.session = requests.Session() self.session.headers.update("Authorization": f"Bearer self.token")

def close(self): self.conn.close() | Problem | Strategy | |---------|----------| | Network failure | Retry with backoff (3–5 attempts) | | Rate limiting | Parse Retry-After header, queue commands | | Invalid token | Re‑authenticate automatically once | | Data gaps | Interpolate or flag missing samples | | Meter offline | Cache commands; apply when reconnected |

HD-R716/R712/R708/R732/R3210

def _init_db(self): self.conn = sqlite3.connect("energy_cache.db") self.conn.execute(""" CREATE TABLE IF NOT EXISTS readings ( ts TEXT PRIMARY KEY, power_w REAL, cumulative_wh REAL ) """)

"timestamp": "2025-03-15T10:00:00Z", "device_id": "meter_001", "measurements": "power_w": 1243.5, "energy_wh_cumulative": 1203400, "voltage_v": 239.2, "current_a": 5.2, "frequency_hz": 50.02 , "tariff": "off_peak"

def fetch_latest(self): resp = self.session.get(f"self.api_root/meters/self.meter_id/reading") resp.raise_for_status() data = resp.json() # Cache it self.conn.execute( "INSERT OR REPLACE INTO readings (ts, power_w, cumulative_wh) VALUES (?, ?, ?)", (datetime.now(timezone.utc).isoformat(), data["power_w"], data["cumulative_wh"]) ) self.conn.commit() return data

def control_load(self, state: bool): """Turn load on/off (demand response)""" resp = self.session.post( f"self.api_root/meters/self.meter_id/control", json="load_control": state ) return resp.status_code == 200

from oauthlib.oauth2 import BackendApplicationClient from requests_oauthlib import OAuth2Session client = BackendApplicationClient(client_id=CLIENT_ID) oauth = OAuth2Session(client=client) token = oauth.fetch_token(token_url=TOKEN_URL, client_secret=CLIENT_SECRET) Typical core entities:

import requests import sqlite3 import time from dataclasses import dataclass from datetime import datetime, timezone @dataclass class EnergyClient: api_root: str meter_id: str token: str

def __post_init__(self): self._init_db() self.session = requests.Session() self.session.headers.update("Authorization": f"Bearer self.token")

def close(self): self.conn.close() | Problem | Strategy | |---------|----------| | Network failure | Retry with backoff (3–5 attempts) | | Rate limiting | Parse Retry-After header, queue commands | | Invalid token | Re‑authenticate automatically once | | Data gaps | Interpolate or flag missing samples | | Meter offline | Cache commands; apply when reconnected |

  • energyclient
    E-mail To Us
    sales@huidu.cn
  • energyclient
    We are Here
    Headquarters: 17th and 18th Floors, No. 196, Tangtou Avenue, Shiyan Street, Bao'an District, Shenzhen;
    Supply Chain Center: 4th Floor, Building 10, Hongfa Industrial Park, Tangtou Avenue, Shiyan Town, Bao'an District, Shenzhen;
    Hunan Branch: 402-1, Building 15, Xinggong International Industrial Park, Yuelu District, Changsha City, Hunan Province.
energyclient