MQTT, Arduino, Old Ammeters and Bandwidth Monitoring
11 Mar 2010Thanks to some help from @knolleary the arduino pubsub library now works with mosquitto. I have now completed my bandwidth monitor project which I want to document in this post.
I have mentioned in previous posts that I use various scripts and sensors to feed data into the open source MQTT broker mosquitto. Currently all data is posted to pachube, rather than everything being online I decided I wanted some physical feedback. Having made an impulse buy of two vintage Ferranti ammeters using these to display some of my data seemed like obvious answer! The code on the arduino basically just displays a number passed by MQTT on the meter and therefore could be applied to any measurement one cared to choose.
The basic idea of this system is to monitor the current internet speed usage and display it on the ammeter. The system is based around an arduino with ethernet shield which acts as an MQTT client, this subscribes to the downstream bandwidth topic on my MQTT broker, receives the messages and changes the level of a PWM output pin on the arduino which causes the meter to show the appropriate level. The meter displays the current through a resistor which is varied by the PWM signal from the arduino. The reading on the meter corresponds to the current internet speed usage as a percentage of the overall theoretical available bandwidth.
The Arduino Code
As this is quite well commented I won’t go through it, but it serves as a good example of how to receive MQTT messages using an arduino:
The PHP script that provides the bandwidth data resides on my sheevaplug and queries my router for an XML file with the appropriate details, I talked about this in a previous post.