Bluetoothワットチェッカー RS-BTWATTCH2からデータをNode-REDで可視化

Bluetooth環境センサーRS-BTEVS1からデータをNode-REDで可視化 の記事と類似した内容です。

 

使用機器

Bluetoothワットチェッカー RS-BTWATTCH2(ラトックシステム株式会社)

繋いだコンセントのON/OFF切り替えや、電圧・電流・電力を測定できるデバイスです。
BLEのレシーバーを使用して受信したデータをNode-REDで可視化していきます。

機器の接続

コンセントの間に入るよう接続します。再度のON/OFFボタンで給電の切り替えができます。
今回はPCの充電器を接続しています。

MACアドレスはON/OFFボタンの反対側に記載されています。

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

ノードの作成


[{&quot;id&quot;:&quot;33d70e22c9e88081&quot;,&quot;type&quot;:&quot;BLE Beacon Scanner&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;&quot;,&quot;x&quot;:120,&quot;y&quot;:380,&quot;wires&quot;:[[&quot;5a047c8194dbc24b&quot;]]},{&quot;id&quot;:&quot;5a047c8194dbc24b&quot;,&quot;type&quot;:&quot;switch&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;MacAddressでfilter&quot;,&quot;property&quot;:&quot;payload.address&quot;,&quot;propertyType&quot;:&quot;msg&quot;,&quot;rules&quot;:[{&quot;t&quot;:&quot;eq&quot;,&quot;v&quot;:&quot;fa:ce:09:c4:70:1d&quot;,&quot;vt&quot;:&quot;str&quot;}],&quot;checkall&quot;:&quot;true&quot;,&quot;repair&quot;:false,&quot;outputs&quot;:1,&quot;x&quot;:350,&quot;y&quot;:380,&quot;wires&quot;:[[&quot;d9d5119b52de41ca&quot;,&quot;c16133fd194d6236&quot;,&quot;3c45542dd9e57d7b&quot;]]},{&quot;id&quot;:&quot;d9d5119b52de41ca&quot;,&quot;type&quot;:&quot;debug&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;Debug&quot;,&quot;active&quot;:false,&quot;tosidebar&quot;:true,&quot;console&quot;:false,&quot;tostatus&quot;:false,&quot;complete&quot;:&quot;payload&quot;,&quot;targetType&quot;:&quot;msg&quot;,&quot;statusVal&quot;:&quot;&quot;,&quot;statusType&quot;:&quot;auto&quot;,&quot;x&quot;:530,&quot;y&quot;:380,&quot;wires&quot;:[]},{&quot;id&quot;:&quot;c16133fd194d6236&quot;,&quot;type&quot;:&quot;function&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;Object-&amp;gt;Array&quot;,&quot;func&quot;:&quot;// input変数にはInjectノードからのメッセージが含まれます\nvar inputObject = msg.payload.other; // input.payloadはオブジェクトと仮定\n\nif (typeof inputObject === 'object' &amp;amp;&amp;amp; inputObject !== null) {\n // オブジェクトのキーを取得し、それを使ってArrayを生成\n var keys = Object.keys(inputObject);\n var outputArray = keys.map(key =&amp;gt; inputObject[key]);\n\n return { payload: outputArray };\n}\n\n// オブジェクトが存在しない場合\nreturn msg; // または、適切な値に置き換えてください\n&quot;,&quot;outputs&quot;:1,&quot;timeout&quot;:0,&quot;noerr&quot;:0,&quot;initialize&quot;:&quot;&quot;,&quot;finalize&quot;:&quot;&quot;,&quot;libs&quot;:[],&quot;x&quot;:420,&quot;y&quot;:440,&quot;wires&quot;:[[&quot;c63a4178e013945a&quot;,&quot;9808b62ad6efd084&quot;]]},{&quot;id&quot;:&quot;9808b62ad6efd084&quot;,&quot;type&quot;:&quot;function&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;16進数文字列の作成&quot;,&quot;func&quot;:&quot;const data = msg.payload;\nvar fixdata = '';\n\nfor (let i = 0; i &amp;lt; 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&quot;,&quot;outputs&quot;:1,&quot;timeout&quot;:0,&quot;noerr&quot;:0,&quot;initialize&quot;:&quot;&quot;,&quot;finalize&quot;:&quot;&quot;,&quot;libs&quot;:[],&quot;x&quot;:500,&quot;y&quot;:500,&quot;wires&quot;:[[&quot;214c46e17afd8593&quot;,&quot;89862c16ce1bf864&quot;,&quot;cc9ff6ef8fea56f6&quot;]]},{&quot;id&quot;:&quot;89862c16ce1bf864&quot;,&quot;type&quot;:&quot;function&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;データ整理&quot;,&quot;func&quot;:&quot;const data = msg.payload;\nconst jsonData = {\n CompanyID: data.substring(0, 4),\n Relay: data.substring(4, 6),\n Voltage: data.substring(6, 10),\n Current: data.substring(10,14),\n Power: data.substr(14)\n};\nmsg.payload = jsonData;\nreturn msg;&quot;,&quot;outputs&quot;:1,&quot;timeout&quot;:0,&quot;noerr&quot;:0,&quot;initialize&quot;:&quot;&quot;,&quot;finalize&quot;:&quot;&quot;,&quot;libs&quot;:[],&quot;x&quot;:550,&quot;y&quot;:560,&quot;wires&quot;:[[&quot;83d1419df816a62d&quot;]]},{&quot;id&quot;:&quot;c63a4178e013945a&quot;,&quot;type&quot;:&quot;debug&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;Debug2&quot;,&quot;active&quot;:false,&quot;tosidebar&quot;:true,&quot;console&quot;:false,&quot;tostatus&quot;:false,&quot;complete&quot;:&quot;payload&quot;,&quot;targetType&quot;:&quot;msg&quot;,&quot;statusVal&quot;:&quot;&quot;,&quot;statusType&quot;:&quot;auto&quot;,&quot;x&quot;:620,&quot;y&quot;:440,&quot;wires&quot;:[]},{&quot;id&quot;:&quot;214c46e17afd8593&quot;,&quot;type&quot;:&quot;debug&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;Debug3&quot;,&quot;active&quot;:false,&quot;tosidebar&quot;:true,&quot;console&quot;:false,&quot;tostatus&quot;:false,&quot;complete&quot;:&quot;payload&quot;,&quot;targetType&quot;:&quot;msg&quot;,&quot;statusVal&quot;:&quot;&quot;,&quot;statusType&quot;:&quot;auto&quot;,&quot;x&quot;:700,&quot;y&quot;:500,&quot;wires&quot;:[]},{&quot;id&quot;:&quot;83d1419df816a62d&quot;,&quot;type&quot;:&quot;debug&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;Debug4&quot;,&quot;active&quot;:false,&quot;tosidebar&quot;:true,&quot;console&quot;:false,&quot;tostatus&quot;:false,&quot;complete&quot;:&quot;payload&quot;,&quot;targetType&quot;:&quot;msg&quot;,&quot;statusVal&quot;:&quot;&quot;,&quot;statusType&quot;:&quot;auto&quot;,&quot;x&quot;:740,&quot;y&quot;:560,&quot;wires&quot;:[]},{&quot;id&quot;:&quot;3c45542dd9e57d7b&quot;,&quot;type&quot;:&quot;change&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;&quot;,&quot;rules&quot;:[{&quot;t&quot;:&quot;set&quot;,&quot;p&quot;:&quot;payload&quot;,&quot;pt&quot;:&quot;msg&quot;,&quot;to&quot;:&quot;payload.other&quot;,&quot;tot&quot;:&quot;msg&quot;}],&quot;action&quot;:&quot;&quot;,&quot;property&quot;:&quot;&quot;,&quot;from&quot;:&quot;&quot;,&quot;to&quot;:&quot;&quot;,&quot;reg&quot;:false,&quot;x&quot;:420,&quot;y&quot;:300,&quot;wires&quot;:[[&quot;b2bfbfa05011dfdc&quot;,&quot;689b9264a475faa0&quot;]]},{&quot;id&quot;:&quot;b2bfbfa05011dfdc&quot;,&quot;type&quot;:&quot;debug&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;Debug5&quot;,&quot;active&quot;:false,&quot;tosidebar&quot;:true,&quot;console&quot;:false,&quot;tostatus&quot;:false,&quot;complete&quot;:&quot;payload&quot;,&quot;targetType&quot;:&quot;msg&quot;,&quot;statusVal&quot;:&quot;&quot;,&quot;statusType&quot;:&quot;auto&quot;,&quot;x&quot;:620,&quot;y&quot;:300,&quot;wires&quot;:[]},{&quot;id&quot;:&quot;689b9264a475faa0&quot;,&quot;type&quot;:&quot;switch&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;リレーの状態&quot;,&quot;property&quot;:&quot;payload[2]&quot;,&quot;propertyType&quot;:&quot;msg&quot;,&quot;rules&quot;:[{&quot;t&quot;:&quot;eq&quot;,&quot;v&quot;:&quot;0x01&quot;,&quot;vt&quot;:&quot;num&quot;},{&quot;t&quot;:&quot;eq&quot;,&quot;v&quot;:&quot;0x00&quot;,&quot;vt&quot;:&quot;num&quot;}],&quot;checkall&quot;:&quot;true&quot;,&quot;repair&quot;:false,&quot;outputs&quot;:2,&quot;x&quot;:240,&quot;y&quot;:140,&quot;wires&quot;:[[&quot;5306cee084a59eb3&quot;],[&quot;b59bc918e109da0c&quot;]]},{&quot;id&quot;:&quot;5306cee084a59eb3&quot;,&quot;type&quot;:&quot;change&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;&quot;,&quot;rules&quot;:[{&quot;t&quot;:&quot;set&quot;,&quot;p&quot;:&quot;relay&quot;,&quot;pt&quot;:&quot;msg&quot;,&quot;to&quot;:&quot;ON&quot;,&quot;tot&quot;:&quot;str&quot;}],&quot;action&quot;:&quot;&quot;,&quot;property&quot;:&quot;&quot;,&quot;from&quot;:&quot;&quot;,&quot;to&quot;:&quot;&quot;,&quot;reg&quot;:false,&quot;x&quot;:450,&quot;y&quot;:120,&quot;wires&quot;:[[&quot;b7d0c77263ccc701&quot;,&quot;4c7d4c659763cd1a&quot;]]},{&quot;id&quot;:&quot;b59bc918e109da0c&quot;,&quot;type&quot;:&quot;change&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;&quot;,&quot;rules&quot;:[{&quot;t&quot;:&quot;set&quot;,&quot;p&quot;:&quot;relay&quot;,&quot;pt&quot;:&quot;msg&quot;,&quot;to&quot;:&quot;OFF&quot;,&quot;tot&quot;:&quot;str&quot;}],&quot;action&quot;:&quot;&quot;,&quot;property&quot;:&quot;&quot;,&quot;from&quot;:&quot;&quot;,&quot;to&quot;:&quot;&quot;,&quot;reg&quot;:false,&quot;x&quot;:450,&quot;y&quot;:160,&quot;wires&quot;:[[&quot;b7d0c77263ccc701&quot;,&quot;4c7d4c659763cd1a&quot;]]},{&quot;id&quot;:&quot;b7d0c77263ccc701&quot;,&quot;type&quot;:&quot;ui_text&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;group&quot;:&quot;cf6fb9f48fc8a071&quot;,&quot;order&quot;:6,&quot;width&quot;:0,&quot;height&quot;:0,&quot;name&quot;:&quot;&quot;,&quot;label&quot;:&quot;リレーの状態&quot;,&quot;format&quot;:&quot;{{msg.relay}}&quot;,&quot;layout&quot;:&quot;row-spread&quot;,&quot;className&quot;:&quot;&quot;,&quot;style&quot;:false,&quot;font&quot;:&quot;&quot;,&quot;fontSize&quot;:16,&quot;color&quot;:&quot;#000000&quot;,&quot;x&quot;:920,&quot;y&quot;:140,&quot;wires&quot;:[]},{&quot;id&quot;:&quot;4c7d4c659763cd1a&quot;,&quot;type&quot;:&quot;function&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;電圧の計算&quot;,&quot;func&quot;:&quot;const data = (msg.payload[4]<em>255 + msg.payload[3])/10;\n\nmsg.voltage = data;\nreturn msg;&quot;,&quot;outputs&quot;:1,&quot;timeout&quot;:0,&quot;noerr&quot;:0,&quot;initialize&quot;:&quot;&quot;,&quot;finalize&quot;:&quot;&quot;,&quot;libs&quot;:[],&quot;x&quot;:650,&quot;y&quot;:220,&quot;wires&quot;:[[&quot;2cb4cff67669c961&quot;,&quot;25f2f36e31340b55&quot;,&quot;9bb07dc2debd9ff5&quot;]]},{&quot;id&quot;:&quot;2cb4cff67669c961&quot;,&quot;type&quot;:&quot;debug&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;debug 26&quot;,&quot;active&quot;:false,&quot;tosidebar&quot;:true,&quot;console&quot;:false,&quot;tostatus&quot;:false,&quot;complete&quot;:&quot;voltage&quot;,&quot;targetType&quot;:&quot;msg&quot;,&quot;statusVal&quot;:&quot;&quot;,&quot;statusType&quot;:&quot;auto&quot;,&quot;x&quot;:840,&quot;y&quot;:200,&quot;wires&quot;:[]},{&quot;id&quot;:&quot;25f2f36e31340b55&quot;,&quot;type&quot;:&quot;ui_text&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;group&quot;:&quot;cf6fb9f48fc8a071&quot;,&quot;order&quot;:6,&quot;width&quot;:0,&quot;height&quot;:0,&quot;name&quot;:&quot;&quot;,&quot;label&quot;:&quot;電圧&quot;,&quot;format&quot;:&quot;{{msg.voltage}} V&quot;,&quot;layout&quot;:&quot;row-spread&quot;,&quot;className&quot;:&quot;&quot;,&quot;style&quot;:false,&quot;font&quot;:&quot;&quot;,&quot;fontSize&quot;:16,&quot;color&quot;:&quot;#000000&quot;,&quot;x&quot;:830,&quot;y&quot;:240,&quot;wires&quot;:[]},{&quot;id&quot;:&quot;9bb07dc2debd9ff5&quot;,&quot;type&quot;:&quot;function&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;電流の計算&quot;,&quot;func&quot;:&quot;const data = (msg.payload[6]</em>255 + msg.payload[5])/10;\n\nmsg.current = data;\nreturn msg;&quot;,&quot;outputs&quot;:1,&quot;timeout&quot;:0,&quot;noerr&quot;:0,&quot;initialize&quot;:&quot;&quot;,&quot;finalize&quot;:&quot;&quot;,&quot;libs&quot;:[],&quot;x&quot;:810,&quot;y&quot;:300,&quot;wires&quot;:[[&quot;d721a16e5e24606d&quot;,&quot;071be9c46632f286&quot;,&quot;3470c16d46fde983&quot;]]},{&quot;id&quot;:&quot;d721a16e5e24606d&quot;,&quot;type&quot;:&quot;debug&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;debug 27&quot;,&quot;active&quot;:false,&quot;tosidebar&quot;:true,&quot;console&quot;:false,&quot;tostatus&quot;:false,&quot;complete&quot;:&quot;current&quot;,&quot;targetType&quot;:&quot;msg&quot;,&quot;statusVal&quot;:&quot;&quot;,&quot;statusType&quot;:&quot;auto&quot;,&quot;x&quot;:1000,&quot;y&quot;:280,&quot;wires&quot;:[]},{&quot;id&quot;:&quot;071be9c46632f286&quot;,&quot;type&quot;:&quot;ui_text&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;group&quot;:&quot;cf6fb9f48fc8a071&quot;,&quot;order&quot;:6,&quot;width&quot;:0,&quot;height&quot;:0,&quot;name&quot;:&quot;&quot;,&quot;label&quot;:&quot;電流&quot;,&quot;format&quot;:&quot;{{msg.current}} mA&quot;,&quot;layout&quot;:&quot;row-spread&quot;,&quot;className&quot;:&quot;&quot;,&quot;style&quot;:false,&quot;font&quot;:&quot;&quot;,&quot;fontSize&quot;:16,&quot;color&quot;:&quot;#000000&quot;,&quot;x&quot;:990,&quot;y&quot;:320,&quot;wires&quot;:[]},{&quot;id&quot;:&quot;3470c16d46fde983&quot;,&quot;type&quot;:&quot;function&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;電力の計算&quot;,&quot;func&quot;:&quot;const data = (msg.payload[9] * 255 * 16 + msg.payload[8]*255 + msg.payload[7])/1000;\n\nmsg.power = data;\nreturn msg;&quot;,&quot;outputs&quot;:1,&quot;timeout&quot;:0,&quot;noerr&quot;:0,&quot;initialize&quot;:&quot;&quot;,&quot;finalize&quot;:&quot;&quot;,&quot;libs&quot;:[],&quot;x&quot;:970,&quot;y&quot;:380,&quot;wires&quot;:[[&quot;df908ffde1aac32d&quot;,&quot;6d803af0d65ef315&quot;,&quot;5423597d4b564df5&quot;]]},{&quot;id&quot;:&quot;df908ffde1aac32d&quot;,&quot;type&quot;:&quot;debug&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;name&quot;:&quot;debug 28&quot;,&quot;active&quot;:false,&quot;tosidebar&quot;:true,&quot;console&quot;:false,&quot;tostatus&quot;:false,&quot;complete&quot;:&quot;power&quot;,&quot;targetType&quot;:&quot;msg&quot;,&quot;statusVal&quot;:&quot;&quot;,&quot;statusType&quot;:&quot;auto&quot;,&quot;x&quot;:1140,&quot;y&quot;:360,&quot;wires&quot;:[]},{&quot;id&quot;:&quot;6d803af0d65ef315&quot;,&quot;type&quot;:&quot;ui_text&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;group&quot;:&quot;cf6fb9f48fc8a071&quot;,&quot;order&quot;:6,&quot;width&quot;:0,&quot;height&quot;:0,&quot;name&quot;:&quot;&quot;,&quot;label&quot;:&quot;電力&quot;,&quot;format&quot;:&quot;{{msg.power}} W&quot;,&quot;layout&quot;:&quot;row-spread&quot;,&quot;className&quot;:&quot;&quot;,&quot;style&quot;:false,&quot;font&quot;:&quot;&quot;,&quot;fontSize&quot;:16,&quot;color&quot;:&quot;#000000&quot;,&quot;x&quot;:1130,&quot;y&quot;:400,&quot;wires&quot;:[]},{&quot;id&quot;:&quot;cc9ff6ef8fea56f6&quot;,&quot;type&quot;:&quot;ui_text&quot;,&quot;z&quot;:&quot;9892657eac51d18d&quot;,&quot;group&quot;:&quot;cf6fb9f48fc8a071&quot;,&quot;order&quot;:6,&quot;width&quot;:0,&quot;height&quot;:0,&quot;name&quot;:&quot;&quot;,&quot;label&quot;:&quot;Rawdata&quot;,&quot;format&quot;:&quot;{{msg.payload}}&quot;,&quot;layout&quot;:&quot;row-spread&quot;,&quot;className&quot;:&quot;&quot;,&quot;style&quot;:false,&quot;font&quot;:&quot;&quot;,&quot;fontSize&quot;:16,&quot;color&quot;:&quot;#000000&quot;,&quot;x&quot;:920,&quot;y&quot;:540,&quot;wires&quot;:[]},{&quot;id&quot;:&quot;cf6fb9f48fc8a071&quot;,&quot;type&quot;:&quot;ui_group&quot;,&quot;name&quot;:&quot;ratoc_btwattch2&quot;,&quot;tab&quot;:&quot;4e6203f8b7533ede&quot;,&quot;order&quot;:4,&quot;disp&quot;:true,&quot;width&quot;:&quot;6&quot;,&quot;collapse&quot;:false,&quot;className&quot;:&quot;&quot;},{&quot;id&quot;:&quot;4e6203f8b7533ede&quot;,&quot;type&quot;:&quot;ui_tab&quot;,&quot;name&quot;:&quot;ratok&quot;,&quot;icon&quot;:&quot;dashboard&quot;,&quot;disabled&quot;:false,&quot;hidden&quot;:false}]

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

本来は不要ですが、ここではRS-BTWATTCH2の仕様書通りに16進数の文字列等(生データ)を作成しています。

残りのノードでは、実際に各データを仕様書通りに読み分け、計算の必要な個所ではfunctionノードで処理をしています。

それぞれダッシュボード上に表示させています。

ダッシュボードでの表示

各データがこのように可視化されます。