Bluetooth環境センサーRS-BTEVS1からデータをNode-REDで可視化

使用機器

Bluetooth環境センサー RS-BTEVS1 (ラトックシステム株式会社)

室内の温度や湿度、CO2濃度にPM2.5(1/4/10)も測定できる環境センサーです。
BLEのレシーバーを使用して受信したデータをNode-REDで可視化していきます。

機器の立ち上げ

コンセントにさしてすぐ使用できます。左側のアンテナを立てておきましょう。

MACアドレスはここに記載されています。Node-REDでの実装時に使用します。

計測データの仕様をpdfから引用してきました。

ノードの作成


[{"id":"fcc27bf6cad6aa63","type":"BLE Beacon Scanner","z":"23af55b50b4cc44f","name":"","x":240,"y":200,"wires":[["1265703ed62aff71"]]},{"id":"6aca689b132472bc","type":"debug","z":"23af55b50b4cc44f","name":"Debug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":200,"wires":[]},{"id":"1265703ed62aff71","type":"switch","z":"23af55b50b4cc44f","name":"MacAddressでfilter","property":"payload.address","propertyType":"msg","rules":[{"t":"eq","v":"xx:xx:xx:xx:xx:xx(MACアドレスを入力)","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":510,"y":200,"wires":[["6aca689b132472bc","f05f425955799d2c"]]},{"id":"56bc5675787ebacc","type":"debug","z":"23af55b50b4cc44f","name":"Debug2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":780,"y":260,"wires":[]},{"id":"f05f425955799d2c","type":"function","z":"23af55b50b4cc44f","name":"Object->Array","func":"// input変数にはInjectノードからのメッセージが含まれます\nvar inputObject = msg.payload.other; // input.payloadはオブジェクトと仮定\n\nif (typeof inputObject === 'object' && inputObject !== null) {\n // オブジェクトのキーを取得し、それを使ってArrayを生成\n var keys = Object.keys(inputObject);\n var outputArray = keys.map(key => inputObject[key]);\n\n return { payload: outputArray };\n}\n\n// オブジェクトが存在しない場合\nreturn msg; // または、適切な値に置き換えてください\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":260,"wires":[["56bc5675787ebacc","c4393b6d65082064","2c8fd5e2b3174986","93ae16e87d19abdc","1a5c501b20164e0f","5ebd915b8d95917d","9ea7fb152690e368","6f7b3495d5700c7f","6bf989fbb9a1687c"]]},{"id":"c4393b6d65082064","type":"function","z":"23af55b50b4cc44f","name":"16進数文字列の作成","func":"const data = msg.payload;\nvar fixdata = '';\n\nfor (let i = 0; i < data.length; i++) {\n var hexValue = data[i].toString(16);\n\n // 1桁の場合、前に0を補完\n if (hexValue.length === 1) {\n hexValue = '0' + hexValue;\n }\n\n fixdata = fixdata + hexValue;\n}\n\nmsg.payload = fixdata;\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":320,"wires":[["07adc2c8774ebdaf","b503e2b5aa6395cb","fef74c87faf34edc"]]},{"id":"07adc2c8774ebdaf","type":"debug","z":"23af55b50b4cc44f","name":"Debug3","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":860,"y":320,"wires":[]},{"id":"b503e2b5aa6395cb","type":"function","z":"23af55b50b4cc44f","name":"データ整理","func":"const data = msg.payload;\nconst jsonData = {\n CompanyID: data.substring(0, 4),\n CO2: data.substring(4, 8),\n PMdata: data.substring(8, 16),\n Temperature: data.substring(16,20),\n Humid: data.substr(20)\n};\nmsg.payload = jsonData;\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":710,"y":380,"wires":[["7ec7d7569e433f02","97dae78b1ac20fdd","1019f66b07b300ff","7f142e3129f5faae","fa171c843d32d64c","5ab7fbe8dc6c0ef0"]]},{"id":"7ec7d7569e433f02","type":"debug","z":"23af55b50b4cc44f","name":"Debug4","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":380,"wires":[]},{"id":"12eb37daec728514","type":"function","z":"23af55b50b4cc44f","name":"Temperature計算②","func":"msg.temp = (msg.payload[9] * 255 + msg.payload[8]) /10;\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1110,"y":100,"wires":[["58a610e0e9fdcb04","d33056ec34e78e80","a60c9946e21c9433"]]},{"id":"58a610e0e9fdcb04","type":"debug","z":"23af55b50b4cc44f","name":"DebugTemp","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"temp","targetType":"msg","statusVal":"","statusType":"auto","x":1390,"y":40,"wires":[]},{"id":"2c8fd5e2b3174986","type":"debug","z":"23af55b50b4cc44f","name":"DebugHumid","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload[10]","targetType":"msg","statusVal":"","statusType":"auto","x":1170,"y":160,"wires":[]},{"id":"6bf989fbb9a1687c","type":"function","z":"23af55b50b4cc44f","name":"CO2計算②","func":"msg.co2 = msg.payload[3] * 255 + msg.payload[2];\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":970,"y":40,"wires":[["12eb37daec728514","4b8541eec9a9a45d"]]},{"id":"4b8541eec9a9a45d","type":"debug","z":"23af55b50b4cc44f","name":"DebugCO2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"co2","targetType":"msg","statusVal":"","statusType":"auto","x":1170,"y":40,"wires":[]},{"id":"fef74c87faf34edc","type":"ui_text","z":"23af55b50b4cc44f","group":"71c614f549b6503f","order":0,"width":0,"height":0,"name":"","label":"16進全体","format":"{{msg.payload}}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1140,"y":440,"wires":[]},{"id":"97dae78b1ac20fdd","type":"ui_text","z":"23af55b50b4cc44f","group":"71c614f549b6503f","order":1,"width":0,"height":0,"name":"","label":"CompanyID","format":"{{msg.payload.CompanyID}}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1150,"y":480,"wires":[]},{"id":"1019f66b07b300ff","type":"ui_text","z":"23af55b50b4cc44f","group":"71c614f549b6503f","order":2,"width":0,"height":0,"name":"","label":"CO2 level","format":"{{msg.payload.CO2}}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1140,"y":520,"wires":[]},{"id":"fa171c843d32d64c","type":"ui_text","z":"23af55b50b4cc44f","group":"71c614f549b6503f","order":3,"width":0,"height":0,"name":"","label":"PM〇〇","format":"{{msg.payload.PMdata}}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1140,"y":560,"wires":[]},{"id":"5ab7fbe8dc6c0ef0","type":"ui_text","z":"23af55b50b4cc44f","group":"71c614f549b6503f","order":4,"width":0,"height":0,"name":"","label":"Temperature","format":"{{msg.payload.Temperature}}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1150,"y":600,"wires":[]},{"id":"7f142e3129f5faae","type":"ui_text","z":"23af55b50b4cc44f","group":"71c614f549b6503f","order":5,"width":0,"height":0,"name":"","label":"Humidity","format":"{{msg.payload.Humid}}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1140,"y":640,"wires":[]},{"id":"a60c9946e21c9433","type":"ui_text","z":"23af55b50b4cc44f","group":"a67b478cee43f5f9","order":6,"width":0,"height":0,"name":"","label":"CO2 level","format":"{{msg.co2}} ppm","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1560,"y":60,"wires":[]},{"id":"d33056ec34e78e80","type":"ui_text","z":"23af55b50b4cc44f","group":"a67b478cee43f5f9","order":6,"width":0,"height":0,"name":"","label":"Temperature","format":"{{msg.temp}} ℃","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1570,"y":100,"wires":[]},{"id":"93ae16e87d19abdc","type":"ui_text","z":"23af55b50b4cc44f","group":"a67b478cee43f5f9","order":6,"width":0,"height":0,"name":"","label":"Humidity","format":"{{msg.payload[10]}} %RH","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1560,"y":140,"wires":[]},{"id":"1a5c501b20164e0f","type":"ui_text","z":"23af55b50b4cc44f","group":"9ed0a591c4a0eed9","order":6,"width":0,"height":0,"name":"","label":"PM1.0 質量濃度","format":"{{msg.payload[4]}} μg/m3","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1580,"y":200,"wires":[]},{"id":"5ebd915b8d95917d","type":"ui_text","z":"23af55b50b4cc44f","group":"9ed0a591c4a0eed9","order":6,"width":0,"height":0,"name":"","label":"PM2.5 質量濃度","format":"{{msg.payload[5]}} μg/m3","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1580,"y":240,"wires":[]},{"id":"9ea7fb152690e368","type":"ui_text","z":"23af55b50b4cc44f","group":"9ed0a591c4a0eed9","order":6,"width":0,"height":0,"name":"","label":"PM4.0 質量濃度","format":"{{msg.payload[6]}} μg/m3","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1580,"y":280,"wires":[]},{"id":"6f7b3495d5700c7f","type":"ui_text","z":"23af55b50b4cc44f","group":"9ed0a591c4a0eed9","order":6,"width":0,"height":0,"name":"","label":"PM10.0 質量濃度","format":"{{msg.payload[7]}} μg/m3","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":1590,"y":320,"wires":[]},{"id":"0937c6c3c2140fc0","type":"comment","z":"23af55b50b4cc44f","name":"Rawdata","info":"","x":1080,"y":400,"wires":[]},{"id":"71c614f549b6503f","type":"ui_group","name":"Rawdata","tab":"4e6203f8b7533ede","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"a67b478cee43f5f9","type":"ui_group","name":"View","tab":"4e6203f8b7533ede","order":2,"disp":true,"width":"6","collapse":false,"className":""},{"id":"9ed0a591c4a0eed9","type":"ui_group","name":"PM data","tab":"4e6203f8b7533ede","order":3,"disp":true,"width":"6","collapse":false,"className":""},{"id":"4e6203f8b7533ede","type":"ui_tab","name":"ratok","icon":"dashboard","disabled":false,"hidden":false}]


まずは、BLE Beacon ScannarからRS-BTEVS1のMACアドレスでフィルターをかけ、データを絞り込みます。

この時点で、payloadにはデータが格納されておりますが、RS-BTEVS1の仕様書通りに16進数の文字列等(生データ)を作成しています。

生データと可視化データのダッシュボード用ノードです。

CO2・Temperatureは仕様書に従った計算で値を求めています。

ダッシュボードでの表示

ダッシュボード上にはこのように表示され、可視化することができます。