Skip to content

Instantly share code, notes, and snippets.

@yanovik
Created February 18, 2018 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanovik/d39bb5c3963b1cc97146fda04b271e80 to your computer and use it in GitHub Desktop.
Save yanovik/d39bb5c3963b1cc97146fda04b271e80 to your computer and use it in GitHub Desktop.
SDS011 Air Quality Sensor with usb-uart adapter

inova fitness SDS011 Air Quality Sensor with usb-uart adapter

[{"id":"9090c1f9.4246d","type":"serial in","z":"2d8cb920.81f3a6","name":"USB UART RX","serial":"135cce08.b651f2","x":100,"y":80,"wires":[["ca7ea92e.3dcf48"]]},{"id":"ca7ea92e.3dcf48","type":"function","z":"2d8cb920.81f3a6","name":"Read Dust concentration","func":"var str = msg.payload.toString('hex');\nvar int = parseInt(str, 16);\nif (str == 'aa')\n {\n context.set('PmBuffer',msg.payload);\n context.set('count',1);\n context.set('checksumm',0);\n }\n else\n {\n var PmBuffer = Buffer.concat([context.get('PmBuffer'),msg.payload]);\n context.set('PmBuffer',PmBuffer);\n var count = context.get('count');\n var checksumm = context.get('checksumm');\n count += 1;\n context.set('count',count);\n if (count == 3)\n context.set('pm25',int);\n if (count == 4)\n context.set('pm25',context.get('pm25')+int*256);\n if (count == 5)\n context.set('pm10',int);\n if (count == 6)\n context.set('pm10',context.get('pm10')+int*256);\n if (count > 2 && count < 9)\n {\n checksumm += int;\n context.set('checksumm',checksumm);\n }\n if (count == 9)\n context.set('checksum8',int);\n if ((count == 10) && (str == 'ab'))\n {\n msg.payload = {};\n msg.payload.pm25 = context.get('pm25')/10;\n msg.payload.pm10 = context.get('pm10')/10;\n msg.payload.buffer = PmBuffer;\n msg.payload.checksumcalculated = checksumm % 256;\n msg.payload.checksummsg = context.get('checksum8');\n if (msg.payload.checksumcalculated == msg.payload.checksummsg)\n return [ msg, {\"payload\":msg.payload.pm25} , {\"payload\":msg.payload.pm10} ];\n else\n return [ {\"payload\":\"Wrong CheckSumm\"}, null , null ];\n }\n}\n//The number of bytes Name Content\n// 0 Message header AA\n// 1 Commander No. C0\n// 2 DATA 1 PM2.5 Low byte\n// 3 DATA 2 PM2.5 High byte\n// 4 DATA 3 PM10 Low byte\n// 5 DATA 4 PM10 High byte\n// 6 DATA 5 ID byte 1\n// 7 DATA 6 ID byte 2\n// 8 Check-sum Check-sum\n// 9 Message tail AB\n","outputs":3,"noerr":0,"x":390,"y":80,"wires":[["f872cde7.3677b"],["d30975c2.004fa8"],["bf82c2e.9519f4"]]},{"id":"a847d0e7.5ddf","type":"comment","z":"2d8cb920.81f3a6","name":"SDS011 laser PM2.5 sensor","info":"SDS011 laser PM2.5 sensor MANUAL\nhttps://pan.baidu.com/s/1skCk8AL","x":140,"y":40,"wires":[]},{"id":"f872cde7.3677b","type":"debug","z":"2d8cb920.81f3a6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":590,"y":40,"wires":[]},{"id":"d30975c2.004fa8","type":"debug","z":"2d8cb920.81f3a6","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":610,"y":80,"wires":[]},{"id":"bf82c2e.9519f4","type":"debug","z":"2d8cb920.81f3a6","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":610,"y":120,"wires":[]},{"id":"135cce08.b651f2","type":"serial-port","z":"","serialport":"/dev/tty.SLAB_USBtoUART","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","newline":"","bin":"bin","out":"char","addchar":false}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment