คู่มือฉบับสมบูรณ์: เชื่อมต่อ SmartLogger3000A → ดึงข้อมูลพลังงานแสงอาทิตย์ → ส่งต่อผ่าน MQTT ครบจบในบทความเดียว
Huawei SmartLogger3000A คือ Data Concentrator สำหรับโรงไฟฟ้าโซลาร์ ทำหน้าที่รวบรวมข้อมูลจาก Inverter, มิเตอร์, และเซ็นเซอร์สภาพอากาศ แล้วเปิดช่องทางให้ระบบภายนอกเข้าถึงได้
ข้อมูลไหลจาก SmartLogger ผ่าน 3 ขั้นตอน: Poll → Transform → Publish
| Unit ID | อุปกรณ์ | หมายเหตุ |
|---|---|---|
0 | SmartLogger (Plant Level) | ข้อมูลรวมทั้ง plant — ใช้ตัวนี้เป็นหลัก |
1–247 | Inverter, Meter, EMI | อุปกรณ์แต่ละตัวที่ต่อพ่วงผ่าน RS485 |
ข้อมูลทางเทคนิคสำคัญของ SmartLogger3000A สำหรับการ integrate
| รายการ | รายละเอียด |
|---|---|
| Model Variants | A01EU, A03EU (MBUS/PLC), A01CN, A00GL, A01AU |
| Ethernet | WAN + LAN — 10/100/1000 Mbps (RJ45) |
| RS485 | 3 พอร์ต COM — Modbus-RTU / IEC 60870-5-103 |
| Modbus-TCP Port | 502 (ค่า default) |
| อุปกรณ์สูงสุด | 80 ตัว / logger (150 inverters ผ่าน MBUS บนรุ่น A03) |
| อุณหภูมิใช้งาน | -40°C ถึง +60°C |
| กินไฟ | 8W (ปกติ) / 15W (สูงสุด) |
| IP Rating | IP20 (ติดตั้งในตู้) |
Register ที่ใช้บ่อยที่สุดสำหรับ monitoring ระดับ Plant (Unit ID = 0)
| Register | Count | ชื่อ | หน่วย | Scale | Type |
|---|---|---|---|---|---|
32064 | 2 | Active Power (รวม plant) | kW | ×0.001 | I32 (signed) |
32066 | 2 | Reactive Power (รวม plant) | kVar | ×0.001 | I32 (signed) |
32078 | 2 | Daily Energy Yield | kWh | ×0.01 | U32 |
32080 | 2 | Monthly Energy Yield | kWh | ×0.01 | U32 |
32082 | 2 | Annual Energy Yield | kWh | ×0.01 | U32 |
32084 | 2 | Total Energy Yield (ตลอดอายุ) | kWh | ×0.01 | U32 |
| Register | Count | ชื่อ | หน่วย | Scale | Type |
|---|---|---|---|---|---|
32070 | 1 | Grid Frequency | Hz | ×0.01 | U16 |
32071 | 1 | Grid Voltage Phase A | V | ×0.1 | U16 |
32072 | 1 | Grid Voltage Phase B | V | ×0.1 | U16 |
32073 | 1 | Grid Voltage Phase C | V | ×0.1 | U16 |
32074 | 2 | Grid Current Phase A | A | ×0.01 | I32 (signed) |
32076 | 2 | Grid Current Phase B | A | ×0.01 | I32 (signed) |
32086 | 1 | Inverter Count (Online) | — | ×1 | U16 |
32089 | 1 | Plant Status | — | ×1 | U16 |
32091 | 1 | Internal Temperature | °C | ×0.1 | I16 (signed) |
ใช้ pymodbus เชื่อมต่อ SmartLogger ผ่าน Modbus-TCP แล้วอ่านค่า register
pip install pymodbus paho-mqtt
from pymodbus.client import ModbusTcpClient # ===== ตั้งค่า ===== LOGGER_IP = "192.168.1.100" # เปลี่ยนเป็น IP SmartLogger PORT = 502 UNIT_ID = 1 # SmartLogger aggregate # Register ที่จะอ่าน: (address, count, name, unit, scale, signed) REGISTERS = [ (32064, 2, "Active Power", "kW", 0.001, True), (32078, 2, "Daily Energy", "kWh", 0.01, False), (32084, 2, "Total Energy", "kWh", 0.01, False), (32070, 1, "Grid Frequency", "Hz", 0.01, False), (32071, 1, "Voltage Phase A", "V", 0.1, False), (32089, 1, "Plant Status", "", 1, False), ] def read_value(client, addr, count, signed): result = client.read_holding_registers(addr, count, slave=UNIT_ID) if result.isError(): return None if count == 1: val = result.registers[0] return val - 65536 if signed and val > 32767 else val raw = (result.registers[0] << 16) | result.registers[1] return raw - 4294967296 if signed and raw > 2147483647 else raw # ===== Main ===== client = ModbusTcpClient(LOGGER_IP, port=PORT, timeout=5) if not client.connect(): print("ERROR: ไม่สามารถเชื่อมต่อ SmartLogger ได้") exit(1) print(f"เชื่อมต่อ {LOGGER_IP}:{PORT} สำเร็จ\n") for addr, count, name, unit, scale, signed in REGISTERS: raw = read_value(client, addr, count, signed) if raw is not None: print(f" {name:20s} = {raw * scale:>12.2f} {unit}") else: print(f" {name:20s} = ERROR") client.close()
Active Power = 150.42 kWDaily Energy = 450.20 kWhGrid Frequency = 50.01 Hz
เมื่อดึงข้อมูลได้แล้ว ขั้นตอนต่อไปคือแปลงเป็น JSON แล้ว publish ไปยัง MQTT Broker
solar/{building_id}/data
# ตัวอย่าง:
solar/building_1/data
solar/building_2/data
{
"ts": "2026-06-15T10:30:00+07:00",
"building": "building_1",
"active_power_kw": 150.42,
"daily_energy_kwh": 450.20,
"total_energy_kwh": 125430.80,
"grid_voltage_a": 230.5,
"grid_voltage_b": 231.2,
"grid_voltage_c": 229.8,
"grid_frequency_hz": 50.01,
"inverter_online": 5,
"plant_status": 1
}
import json, time from datetime import datetime, timezone, timedelta from pymodbus.client import ModbusTcpClient import paho.mqtt.client as mqtt TZ = timezone(timedelta(hours=7)) # ===== Config ===== LOGGER_IP = "192.168.1.100" MQTT_BROKER = "broker.vekin.tech" BUILDING = "building_1" POLL_INTERVAL = 60 # วินาที # ===== Connect ===== mb = ModbusTcpClient(LOGGER_IP, port=502, timeout=5) mq = mqtt.Client(client_id=f"solar-{BUILDING}") mq.connect(MQTT_BROKER, 1883) mq.loop_start() mb.connect() while True: data = poll_all_registers(mb) # ฟังก์ชันจากตัวอย่างด้านบน data["ts"] = datetime.now(TZ).isoformat() data["building"] = BUILDING mq.publish(f"solar/{BUILDING}/data", json.dumps(data), qos=1) print(f"[{data['ts']}] {data['active_power_kw']} kW") time.sleep(POLL_INTERVAL)
นอกจาก Modbus แล้ว Huawei ยังมี Cloud API ให้ดึงข้อมูลผ่าน Internet ได้
| รายการ | รายละเอียด |
|---|---|
| Base URL | https://{region}.fusionsolar.huawei.com/thirdData/ |
| Authentication | POST /thirdData/login → ได้ xsrf-token จาก response header |
| Real-time Data | /thirdData/getStationRealKpi (ข้อมูลทุก 5 นาที) |
| Device List | /thirdData/getDevList → รายชื่อ Inverter, Meter ทั้งหมด |
| Rate Limit | Login 5 ครั้ง/10 นาที · Data ~1 call/5 นาที · 1 session เท่านั้น |
| ขอ Account | System → Company Management → Northbound Management → Add |
ปัญหาที่เจอบ่อยในการเชื่อมต่อ Modbus-TCP กับ SmartLogger และวิธีแก้ไข
1 (SmartLogger) แต่ถ้าต้องการข้อมูลเฉพาะ Inverter ตัวใดตัวหนึ่ง ต้องเปลี่ยนเป็น ID ของ Inverter นั้น (เช่น 2, 3, 4)