Friday 30 December 2022

Internet Speed test Application for Windows

Introduction

I like to write software as a bit of a hobby. I use Microsoft C#  Visual Studio and have written a small  number of (Windows) applications for my own use. These are always a "work in progress" and each application uses code from previous applications

My latest application is a Windows application wrapper around the Ookla Speedtest CLI application (I know there is an official Ookla Windows application here) but where's the fun in that? Has mixed reviews on the Windows Store as well to be honest.

Ookla (here) do the internet speed tester. The reason for this was that recently we moved from ADSL (copper wire) broadband (at typically 30-50Mbps) to BT full fibre at 500Mbps and I obviously wanted to check I was getting what I paid for

The initial tests using the web page version showed that at times I was getting 500Mbps download but this was very variable (I was not rigorous enough to test whilst ensuring no other devices were using the internet). Upload speeds were very consistent at about 70Mbps.

Here's an example:

What I could not tell reliably was how did this vary and by what amount. I decided that what I'd do was put a Windows wrapper wound the Ookla CLI version

This can be downloaded from here:


This page describes the software that I wrote

The Code

In this case I also took some time to prepare a proper class library - I have quite a few classes that I re-use (these are: an SQL database class, an application logger class, a general utilities class, a DataTable handling class, a Process Class and a few other miscellaneous classes). I realised that my existing method of copying the last version of the class to the new project did not work and I never copied the updates back. Now that I have a Class Library, this is a much better solution and I used it on a 2nd project at the same time (this was to address some database creation issues I had) and the code worked for both projects.

It took some effort to work out how to do this - for example I had not realised that it was a "code only" class and and Windows  forms (for example) could not be included. I am assuming that I can create a Windows forms class library. In terms of the SQL code I spent a lot of time trying to simplify the code and break up into smaller classes with some inherited behaviour. This has improved the code but it needs more work

I run the speed test by spawning it as a Process, intercepting the STDOUT and parsing it (this

I also wanted the application to be responsive during the speed test - once the Process class started the execution the application hung until the test was completed - for up to 25-30 seconds. This was not good. To fix this I used a background worker thread (actually I used 2 - one for the speed test and the other to monitor completion and allow aborting the test). This was a new area of code for me. Using these background worker threads showed another issue that this was a sperate thread so I could not get results or interact - this was fixed with creating some delegates to update a DataGridview, update progress bars etc. Not quite sure what delegates do (I need to do some more reading) but it works. Thanks to Stackoverflow for all this.

Installing the software

Before you install this application you need to down load the Ookla Windows CLI file from here. Download and extract the exe file to a location of your choice

You can test the code manually if you like. Open a Command prompt, change directory to the location of speedtest.exe and type speedtest.exe.


Note that the first time you run the Ookla CLI application it asks you to accept the licence terms and GPDR terms. My application checks if this has been already done. If it has it moves on, if it has not it accepts them on your behalf.

My application is here on my Google drive. Download and extract the zip file to get the installer:


Double click on Setup. You'll get the unsigned warning


I have not signed the code but from my drive it should be "safe". Here's the file info at the point I uploaded it:


Running the Application

When the application first runs it needs to know where the Ookla Speedtest cli exe file is. A standard File Open dialog box will appear to allow you to set the path for this. The title of the dialog box is "Locate the Speedtest.exe file"




Double clicking the file or selecting it and pressing "Open" registers the path. It also checks that it is called "speedtest.exe".

It will then create an SQL database to hold the results (in C:\Users\<User>\AppData\Local\Speed_Test) where <User> is your user account.

It creates an ini file for settings in the Application's Environment.SpecialFolder.ApplicationData folder. This is really hard to find so there is a means to get this easily from the application itself (see below). It also creates a log file (appliocation.txt) in the same folder

Assuming this is successful the main form will open:


To look at the database folder use the Miscellaneous menu:


You can select "Show Application folder" for the log file and the ini file or "Show database folder" for the database files

Finally select "Show Application messages" to look at application messages:


To get a speed test press the "Do a Speed test" Button:


At the end of the test you'll see some Stats data (best, worst, average results etc) and the individual results:


Until you have 3 results there will only be a line chart. Once there are 3 results or more there are also some histograms for upload and download:


You can run an automated Speedtest every 2 minutes using the "Start Auto Speed test" button.

Note that there is a 30 second timeout for the Speedtest to complete within. If your machine is timing out you will need to edit the setting in the ini file. Open the folder (Miscellaneous Settings, Show Application Folder) and double click on Speed_test.ini:


You'll see this:

[Database_Properties]
Database_Path=C:\Users\<User>\AppData\Local\Speed_Test
Database_Name=Speed_Test
[Executable_Properties]
Executable_Path=L:\Visual Studio\Speed_Test\Speed_Test\bin\Debug
Executable_Name=speedtest.exe
[Log_Properties]
Log_Path=C:\Users\<User>\AppData\Local\Speed_Test
Log_Name=log.txt
[Timer_Properties]
Timer_Value=30000

Change Timer_Value to a longer value if needed. Note that this is seconds x 1000, so if you want 45 seconds enter:
Timer_Value=45000

You'll also have your User name instead of <User>

Save the file and restart the application

These graphs look better with more results:



There are tooltips on the graphs. On the line graph hovering a mouse over a point will give the speed and date/time of the result:




Right clicking on the lower DataGridview will allow you to export the results as tsv (Tab Separated Values - because some Server names contain a "," symbol):


Here's an example output of the export:



If there are issues you can review the application.txt file and send it to me via this Blog:

This file is appended which each run of the application so can get large. If there are no issues it can be deleted (as long as the application is not running at the time) and it will be recre4ated next time the application starts.