speed-test-lib
speed-test-lib copied to clipboard
upload and download speed is off
Hello,
I'm trying to calculate the upload and download speed using the function startUploadRepeat
and startDownloadRepeat
and converting it from bits to mbps. However, when I run my application and try to calculate the two speeds, the numbers are super off? The upload speed is like 0.1 and the download speed is in the 100 range. I'm using report.getTransferRateBit() to get the rate and dividing it by 1,000,000 but the numbers are still extremely off. Can anyone help me with this? Here is my code:
SpeedTestSocket socketDown = new SpeedTestSocket();
socketDown.startUploadRepeat(server.getUrl(),
15000, 1000000, new IRepeatListener() {
@Override
public void onCompletion(final SpeedTestReport report) {
BigDecimal rate = report.getTransferRateBit();
BigDecimal divisor = BigDecimal.valueOf(1000000);
rate = rate.divide(divisor);
download.add(rate);
String rateString = "";
rateString = rateString + rate;
data.setDownload(rateString);
uploadData();
double num = 0.0000;
BigDecimal total = new BigDecimal(0.0000000);
for(BigDecimal value: download) {
num++;
total = total.add(value);
}
double dbTotal = total.doubleValue();
final double average = dbTotal / num;
runOnUiThread(new Runnable() {
@Override
public void run() {
TextView downText = findViewById(R.id.textViewTableDown);
downText.setText("" + average);
changeButton();
}
});
Log.v("test", "DOWNLOAD SPEED: " + rateString);
}
@Override
public void onReport(final SpeedTestReport report) {
BigDecimal rate = report.getTransferRateBit();
BigDecimal divisor = BigDecimal.valueOf(1000000);
rate = rate.divide(divisor);
download.add(rate);
String rateString = "";
rateString = rateString + rate;
data.setDownload(rateString);
Log.v("test", "DOWNLOAD SPEED, R: " + rateString);
}
});
Also I'm putting all of this data in firebase, which is what the uploadData()
function does. Any help will be greatly appreciated.
same after updating my phone to android 8.1.0