This “Internet Speed Gauge” will give you near real time oversight of your network usage. This information is available on the web interface of most home routers. However, accessing it requires you to stop your current task to go look it up.
I wanted to view this information without having to interrupt my current task, to display it in a format that was understandable with just a quick glance, and to get the information in a way that would work with as many routers as possible, so others could potentially use it too.
How it does the things
I decided on SNMP (Simple Network Management Protocol) as the way to get the information from the router. SNMP is widely used in networking equipment and if your device does not support it by default DDWRT (open source router firmware) can be used to implement SNMP.
To display the information in a way that is easy to understand I used a gauge from a car. Automotive gauges are designed to give you information without being distracting or confusing, so the driver can keep their eyes on the road. Also, I had some laying around.
Since this would be on my desk I decided I would also make the back light RGB because computer accessories should all be RGB. Right?
The gauges that I had use an Air-Core actuator. I had never heard of these before this project.
From Wikipedia: The air core gauge consists of two independent, perpendicular coils surrounding a hollow chamber. A needle shaft protrudes into the chamber, where a permanent magnet is affixed to the shaft. When current flows through the perpendicular coils, their magnetic fields superimpose, and the magnet is free to align with the combined fields.
I was unable to find a library for Arduino that supported SNMP in the manager configuration. SNMP has two main forms, agent and manager. Agents respond to request and managers send request to agents. I was able to get manager functionality working by modifying the Arduino_SNMP library created by 0neblock. I have never programed in C++ other than making LED’s blink on an Arduino so if there are issues with the SNMP library let me know and I’ll try to fix them, for now it is working though.
Additionally, SNMP is not designed for real time viewing. The intended use is for tracking statistics and detecting outages. Because of this, the info on the router is only updated about every 5 seconds (your device may vary). That is the cause of the delay between the number on the speed test and the needle moving.
Step 1: Tools and Materials
- Soldering iron
- Hand tools needed to remove gauge differ depending on what gauge you get but will likely be a Philips screw driver and a 10mm socket
- JST crimping tool (optional)
- 3d printer (optional)
- ESP32 dev board
- Dual H-bridge motor drivers (x2)
- Analog gauge from a car
- There are multiple mechanisms that manufacturers will use. We are going to be using an Air-Core style gauge
- 12v power source
- 5v power source
- 220 ohm resistors (x4)
- 2.2k ohm resistors (x4)
- 10k resistor
- NPN transistor (x4)
- RGB LED strip
- JST connectors
Step 2: Circuit Design
We will need 3 full H-bridges. The models I used are Dual TB6612FNG
and Dual L298N.
Each Air-Core actuator requires 2 full H-bridges because the coils need to be controlled independently.
One of the gauges I am using has one coil shorted to ground with a diode and resistor. I’m not sure of the science behind it but doing that allows it to rotate about 90 degrees with only one coil powered.
I will be using the 12v to 5v regulator that is part of the L298N board that I selected to power the ESP32.
All the LED circuitry is optional, as well as the JST connectors. You could easily solder the wires directly to ESP32 and motor driver.
Step 3: Code Design
We will need to setup Arduino to be able to use the ESP32 board. There is a good guide located here that will walk you through ESP32 Arduino setup.
You will also need the Arduino_SNMP library located here.
To configure the code, you will need to collect some information.
- Router IP
- Max upload speed
- Max download speed
- Your WiFi name and password
- OID that contains the octet counts for “in” and “out” on your routers WAN interface
There are standard OIDs (Object Identifiers) for the information we want. According to the MIB-2 standard the numbers we want are:
Where X is the number assigned to the interface you want to get the statistics from. For me that number is 3. One way to confirm that this is the correct OID for you and to identify what interface number you need to use, is to use a tool like MIB Browser.
To get max speeds I used SpeedTest.net. once you have your speeds in Mbps you will need to convert them into octets using this formula.
Octets per second = (Result from speed test in Mbps * 1048576) / 8
The code sends an SNMP get-request to the router. The router then replies with a number, the number represents the count of octets that have been sent or received. At the same time, we record the number of milliseconds that have passed since the Arduino started.
Once this process has happened at least twice we can calculate the percentage of usage based off our max values using this code
percentDown = ((float)(byteDown – byteDownLast)/(float)(maxDown*((millis() – timeLast)/1000))) * 100;
The math breaks down like this:
octetsDiff = snmp_result – Previous_ snmp_result
timeFrame = currentTime – timeLast
MaxPosableOverTime = (timeFrame * Octets_per_second)/1000
Percent = (octetsDiff / MaxPosableOverTime) * 100
Now that we have the percent of network usage we just need to write it to the gauge. We do that in 2 steps. First we use the updateDownloadGauge function. In this function we use “map” to convert the percentage to a number that represents a radian position on the gauge. Then we give that number to the setMeterPosition function to move the needle to the new position.
Step 4: Case Design
o contain everything, I designed an enclosure in fusion360 and 3Dprinted it. The design I made is relatively simple. I used hot glue to fasten the components to the inside and the gauge is held in place by being pinched between the front cover and the back cover. You do not need to use 3D printing to create the case. For example, you could make a case out of wood, or you could put everything back in the original case that the gauges came in.
My STL files are available on thingiverse if you want to look at them but it is unlikely they will work for you unless you get the exact same gauges I used.
Case files: https://www.thingiverse.com/thing:2932127
Thanks for reading. Let me know if you have any questions and I’ll do my best to answer.
Source: Internet Speed Gauge