A plug and play way to easily read data from your connected Victron VE.Direct devices
0.0.6: [Feature]
--Added all methods, constructor parameters and events documentation on README.md
-
0.0.5: [Feature breaking changes!]
--Improved events naming, types and listener
--Implement reset functionality
--Implement custom VE.Direct devices paths constructor parameter
-
0.0.4: [Hotfix]
--Fixes incorrect identification of VE.Direct serial port interfaces
-
Connect your Victron device using the VE.Direct USB interface to your Raspberry or Linux x86-64 based computer
-
npm i @devalexdom/victron-vedirect-pnp
-
Run:
const VEDirectPnP = require("@devalexdom/victron-vedirect-pnp");
const dataReader = new VEDirectPnP();
dataReader.on("stream-init", () => {
console.log(dataReader.getDevicesData());
/*{
"HQ21340EFYE": {
"deviceName": "SmartSolar MPPT 100|50",
"deviceSN": "HQ21340EFYE",
"deviceType": "MPPT",
"deviceFirmwareVersion": 1.59,
"batteryVoltage": 28.32,
"batteryCurrent": 21.2,
"statusMessage": "Absorption",
"errorMessage": "",
"mpptMessage": "Voltage or current limited",
"maximumPowerToday": 909,
"maximumPowerYesterday": 835,
"totalEnergyProduced": 130.4,
"energyProducedToday": 1.98,
"energyProducedYesterday": 3.55,
"photovoltaicPower": 608,
"photovoltaicVoltage": 37.32,
"photovoltaicCurrent": 16.291532690246516,
...
*/
});
- And start making great green things ๐ฑ๐!
const VEDirectPnP = require("@devalexdom/victron-vedirect-pnp");
const dataReader = new VEDirectPnP({ veDirectDevicesPath: "/dev/serial/by-id/" }); //Optional parameter to set the directory path of the VE.Direct USB interfaces
dataReader.on("stream-init", () => {
const allDevicesData = dataReader.getDevicesData();
console.log(allDevicesData["HQ21340EFYE"]);
/* If your device serial number is HQ21340EFYE the expected output will be:
{
deviceName: 'SmartSolar MPPT 100|50',
deviceSN: 'HQ21340EFYE',
deviceType: 'MPPT',
deviceFirmwareVersion: 1.59,
batteryVoltage: 25.49, //Volts
batteryCurrent: 0, //Amps
statusMessage: 'Off',
errorMessage: '',
mpptMessage: 'Off',
maximumPowerToday: 835, //Watts
maximumPowerYesterday: 837, //Watts
totalEnergyProduced: 128.42, //kWh
energyProducedToday: 3.55, //kWh
energyProducedYesterday: 3.63, //kWh
photovoltaicPower: 0, //Watts
photovoltaicVoltage: 0.82, //Volts
photovoltaicCurrent: 0, //Amps
loadCurrent: 0, //Amps
loadOutputState: true,
relayState: false,
offReasonMessage: 'No input power',
daySequenceNumber: 142,
VEDirectData: {
PID: 41047,
FW: 159,
'SER#': 'HQ21340EFYE',
V: 25490,
I: 0,
VPV: 820,
PPV: 0,
CS: 0,
MPPT: 0,
OR: 1,
ERR: 0,
LOAD: 'ON',
H19: 12842,
H20: 355,
H21: 835,
H22: 363,
H23: 837,
HSDS: 142,
dataTimeStamp: 1643058077196
}
}
*/
}, 1000);
})
//Handling errors
dataReader.on("error", (error) => {
console.error(error);
})
By default "/dev/serial/by-id/", the path where the VE.Direct interfaces will be searched
Manually sets the VE.Direct interfaces paths
new VEDirectPnP({
veDirectDevicesPath: "/dev/serial/by-id/",
customVEDirectDevicesPaths: ["/dev/serial/by-id/usb-VictronEnergy_BV_VE_Direct_cable_VE83Y8X8-if00-port0"]
});
Returns a key -> value, the key is the serial number of the Victron device, value the processed stream data
const dataReader = new VEDirectPnP();
dataReader.on("interface-found", (eventData) => {
/*
eventData: IVEDirectPnP_EventData
{
message: string;
dataDump: any;
eventName: string;
}
*/
})
Listen to VEDirectPnP events
const dataReader = new VEDirectPnP();
dataReader.on("interface-found", (eventData) => {
/*
eventData: IVEDirectPnP_EventData
{
message: string;
dataDump: any;
eventName: string;
}
*/
})
With the "all" wildcard the listener will fire with all events
const dataReader = new VEDirectPnP();
dataReader.on("all", console.log);
/*
{
message: 'Found VE.Direct serial port interface',
dataDump: '/dev/serial/by-id/usb-VictronEnergy_BV_VE_Direct_cable_VE83Y8X8-if00-port0',
eventName: 'interface-found'
}
{
message: 'VE.Direct device connected through serial port',
dataDump: '/dev/serial/by-id/usb-VictronEnergy_BV_VE_Direct_cable_VE83Y8X8-if00-port0',
eventName: 'device-connection-open'
}
{
message: 'VE.Direct devices data stream init',
eventName: 'stream-init'
}
*/
Destroys the data stream from VE.Direct devices
const dataReader = new VEDirectPnP();
dataReader.destroy(()=>{
//callback when data stream is destroyed (All serial ports connection closed)
});
Resets the data stream from VE.Direct devices
const dataReader = new VEDirectPnP();
dataReader.reset(); //Be aware that the event "stream-init" will be emitted again
Cleans the cached data from VE.Direct devices stream
const dataReader = new VEDirectPnP();
dataReader.reset();
Initializes the data stream from VE.Direct devices
const dataReader = new VEDirectPnP();
dataReader.init(); //Initializes data stream from VE.Direct devices (Called on VEDirectPnP constructor)
Emitted when the VE.Direct devices starts sending data through serial port
Emitted when the VE.Direct devices stream has been destroyed (All serial ports connection closed)
Emitted when a critical error occurs with a (hopelly) helpful message
Emitted when a VE.Direct interface is automatically detected (The plug and play way)
Emitted when a connection to the VE.Direct device is opened
Emitted when a connection to the VE.Direct device suffers an error
const dataReader = new VEDirectPnP();
dataReader.on("device-connection-error", () => {
setTimeout(() => {
dataReader.reset();
}, 5000);
});//Example to reestablish a lost connection, it's not tested but should do the trick ;)
- Victron Phoenix Inverters data mapping
- Victron BMV data mapping
- Victron Phoenix Charger data mapping
- Kill the bugs
VE.Direct protocol 3.29 documentation.
VE.Direct parser using Stream interface @bencevans/ve.direct.