{"action":"created","issue":{"url":"https://api.github.com/repos/jankolkmeier/xbee-api/issues/33","labels_url":"https://api.github.com/repos/jankolkmeier/xbee-api/issues/33/labels{/name}","comments_url":"https://api.github.com/repos/jankolkmeier/xbee-api/issues/33/comments","events_url":"https://api.github.com/repos/jankolkmeier/xbee-api/issues/33/events","html_url":"https://github.com/jankolkmeier/xbee-api/issues/33","id":98424968,"number":33,"title":"RangeError: index out of range another case?","user":{"login":"emnik","id":5132377,"avatar_url":"https://avatars.githubusercontent.com/u/5132377?v=3","gravatar_id":"","url":"https://api.github.com/users/emnik","html_url":"https://github.com/emnik","followers_url":"https://api.github.com/users/emnik/followers","following_url":"https://api.github.com/users/emnik/following{/other_user}","gists_url":"https://api.github.com/users/emnik/gists{/gist_id}","starred_url":"https://api.github.com/users/emnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emnik/subscriptions","organizations_url":"https://api.github.com/users/emnik/orgs","repos_url":"https://api.github.com/users/emnik/repos","events_url":"https://api.github.com/users/emnik/events{/privacy}","received_events_url":"https://api.github.com/users/emnik/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-07-31T16:29:06Z","updated_at":"2015-08-02T19:50:44Z","closed_at":"2015-08-02T19:50:44Z","body":"Sorry for the bad title but...\r\nI am developing a smart thermostat using node.js on raspberry pi with Xbee Series 1.\r\nThe following is happening only with xbee-api in node.js (in python code I don't have such a problem) so it must be a bug.\r\nThe first time after booting RPi, on every Xbee frame I receive when I added  console.log(util.inspect(S)); in xbee-api.js (~line 187) I get:\r\nMULTIPLE frames (every time much more than the previous) with wrong offset, length etc:\r\nTo be more specific: I receive data from a remote Xbee every 30sec:\r\n\r\nOn the first data I get 16 TIMES:\r\n```\r\n{ buffer: <Buffer 00 00 a8 48 e4 01 00 00 00 00 48 34 e4 01 a0 a7 a1 be 00 00 00 00 ff ff ff ff 20 c4 81 00 00 00 00 00 00 00 00 00 60 00 00 00 2d 00 00 00 fc 48 e4 01 ... >,\r\n  offset: 0,\r\n  length: 0,\r\n  total: 0,\r\n  checksum: 0,\r\n  b: 0,\r\n  escape_next: false,\r\n  waiting: true }\r\n```\r\nOn the second data I get 11 TIMES:\r\n```\r\n{ buffer: <Buffer 7e 00 00 09 81 00 02 35 00 00 00 f0 41 16 00 00 00 74 6f 67 67 6c 65 00 00 00 c1 81 00 30 95 d7 01 01 13 05 02 60 13 05 02 06 00 00 00 0a 1e c8 d3 00 ... >,\r\n```\r\nwith offset values ranging from 1 to 14 every time...\r\n\r\nOn the third data I get 13 TIMES:\r\n```\r\n{ buffer: <Buffer 7e 00 00 09 81 00 02 35 00 00 00 f0 41 16 7e 00 09 81 00 02 33 00 00 80 f0 41 98 81 00 30 95 d7 01 01 13 05 02 60 13 05 02 06 00 00 00 0a 1e c8 d3 00 ... >,\r\n```\r\nwith offset values ranging from 5 to 27 every time...\r\n\r\n... this keeps growing and when the offset becomes = 128 it crashes:\r\n```\r\nbuffer.js:706\r\n    throw new RangeError('index out of range');\r\n          ^\r\nRangeError: index out of range\r\n    at checkInt (buffer.js:706:11)\r\n    at Buffer.writeUInt8 (buffer.js:748:5)\r\n    at XBeeAPI.parseRaw (/home/pi/apps/pyre/node_modules/xbee-api/lib/xbee-api.js:162:18)\r\n    at XBeeAPI.<anonymous> (/home/pi/apps/pyre/node_modules/xbee-api/lib/xbee-api.js:133:10)\r\n    at Object.SerialPort.opts.dataCallback (/home/pi/apps/pyre/node_modules/serialport/serialport.js:181:12)\r\n    at SerialPortFactory.SerialPort._emitData (/home/pi/apps/pyre/node_modules/serialport/serialport.js:396:20)\r\n    at afterRead (/home/pi/apps/pyre/node_modules/serialport/serialport.js:372:20)\r\n    at /home/pi/apps/pyre/node_modules/serialport/serialport.js:388:9\r\n    at FSReqWrap.wrapper [as oncomplete] (fs.js:529:17)\r\n31 Jul 17:39:35 - [nodemon] app crashed - waiting for file changes before starting...\r\n```\r\nSEE HERE: http://pastebin.com/LSeRbJQm \r\n\r\nNow, if I restart the app everything works just fine: \r\nEvery 30 seconds I get a frame such:\r\n```\r\n{ buffer: <Buffer 7e 00 09 81 00 02 30 00 00 80 f0 41 9b 06 02 00 00 07 02 00 00 98 ef 0a 02 01 00 00 00 01 00 00 00 01 36 63 6e 08 02 00 00 00 00 00 00 b0 f2 0a 02 88 ... >,\r\n  offset: 13,\r\n  length: 9,\r\n  total: 612,\r\n  checksum: 155,\r\n  b: 155,\r\n  escape_next: false,\r\n  waiting: false }\r\n```"},"comment":{"url":"https://api.github.com/repos/jankolkmeier/xbee-api/issues/comments/127061794","html_url":"https://github.com/jankolkmeier/xbee-api/issues/33#issuecomment-127061794","issue_url":"https://api.github.com/repos/jankolkmeier/xbee-api/issues/33","id":127061794,"user":{"login":"emnik","id":5132377,"avatar_url":"https://avatars.githubusercontent.com/u/5132377?v=3","gravatar_id":"","url":"https://api.github.com/users/emnik","html_url":"https://github.com/emnik","followers_url":"https://api.github.com/users/emnik/followers","following_url":"https://api.github.com/users/emnik/following{/other_user}","gists_url":"https://api.github.com/users/emnik/gists{/gist_id}","starred_url":"https://api.github.com/users/emnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emnik/subscriptions","organizations_url":"https://api.github.com/users/emnik/orgs","repos_url":"https://api.github.com/users/emnik/repos","events_url":"https://api.github.com/users/emnik/events{/privacy}","received_events_url":"https://api.github.com/users/emnik/received_events","type":"User","site_admin":false},"created_at":"2015-08-02T19:50:44Z","updated_at":"2015-08-02T19:50:44Z","body":"So, I kind of solved (more of a hack really) my problem by encapsulating the for loop of the ParseRaw function in an:\r\n```javascript\r\nif (buffer.length<=8) {\r\n    the for loop...\r\n}\r\n```\r\nI added this, as I noticed that on normal operation the buffer length is 8+5 (**the for loop runs twice for every frame - Can you please explain to me why?**), while when the error arrises, the buffer length at first is 16 (not ok) then 9 + 5 (not ok) and after that 8 + 5 / 8 + 5 / 8 + 5 /... that seems ok.\r\nNow I don't know why is this happening but for me seems to be working. Also I don't know if the values 8 followed by 5 for the buffer size, is specific to the data I am sending over RF (I send a float representing a thermal value) or not..."}}