前提・実現したいこと
BLEを探して、発見次第RSSIをcsvファイルに書き出そうとしているのですが、エラーもないままファイルに書き出しがない状態です。
非同期処理が原因でしょうか。
分かる方がいましたら、回答お願いします。
発生している問題・エラーメッセージ
(base) ~/rssi_sample $ node rssi_sample.js (node:25978) Warning: N-API is an experimental feature and could change at any time. BLE Device Found: undefined(268047b36dc94276a8dad064bf63fd5f) RSSI-11 BLE Device Found: undefined(35bc1bc68df1451ea4633ca8710e44a7) RSSI-44 BLE Device Found: undefined(39c156b11b424e2aa95ca2786e97ac65) RSSI-81 BLE Device Found: undefined(cbd3a134f8784c238a8250702d29c7a5) RSSI-88 BLE Device Found: undefined(6d847f4a481946fc8e58cdaa83b9f503) RSSI-92 BLE Device Found: undefined(fe9ccdb4d1884857a3e4e319dc8d6706) RSSI-77
該当のソースコード
'use strict'; const noble = require('noble-mac'); const fs = require('fs'); const csv = require('csv'); //BLE deviceをさがす。 const discovered = (peripheral) => { console.log(`BLE Device Found: ${peripheral.advertisement.localName}(${peripheral.uuid}) RSSI${peripheral.rssi}`); csv.stringify(peripheral.rssi, (error, output) => { fs.writeFile('out.csv', output, (error) => { console.log('処理データをCSV出力しました。'); }) }) if (peripheral.advertisement.localName === 'ESP32_02') { noble.stopScanning(); console.log('device found'); console.log(`service discover...`); } } //スキャン開始 const scanStart = () => { noble.startScanning(); noble.on('discover', discovered); } if (noble.state === 'poweredOn') { scanStart(); } else { noble.on('stateChange', scanStart); }
補足情報(FW/ツールのバージョンなど)
node v8.9.4
あなたの回答
tips
プレビュー