# Internet Speedometer

Back to overview

A fun way to monitor your internet traffic!

• 1
Calculating Full-scale Deflection Current

Skip this step if you already know the full-scale deflection current for your meter. My meter had no mention of it so I had to calculate. But first, let us quickly see how does such a movement work. It consists of a coil suspended in a magnetic field. When current flows through the coil, according to Faraday's law, it experiences a force. The coil is allowed to rotate freely in the magnetic field and so does the pointer which is attached to the coil. The magnitude of current which makes the pointer move at the 'end of the scale' is called full-scale deflection current. This is also the maximum current which must be allowed to flow through the coil.

There's a lot more going on but this is enough for what we are doing. We now have the movement. It can be used as a voltmeter by adding a high resistance in series with it or as an Ammeter by adding a small resistance in parallel to it. We will be using it as a voltmeter to display the voltage proportional to the internet speed. So, we need to calculate the resistance which is to be added in series. For that, we first need to calculate the full-scale deflection current.

1. Choose a high resistance value (like >100k)
2. Connect it in series with the movement and apply a variable voltage across it using the pot.
3. Keep increasing the voltage slowly till the pointer reaches the end of the scale.
4. Using a multimeter, measure the current flowing through. This is the full-scale deflection current. (I = 150uA in my case)

We are using a DAC which has the output voltage range from 0 to VCC (3.3V due to NodeMCU). This means that when 3.3V is applied to the meter, it should point at the end of the scale. This can happen when full-scale deflection current flows through the circuit when 3.3V is applied. Using Ohm's Law, 3.3/(full-scale deflection current) gives the value to resistance to be inserted in series.

• 2
Creating SNMP GET Request

Simple Network Management Protocol (SNMP) is an Internet Standard protocol for collecting and organizing information about managed devices on IP networks and for modifying that information to change device behavior. Devices that typically support SNMP include cable modems, routers, switches, servers, workstations, printers, and more. For this build, we will be communicating with our WiFi Router using SNMP and get the required data.

But first, we need to send a request known as a 'GET Request' to the router mentioning the details of the data which we want. GET Request format is shown in the picture. The request consists of various parts. I have highlighted the bytes which you might want to change.

SNMP Message -In my case, the length of the entire message is 40 (grey color) which when converted to hexadecimal is 0x28.

SNMP Community String - The value 'PUBLIC' is written in hexadecimal as '70 75 62 6C 69 63' whose length is 6 (yellow).

SNMP PDU Type - In my case, the length of the message is 27 (blue) i.e. 0x1B.

Varbind List Type - In my case, the length of the message is 16 (green) i.e. 0x10.

Varbind Type - In my case, the length of the message is 14 (pink) i.e. 0x0E.

Object Identifier -

As mentioned earlier, SNMP-enabled network devices (e.g. routers, switches, etc.) maintains a database of system status, availability, and performance information as objects, identified by OIDs. You need to identify the OIDs of your router for Upload and Download packets. It can be done using a free MIB Browser like this one.

Enter Address as 192.168.1.1 and OID as .1.3.6.1.2.1.2.2.1.10.x (ifInOctets) or .1.3.6.1.2.1.2.2.1.16.x. (ifOutOctets)Select Get operation and click on Go. You should see the OID along with its value and type.

In my case, the length of the message is 10 (red) i.e. 0x0A. Replace the value with the OID. In this case, '2B 06 01 02 01 02 02 01 10 10'

That's it! Your request message is ready. Keep the rest of the bytes as they are.

Turning ON SNMP on your router:

• Log on to your WiFi router's page through the default gateway. Type 192.168.1.1 in your browser and press enter. By default, the username and password should be 'admin'.
• I am using a TP-LINK (TD-W8961N) router. For this router, you have to go to Access Management > SNMP and select 'Activated'.
• GET Community: public
• Trap host: 0.0.0.0
• 3
Understanding GET Response

You can skip this step, but it's good to know if you need to do some troubleshooting.

Once you upload the code and run it, you can take a look at the response through the Serial monitor. It should look like as shown in the picture. There are a few bytes you need to look for which I have highlighted.

Starting from 0,

15th byte tells the PDU Type - 0xA2 means that it is a GetResponse.

48th byte tells the data type - 0x41 means that the data type is Counter.

49th byte tells the length of data - 0x04 means that the data is 4 bytes long.

Byte 50, 51, 52, 53 contains the data.

• 4
Digital to Analog Converter (DAC)

Microcontrollers are digital devices that do not understand Analog voltages directly. I am using an analog meter that needs a variable voltage as the input. But microcontroller can just output HIGH (3.3V in case of NodeMCU) and LOW (0V). Now you might say why don't just use PWM. It won't work since the meter will only display the average value.

I am using MCP4725 DAC to get variable voltage. It is a 12-bit DAC i.e. in simple terms, it will divide 0 to 3.3V into 4096 (= 2^12) parts. The resolution will be 3.3/4096 = 0.8056mV. This means that 0 corresponds to 0V, 1 corresponds to 0.8056mV, 2 corresponds to 1.6112mV,....., 4095 corresponds to 3.3V.

The internet speed will be 'mapped' from '0 to 7 mbps' to '0 to 4095' and then this value will be given to DAC to output a voltage which will be proportional to internet speed.

• 5
The Assembly

Connections are very simple. The schematic has been attached here.

I designed and printed the scale. The upper one is for download speed and the lower one is for upload speed. I glued the new scale over the old one.

I removed all the old stuff from the multimeter and I crammed everything in it. It was a tight fit. I had to drill a hole in the front to attach the toggle switch which is used to select between upload and download speed.

• 6
Time for Coding

The code has been attached here. Download and open it in Arduino IDE. Install the MCP4725 library from Adafruit.