jorisvervuurt / JVSBME680

An easy-to-use Node.js module for Pimoroni's BME680 Breakout
MIT License
6 stars 0 forks source link

When initialising the sensor, the library attempts to parse two JSON objects which causes an error. #1

Open artomweb opened 3 years ago

artomweb commented 3 years ago

Error:

undefined:1 {"data": null, "component": "GasSensor", "event": "enableResponse"}{"data": null, "component": "GasSensor", "event": "setHeaterTemperatureResponse"} ^

SyntaxError: Unexpected token { in JSON at position 67 at JSON.parse () at Socket._pythonProcess.stdout.on (/home/pi/Desktop/server/node_modules/jvsbme680/lib/BME680.js:168:36) at Socket.emit (events.js:198:13) at addChunk (_stream_readable.js:288:12) at readableAddChunk (_stream_readable.js:265:13) at Socket.Readable.push (_stream_readable.js:224:10) at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)

This only used to happen occasionally and could be fixed I believe with git reset. However this no longer works and the error is always given. I have had a few problems with this library because my code also uses socket io, which breaks a lot of things.

jorisvervuurt commented 3 years ago

Thanks for creating the issue. To be honest, I haven't personally used this library for multiple years. The actual sensor reading is done by a Python script, which internally sends JSON back to the Node process. Not ideal, but it was the quickest way back then. :P It seems the JSON data gets delayed somehow and then is sent out simultaneously. Parsing the data assumes it is valid JSON, which in this case it indeed no longer is.

Feel free to submit a pull request to fix this issue; otherwise I will have to find the time to look at it. ;-)