java - 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.
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.
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);
}
解决方案
推荐阅读
- r - 数据框中的错误:选择了未定义的列
- sql - sql查询结果格式
- java - 如何使用@RequestParam 将数组的默认值设置为空
- javascript - 慢慢自动滚动到 div 的底部
- java - 如何在片段中放置或替换列表
- java - Docker 容器中的 AWS SAM CLI 导致 ClassNotFoundException
- email - Auth0:让用户重新发送验证邮件
- c# - 无法将 Entity Framework Core 迁移添加到 .NET Standard 2.0 项目
- python - 将 PIL.Image.image 显示到散景 hoovertool
- ubuntu - 从外部/远程机器访问 VerneMQ 状态和指标