parnic / node-screenlogic

Pentair ScreenLogic Javascript library using Node.JS
https://www.npmjs.com/package/node-screenlogic
MIT License
53 stars 15 forks source link

Socket reads only first chunk (1024 bytes). #5

Closed tkapluk closed 5 years ago

tkapluk commented 5 years ago

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

parnic commented 5 years ago

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

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

tkapluk commented 5 years ago

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

parnic commented 5 years ago

Please let me know if that commit fixes your issue.

tkapluk commented 5 years ago

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.

parnic commented 5 years ago

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

tkapluk commented 5 years ago

Now work fine. Thanks.