Created
October 3, 2023 12:55
-
-
Save imksoo/e48f9266dbcfdb5c60e8265d7724da0d to your computer and use it in GitHub Desktop.
ニチコンの家庭用蓄電池からEchonet Lite経由で充電残量を取得するJavascriptコード
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
const EchonetLite = require('node-echonet-lite'); | |
const el = new EchonetLite({ type: 'lan' }); | |
el.init((err) => { | |
if (err) { | |
console.log(err); | |
process.exit(1); | |
} else { | |
getBatteryStatus(el); | |
} | |
}); | |
function getBatteryStatus(el) { | |
const addr = '172.17.1.66'; | |
const eoj = [0x02, 0x7D, 0x01]; | |
const epc = [0xE4]; | |
el.getPropertyValue(addr, eoj, epc, (err, res) => { | |
if (err) { | |
console.log(err); | |
process.exit(1); | |
} else { | |
const mes = JSON.parse(JSON.stringify(res['message'])); | |
const batteryPercentage = mes['prop'][0]['buffer']['data'][0]; | |
console.log(batteryPercentage); | |
} | |
process.exit(0); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment