victronenergy / node-red-contrib-victron

MIT License
87 stars 18 forks source link

ItemsChanged failure on dbus-system.js #112

Closed dirkjanfaber closed 2 years ago

dirkjanfaber commented 2 years ago

On an ESS system Node-RED would not start with the following error in /var/log/node-red/current:

 16 Dec 11:59:41 - [red] Uncaught Exception:
 16 Dec 11:59:41 - [error] TypeError: Cannot read property '0' of undefined
     at /usr/lib/node_modules/@victronenergy/node-red-contrib-victron/src/services/dbus-listener.js:183:41
     at Array.forEach (<anonymous>)
     at VictronDbusListener._signalRecieve (/usr/lib/node_modules/@victronenergy/node-red-contrib-victron/src/services/dbus-listener.js:178:29)
     at EventEmitter.emit (events.js:412:35)
     at /usr/lib/node_modules/@victronenergy/node-red-contrib-victron/node_modules/dbus-native/index.js:106:14
     at Socket.<anonymous> (/usr/lib/node_modules/@victronenergy/node-red-contrib-victron/node_modules/dbus-native/lib/message.js:55:9)
     at Socket.emit (events.js:400:28)
     at emitReadable_ (internal/streams/readable.js:550:12)
     at processTicksAndRejections (internal/process/task_queues.js:81:21)
dirkjanfaber commented 2 years ago

Added a console.log(entry) before the error and checked the messages:

 [
   '/History/Daily/0/MaxBatteryVoltage',
   [ [ 'Value', [Array] ], [ 'Text', [Array] ] ]
 ]
 [ '/Ac/L1/Current', [ [ 'Value', [Array] ] ] ]
 16 Dec 11:56:53 - [red] Uncaught Exception:

The /Ac/L1/Current does not seem to have a 'Text' entry.

And another one:

[ '/Pv/V', [ [ 'Value', [Array] ], [ 'Text', [Array] ] ] ]
[ '/Pv/V', [] ]
16 Dec 11:59:41 - [red] Uncaught Exception: 

Though I can filter out the values without Text or Value, I had not expected to see them in the first place. Looking at the system with dbus-monitor --system path=/,member=ItemsChanged reveals that they are like that on the dbus.

signal time=1639653187.875452 sender=:1.63 -> destination=(null destination) serial=12581 path=/; interface=com.victronenergy.BusItem; member=ItemsChanged
   array [
      dict entry(
         string "/Yield/Power"
         array [
            dict entry(
               string "Value"
               variant                   double 1368
            )
            dict entry(
               string "Text"
               variant                   string "1368W"
            )
         ]
      )
      dict entry(
         string "/Pv/V"
         array [
            dict entry(
               string "Value"
               variant                   double 93.28
            )
            dict entry(
               string "Text"
               variant                   string "93.28V"
            )
         ]
      )
      dict entry(
         string "/Pv/V"
         array [
         ]
      )
   ]

So besides filtering out these messages I need to verify if this is indeed expected normal behavior.

dirkjanfaber commented 2 years ago

Checked and it turns out that both cases are "invalid", meaning that we can ignore this kind of messages. Instead of throwing away wrong ones, this is better implemented by only allowing right ones.