Skip to content

Instantly share code, notes, and snippets.

@imksoo
Created October 3, 2023 12:55
Show Gist options
  • Save imksoo/e48f9266dbcfdb5c60e8265d7724da0d to your computer and use it in GitHub Desktop.
Save imksoo/e48f9266dbcfdb5c60e8265d7724da0d to your computer and use it in GitHub Desktop.
ニチコンの家庭用蓄電池からEchonet Lite経由で充電残量を取得するJavascriptコード
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