-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
function getFile(filePath) { | ||
if (filePath) { | ||
const fs = require('fs'); | ||
|
||
try { | ||
if (fs.existsSync(filePath)) { | ||
return fs.readFileSync(filePath); | ||
} | ||
} catch (err) { | ||
console.error('Failed to read file', filePath, err); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
function getFileEnv(envVariable) { | ||
const origVar = process.env[envVariable]; | ||
const fileVar = process.env[envVariable + '_FILE']; | ||
if (fileVar) { | ||
const file = getFile(fileVar); | ||
if (file) { | ||
return file.toString().split(/\r?\n/)[0].trim(); | ||
} | ||
} | ||
return origVar; | ||
} | ||
|
||
module.exports = { | ||
modbus: { | ||
type: 'tcp', | ||
port: '192.168.0.51', | ||
portConfig: { | ||
port: 502, | ||
}, | ||
}, | ||
devices: [ | ||
{ | ||
name: 'inverter', | ||
address: 0x01, | ||
type: 'sun2000', | ||
}, | ||
], | ||
integrations: { | ||
console: {}, | ||
mqtt: { | ||
url: process.env.BROKER, | ||
publishTopic: process.env.TOPIC, | ||
}, | ||
mongodb: { | ||
collection: process.env.COLLECTION, | ||
url: process.env.MONGODB_URL, | ||
options: { | ||
auth: { | ||
username: getFileEnv('MONGODB_USERNAME'), | ||
password: getFileEnv('MONGODB_PASSWORD'), | ||
} | ||
} | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Huawei SUN2000 Inverter | ||
|
||
const readLong = (msb, lsb) => msb << 16 | lsb | ||
|
||
async function read (client) { | ||
let data | ||
|
||
data = await client.readHoldingRegisters(32106, 2); | ||
// Accumulated energy yield (kWh) * 100 | ||
const total_p = readLong(data.data[0], data.data[1]) / 100 | ||
|
||
data = await client.readHoldingRegisters(32114, 2); | ||
// Daily energy yield (kWh) * 100 | ||
const daily_p = readLong(data.data[0], data.data[1]) / 100 | ||
|
||
data = await client.readHoldingRegisters(32080, 9) | ||
// Active power (kW) * 1000 | ||
const ap = readLong(data.data[0], data.data[1]) / 1000 | ||
// Reactive power (kVar) * 1000 | ||
const rp = readLong(data.data[2], data.data[3]) / 1000 | ||
// Power factor (1) * 1000 | ||
const pf = data.data[4] / 1000 | ||
// Grid frequency (Hz) * 100 | ||
const freq = data.data[5] / 100 | ||
// Efficiency (%) * 100 | ||
const eff = data.data[6] / 100 | ||
// Internal temperature (°C) * 10 | ||
const temp = data.data[7] / 10 | ||
// Insulation resistance (MΩ) * 1000 | ||
const ins = data.data[8] / 1000 | ||
|
||
return { | ||
total_p, | ||
daily_p, | ||
ap, | ||
rp, | ||
pf, | ||
freq, | ||
eff, | ||
temp, | ||
ins, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.