Skip to content

Instantly share code, notes, and snippets.

@fulup-bzh
Created July 15, 2018 21:15
Show Gist options
  • Save fulup-bzh/a722822e023f30d54d93c75a55747036 to your computer and use it in GitHub Desktop.
Save fulup-bzh/a722822e023f30d54d93c75a55747036 to your computer and use it in GitHub Desktop.
Simple javascript/node module to Handle KEBA P30 WallBox UDP command
'use strict';
// Author : Fulup Ar Foll
// Date : July-2018
// Licence : What ever please you until you fixe bug by yourself
// Object : Handle KEBA P30 WallBox UDP command
// Reference: https://www.keba.com/web/downloads/e-mobility/KeContact_P20_P30_UDP_ProgrGuide_en.pdf
// Debug : echo -n "report" | socat - UDP:KEBA:7090,bind=:7090,bindtodevice=eth0
// where: KEBA=IP-ADDR eth0 the internet interface when you send/receive data
// usage:
// node KEBA-UDP-CLI.js --discovery (broadcast "i" command to every existing KEBA on the network)
// node KEBA-UDP-CLI.js --address=X.X.X.X --command="keba-command" execute command and display result
// Example:
// node KEBA-UDP-CLI.js --address=keba-addr --command=i
// node KEBA-UDP-CLI.js --address=keba-addr --command='report 1'
// Bugs:
// - do not forget to set UDP DIP switch
// - my P30 does not respond to broadcast packet ???
// - Kena Wallbox does not return error or warning when a wrong command is sent
var udpPort=7090; // KEBA UDP port
var broadcast = "255.255.255.255";
var discovery = false;
var kebaAddr = false;
var command = false;
if (process.argv.length <= 2) {
console.log('\nKEBA-UDP-CLI: use --help to get options\n');
process.exit();
}
var dgram = require('dgram');
var client = dgram.createSocket('udp4');
var addr; // adapter address at discovery
// loop on arguments
for (var idx=1; idx < process.argv.length; idx++) {
// ingore any argument not starting with '--'
if (!process.argv[idx].startsWith("--")) continue;
var cmd=process.argv[idx].split('=');
switch (cmd[0]) {
case "--discovery":
case "--D":
discovery=true;
break;
case "--address":
case "--A":
kebaAddr=cmd[1];
break;
case "--command":
case "--C":
command = new Buffer(cmd[1]);
break;
default:
console.log('\n KEBA-UDP-CLI: Unknown Argument: ' + cmd + '\n');
process.exit(1);
}
}
client.on('listening', function () {
var listenaddr = client.address();
if (discovery) {
client.setBroadcast(true);
command = new Buffer("i");
kebaAddr= broadcast;
console.log('KEBA-UDP-CLI: use CTL-C to exist discovery mode');
} else {
if (!kebaAddr || !command) {
console.log('\nKEBA-UDP-CLI: should use (--discovery) or (--address=X.X.X.X and --command=xxxx)\n');
process.exit(1);
}
}
console.log('\nKEBA-UDP-CLI: listening on ' + listenaddr.address + ":" + listenaddr.port);
client.send(command, 0, command.length, udpPort, kebaAddr);
console.log('KEBA-UDP-CLI: sending command=' +command);
});
client.on('message', function (message, rinfo) {
console.log('KEBA-UDP-CLI: Message from: ' + rinfo.address + ':' + rinfo.port +' - length=' + message.length);
console.log(message.toString());
if (!discovery) {
process.exit(0);
}
});
client.bind(udpPort);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment