parnic / node-screenlogic

Pentair ScreenLogic Javascript library using Node.JS

Home Page:https://www.npmjs.com/package/node-screenlogic

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Socket reads only first chunk (1024 bytes).

tkapluk opened this issue · comments

Hello.
When I am runing this.getPoolStatus(); I get error: Attempted to read beyond the bounds of the managed data.

Error: Attempted to read beyond the bounds of the managed data.
smartbuffer.js:957
at SLControllerConfigMessage.ensureReadable (d:\node-screenlogic-master\node_modules\smart-buffer\build\smartbuffer.js:957:19)
at SLControllerConfigMessage._readNumberValue (d:\node-screenlogic-master\node_modules\smart-buffer\build\smartbuffer.js:1025:14)
at SLControllerConfigMessage.readInt32LE (d:\node-screenlogic-master\node_modules\smart-buffer\build\smartbuffer.js:145:21)
at SLControllerConfigMessage.decode (d:\node-screenlogic-master\messages\SLControllerConfigMessage.js:65:19)
at new SLControllerConfigMessage (d:\node-screenlogic-master\messages\SLControllerConfigMessage.js:17:12)
at UnitConnection.onClientMessage (d:\node-screenlogic-master\index.js:219:39)
at Socket. (d:\node-screenlogic-master\index.js:131:15)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)

I investigated this problem. Data send in two chunks, but app don't wait second chunk.

My fix for UnitConnection class:

var buffer = Buffer.from("", 'binary');
this.client.on('data', function(msg) {
buffer = Buffer.concat([buffer, msg]);
if (msg.length!=1024) {
_this.onClientMessage(buffer);
buffer = Buffer.from("", 'binary');
}
}).on('close', function(had_error) {
// console.log('unit connection closed');
});

received message of length 1196

Thanks! I'll try to get this rolled in.

What message were you receiving that was larger than 1k?

In this device many circuits and colors.
circuitCount = 31;
colorCount = 8;

Please let me know if that commit fixes your issue.

This commit don't fix my issue.
App hangs on 30 second and after that I have Error: read ECONNRESET

Error: read ECONNRESET
errors.js:313
at TCP.onStreamRead (internal/stream_base_commons.js:111:27)
Emitted 'error' event at:
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19)

onClientMessage received message of length 1024 when sum of two chunk 1196.

Whoops, try now. Sorry, I don't have the ability to test this locally. :)

Now work fine.
Thanks.