Sineos / redmatic-flow-sysinfo

Display CCU system information in a dashboard
GNU General Public License v3.0
7 stars 2 forks source link

"TypeError: Cannot read property '1' of undefined" #4

Closed RobiRob81 closed 5 years ago

RobiRob81 commented 5 years ago

Function "Extract RSSI values" got with my raspberrymatic a error and wont work or wont display the RSSI values.

Sineos commented 5 years ago

I have updated the flow. Please test and if it does not work:

smart-ralf commented 5 years ago

Hi @Sineos,

I have the same problem with my Raspberrymatic. Unfortunately it seems it was not fixed.

Here the debug output of the rssiInfo node:

{  
   "LEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -60
      ]
   },
   "MEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -64
      ]
   },
   "MEQnnnnnnn":{  
      "OEQ060nnnn":[  
         -57,
         -190
      ]
   },
   "MEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -67
      ]
   },
   "MEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -216
      ]
   },
   "MEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -215
      ]
   },
   "MEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -62
      ]
   },
   "OEQnnnnnnn":{  
      "OEQnnnnnnn":[  
         -75,
         65536
      ],
      "OEQ060nnnn":[  
         65536,
         -207
      ]
   },
   "OEQnnnnnnn":{  
      "OEQ060nnnn":[  
         -56,
         -205
      ]
   },
   "OEQnnnnnnn":{  
      "OEQnnnnnnn":[  
         65536,
         -75
      ],
      "OEQ060nnnn":[  
         65536,
         -41
      ]
   },
   "OEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -61
      ]
   },
   "OEQ060nnnn":{  
      "LEQnnnnnnn":[  
         -60,
         65536
      ],
      "MEQnnnnnnn":[  
         -64,
         65536
      ],
      "MEQnnnnnnn":[  
         -190,
         -57
      ],
      "MEQnnnnnnn":[  
         -67,
         65536
      ],
      "MEQnnnnnnn":[  
         -216,
         65536
      ],
      "MEQnnnnnnn":[  
         -215,
         65536
      ],
      "MEQnnnnnnn":[  
         -62,
         65536
      ],
      "OEQnnnnnnn":[  
         -207,
         65536
      ],
      "OEQnnnnnnn":[  
         -205,
         -56
      ],
      "OEQnnnnnnn":[  
         -41,
         65536
      ],
      "OEQnnnnnnn":[  
         -61,
         65536
      ],
      "OEQnnnnnnn":[  
         -51,
         65536
      ],
      "OEQnnnnnnn":[  
         -64,
         65536
      ],
      "OEQnnnnnnn":[  
         -66,
         65536
      ],
      "OEQnnnnnnn":[  
         -63,
         65536
      ],
      "OEQnnnnnnn":[  
         -81,
         65536
      ],
      "OEQnnnnnnn":[  
         -51,
         65536
      ],
      "OEQnnnnnnn":[  
         -77,
         65536
      ],
      "OEQnnnnnnn":[  
         -51,
         65536
      ],
      "OEQnnnnnnn":[  
         -60,
         65536
      ],
      "OEQnnnnnnn":[  
         -61,
         65536
      ],
      "OEQnnnnnnn":[  
         -62,
         65536
      ],
      "OEQnnnnnnn":[  
         -77,
         65536
      ],
      "OEQnnnnnnn":[  
         -65,
         65536
      ]
   },
   "OEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -51
      ]
   },
   "OEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -64
      ]
   },
   "OEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -66
      ]
   },
   "OEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -63
      ]
   },
   "OEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -81
      ]
   },
   "OEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -51
      ]
   },
   "OEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -77
      ]
   },
   "OEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -51
      ]
   },
   "OEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -60
      ]
   },
   "OEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -61
      ]
   },
   "OEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -62
      ]
   },
   "OEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -77
      ]
   },
   "OEQnnnnnnn":{  
      "OEQ060nnnn":[  
         65536,
         -65
      ]
   }
}

(I anonymized my serial numbers a bit.)

I changed "Extract RSSI values", following works for me:

'use strict';
var rssi = msg.payload;
var myRSSIObj = {},
    myDBValues = [],
    ccu = '',
    msg2 = {},
    myObj = {};

// the last one is not the CCU
ccu = 'Smarthome';

for (var key of Object.keys(rssi)) {
    myObj = rssi[key];
    for (var key2 of Object.keys(myObj)) {

        if (myObj[key2][1] < 0) {
            myDBValues.push(myObj[key2][1]);
        } else if (myObj[key2][1] > 0) {
            myDBValues.push('n/a');
        }

        if (myObj[key2][0] < 0) {
           myDBValues.push(myObj[key2][0]); 
        } else if (myObj[key2][0] > 0) {
            myDBValues.push('n/a');
        }

        myRSSIObj[key] = myDBValues;
        myDBValues = [];
    }        
}

I wanted to push my changes to your repo and to create a pull request for review of my changes, but it seems I have no permission to push.

Regards Ralf

Sineos commented 5 years ago

@smart-ralf thanks for this contribution. Unfortunately your code does not work on my side. What about:

'use strict';
var rssi = msg.payload;
var myRSSIObj = {},
    myDBValues = [],
    ccu = '',
    msg2 = {};

for (var key of Object.keys(rssi)) {
  if (Object.keys(rssi[key]).length === 1) {
    ccu = Object.keys(rssi[key])[0];
    myDBValues.push(rssi[key][ccu][1]);
    if (rssi[key][ccu][0] < 0) {
      myDBValues.push(rssi[key][ccu][0]);
    } else if (rssi[key][ccu][0] > 0) {
      myDBValues.push('n/a');
    }
    myRSSIObj[key] = myDBValues;
    myDBValues = [];
  }
}

msg2 = {
  payload: myRSSIObj,
  topic: msg.topic,
  ccu: ccu
};

return msg2;

Identifying the CCU seems tricky. As far as I'm aware, this one should work with one exception: If someone has only one device besides the CCU then it will fail (but who has only one ;-))

smart-ralf commented 5 years ago

@Sineos

I tested your code and it seems to work now.

bildschirmfoto 2019-02-25 um 19 29 33

It would good to have the names of devices instead of the serial numbers. I'll think about it, maybe I find a way to do it. Thanks for your solution.

19Homer73 commented 5 years ago

@smart-ralf thanks for this contribution. Unfortunately your code does not work on my side. What about:

'use strict';
var rssi = msg.payload;
var myRSSIObj = {},
    myDBValues = [],
    ccu = '',
    msg2 = {};

for (var key of Object.keys(rssi)) {
  if (Object.keys(rssi[key]).length === 1) {
    ccu = Object.keys(rssi[key])[0];
    myDBValues.push(rssi[key][ccu][1]);
    if (rssi[key][ccu][0] < 0) {
      myDBValues.push(rssi[key][ccu][0]);
    } else if (rssi[key][ccu][0] > 0) {
      myDBValues.push('n/a');
    }
    myRSSIObj[key] = myDBValues;
    myDBValues = [];
  }
}

msg2 = {
  payload: myRSSIObj,
  topic: msg.topic,
  ccu: ccu
};

return msg2;

Identifying the CCU seems tricky. As far as I'm aware, this one should work with one exception: If someone has only one device besides the CCU then it will fail (but who has only one ;-))

Worked on my RaspberryMatic as well!!!