首页 > 解决方案 > Timestamp for WiFi scanning

问题描述

I would like to implement apps that I could scan the WiFi Mac address and get its RSSI and Timestamp. For example, the first Timestamp will give me all the RSSI values of each Mac address. Those undetected RSSI signals will have empty cells. Similarly, the next timestamp will give me all the RSSI signals for the detected Mac address. The expected CSV should be below.

enter image description here

However, when I save the file, it gave me the result like this. Also, I have some difficulty to transpose the Mac Adress value in CSV file from row to column.

enter image description here

Here is the code. `private void scanWifiResult() { List wifiscan = wifiManager.getScanResults();

    for (ScanResult scanning : wifiscan) {
        String macAddress = String.valueOf(scanning.BSSID);
        Float RSS = Float.valueOf(scanning.level);
        ArrayList<Float> arrayOfRss = WifiNetworkWithRssi.get(macAddress);
        if (arrayOfRss == null) {
            arrayOfRss = new ArrayList<>();
            WifiNetworkWithRssi.put(macAddress, arrayOfRss);
            scanDataList.add(new ScanData(macAddress, System.currentTimeMillis(), arrayOfRss));
            scanDataList.add(new ScanData(macAddress, System.currentTimeMillis(), RSS));

        }
        if (tagMotion == false && arrayOfRss.size() > 1)
            RSS = (RSS + arrayOfRss.get(arrayOfRss.size() - 1)) / 2;
        arrayOfRss.add(((int) ((RSS + (RSS >= 0 ? 1 : -1) * 0.005f) * 100)) / 100f); 

        long actualTime = System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(SystemClock.elapsedRealtimeNanos() - scanning.timestamp, TimeUnit.NANOSECONDS);
      

enter code here

        String csvString = "";
    for(ScanData scanData : scanDataList) {
        csvString = scanData.getBssid()+","+scanData.getTimeStamp()+","+ TextUtils.join(",",scanData.getRssi()) + "\n";
        csvString = scanData.getBssid()+","+scanData.getTimeStamp()+","+ scanData.getLevel() + "\n";
        file_writer.append(csvString);
    }

标签: javatimestampwifirssi

解决方案


推荐阅读