Skip to content

Commit

Permalink
Merge pull request #38 from bolliy/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
bolliy authored Jan 24, 2024
2 parents 719f8da + c85e143 commit 33ad62c
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 209 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@

Read register data from Huawei SUN2000 inverter and LUNA2000 battery using Modbus TCP.

Feel free to follow the discussions in the [iobroker forum](https://forum.iobroker.net/topic/71768/test-adapter-sun2000-v0-1-x-huawei-wechselrichter)

Modbus interface definition (Issue 5, 2023-02-16):
https://forum.iobroker.net/assets/uploads/files/1699119419919-solar-inverter-modbus-interface-definitions-v5.pdf

## Inspiration

The development of this adapter was inspired by discussions from the forum thread https://forum.iobroker.net/topic/53005/huawei-sun2000-iobroker-via-js-script-funktioniert and the iobroker javascript https://github.com/ChrisBCH/SunLuna2000_iobroker.

## Supported hardware
Expand All @@ -31,7 +35,7 @@ The development of this adapter was inspired by discussions from the forum threa
## Feature list

* Maximum 5 inverters (master/slave) can be processed, each with a battery module (max. 30kWh).
* Live data such as input power, output power, charging/discharging power and the grid consumption are read out at a fixed interval.
* Real-time values such as input power, output power, charging/discharging power and the grid consumption are read out at a fixed interval.
* States are only written for changed data from the inverter. This relieves the burden on the iobroker instance.
* The states “inputPower” or “activePower” in the “collected” path can be monitored with a “was updated” trigger element. Because these states are always written within the set interval.

Expand Down Expand Up @@ -63,6 +67,13 @@ If you use two inverters, then connect to the second inverter and read the commu
Placeholder for the next version (at the beginning of the line):
### **WORK IN PROGRESS**
-->
### **WORK IN PROGRESS**
* changes from requirements [Add sun2000 to latest](https://github.com/ioBroker/ioBroker.repositories/pull/3219)
* improve error handling (#34)
* add simple optimizer info
* Riemann sum of input power with energy loss for new state `dailySolarYield`
* try to recreate the `yield today` from the fusion portal

### 0.1.3 (2024-01-17)
* display the data from PV strings (#27)
* optimize the timing of interval loop
Expand Down
20 changes: 18 additions & 2 deletions io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
"zh-cn": "Huawei sun2000 inverters"
},
"desc": {
"en": "Read data from Huawei SUN2000 inverter and LUNA2000 battery using Modbus TCP\n",
"de": "Auslesen von Huawei SUN2000 Wechselrichter und LUNA2000 Akku über Modbus TCP\n",
"en": "Read data from Huawei SUN2000 inverters and LUNA2000 battery using Modbus TCP\n",
"de": "Auslesen von Huawei SUN2000 Wechselrichtern und LUNA2000 Akkus über Modbus TCP\n",
"ru": "Прочитайте данные от Huawei SUN2000 inverter и LUNA2000 батареи с помощью Modbus TCP\n",
"pt": "Leia dados do inversor Huawei SUN2000 e da bateria LUNA2000 usando Modbus TCP\n",
"nl": "Lees gegevens van Huawei SUN2000 inverter en LUNA2000 batterij met Modbus TCP\n",
Expand Down Expand Up @@ -210,6 +210,22 @@
"desc": "modbus update interval",
"unit": "sec"
}
},
{
"_id": "info.JSONhealth",
"type": "state",
"common": {
"name": {
"en": "health information",
"de": "Gesundheitsinformation"
},
"type": "string",
"role": "indicator.alarm.health",
"read": true,
"write": false,
"desc": "",
"unit": ""
}
}
]
}
31 changes: 13 additions & 18 deletions lib/modbus_connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@ class ModbusConnect extends DeviceInterface {
}

close() {
return new Promise((resolve,reject) => {
if (this.isOpen()) {
this.client.close((err,data) => {
if (err) reject(err);
resolve(data);
} );
} else {
return new Promise((resolve) => {
this.client.close(() => {
//if (err) reject(err);
resolve({});
}
} );
});
}

Expand All @@ -69,22 +65,22 @@ class ModbusConnect extends DeviceInterface {
}


async _destroy() {
return new Promise((resolve,reject) => {
this.client.destroy((err,data) => {
if (err) reject(err);
resolve(data);
_destroy() {
return new Promise((resolve) => {
this.client.destroy(() => {
//if (err) reject(err);
resolve({});
});
});
}

async _checkError(err) {
this.adapter.log.debug('modbus client error: '+JSON.stringify(err));
await this.close();
if (err.modbusCode == null) {
this.adapter.log.debug('modbusCode == 0!');
await this.close();
this.adapter.log.debug('modbus client destroyed');
//https://github.com/yaacov/node-modbus-serial/issues/96
//await this._destroy();
//this.adapter.log.debug('Client destroy!');
await this._create();
}
}
Expand All @@ -93,7 +89,7 @@ class ModbusConnect extends DeviceInterface {
async connect(repeatCounter = 0) {
try {
this.adapter.log.info('Open Connection...');
await this.close();
this.isOpen() && await this.close();
await this.client.setTimeout(5000);
await this.client.connectTcpRTUBuffered(this.ipAddress, { port: this.port} ); //hang
await this.delay(1000);
Expand All @@ -113,7 +109,6 @@ class ModbusConnect extends DeviceInterface {
async readHoldingRegisters(address, length) {
try {
await this.open();
//this.adapter.log.debug('client.setID: '+this._id);
await this.client.setID(this._id);
const data = await this.client.readHoldingRegisters(address, length);
return data.data;
Expand Down
Loading

0 comments on commit 33ad62c

Please sign in to comment.