Jan 09 2013

Bluetooth Net Monitor

A newer version of the Bluetooth network monitor can be read about here, but I’d recommend carrying on reading this post first.

Whenever I want to see why a download is going a little slow or getting lag on an online game I’d have to log in to my routers web page or SSH in to see if its someone else in the house downloading/uploading, the net connection going wonky or just the server, this was a bit annoying to do, so I made this device to constantly show network statistics.

Monitor
The monitor uses an ATmega328P @ 20MHz, 160×128 1.8″ colour LCD, a Bluetooth module, is powered by USB’s 5V, has a button for changing LCD brightness (long press) and display mode (short press) and since it’s powered by USB I added support for V-USB. The plastic part with everything screwed on to is an A8 paper display holder with the back clippy part removed and some rubber feet added.

The monitor has a few modes for displaying data:

Display mode 1

  • Down sync
  • Up sync
  • Down rate
  • Up rate
  • History graph for the past 25 seconds
  • Ping
  • Packet loss
  • WAN IP
  • Time
  • Email notification

Display mode 2

  • Down rate
  • Up rate
  • Large history graph for the past 40 seconds

I’ll probably add more display modes sometime, like showing CPU usage etc. from the PC that its getting power from by making use of V-USB.

netmonlabels

Getting the data
The router (my router is a PC running Debian Linux) runs a shell script which gets down and up speeds of the WAN interface, first hop ping, ping packet loss, WAN IP and everything else, it then sends this data to a serial port (which in this case it’s a USB-to-serial converter using a CP2102) with a serial Bluetooth module attached, data is then sent to the other Bluetooth module in the net monitor which is then displayed on the LCD.

To get modem down and up sync speed a CGI script is ran on the modem, normally you’d have to parse the ADSL status page of the modem, but since I’m running OpenWRT on my Netgear DG834Gv3 I just needed to make a small shell script to get the ADSL status from a /proc file, well there is still a little bit of parsing, but not as much as you’d have to do with a normal HTML status page.

Protocol
The protocol used is a very simple text based one
$|syncdown|syncup|ratedown|rateup|ping|loss|ip|emails|date|time|*

Example:
$|6100|1020|340|4|19|0|255.255.255.255|2|Wed 02 Jan 13|20:31:26|*

Special characters:
$ – Start of packet
* – End of packet
| – Delimiter to separate pieces of data

Other stuff
I might sometime code up a proper program in C instead of using a shell script, it’ll use up a lot less CPU time while running and make it possible/easier to use a more efficient binary protocol.

This was also my first experience with SMD parts (0805 size), I think it went very well, but little bit messy in some places, my future projects will probably be mostly SMD from now on.

DIGITAL CAMERA

I also made a small utility for converting the red channel of images into a byte array representing the intensity of each pixel, colour is added on-the-fly by the the controller based on the intensity, allowing multiple colours of the same image or font without using up extra flash space.

redchan

All the rendering takes quite a bit of processing time which is why the the chip is running at 20MHz, compiler settings and which compiler that is used also effects the performance, going from Atmel Studio 6’s default settings to using AVR-GCC 4.7.2, using these flags for the C compiler –
-O2 -fno-tree-scev-cprop -ffreestanding -mcall-prologues
and these flags for the linker –
-mrelax
reduces program size by around 2KB (now 16,836 bytes), saves 18 byes of RAM (now 301 bytes, that doesn’t count runtime stuff which tops at around 1KB) and gains a few extra FPS.
Using -Os instead of -O2 would give an even smaller code size, but at the cost of performance.


Sources available at GitHub


Video of the net monitor in early development – http://www.youtube.com/watch?v=W9UXh1g5AcA


Featured at
lifehacker, HackADay, Electronics Lab, Dangerous Prototypes

85 comments

4 pings

Skip to comment form

  1. This is GENIUS!!!! Is it for sale????

    1. These aren’t for sale, or at least not yet, see the comment about a Kickstarter below.

    • Konrad on January 11, 2013 at 4:46 pm
    • Reply

    Why is your WAN IP 255.255.255.255
    Is it not working correctly?

    1. Normally it wouldn’t be 255.255.255.255, I just manually set it to that while doing the video and taking pictures.

    • Matt M on January 11, 2013 at 7:10 pm
    • Reply

    Really nice project.
    Where did you have your PCB’s made and where did you get the LCD?

    1. The PCBs were made at OSH Park.
      The LCD is from eBay from a Chinese seller for around £8, search for “lcd module 1.8”, the LCD is meant for 3.3V so if you use 5V you’ll need to find a module with level conversion built in (which the one I’m using has) or you need to add it yourself with a load of resistor dividers/resistors + zeners.

  2. Simply beautiful! I’ve been looking to build something exactly like this – which is probably going to require that I switch from my Netgear router to a small box running Linux for the router. I wonder if it’s possible to run a router off of some of the new dev boards coming out – as I want to minimize the power draw of any constantly on device.

    Anyhow – beautiful build!

    • Trav on January 11, 2013 at 9:44 pm
    • Reply

    Looks great – what font did you use?

    1. Thanks, I used this font in bold italic.

    • James on January 12, 2013 at 10:53 am
    • Reply

    In the write up it says you use an ATMEGA328P but in the schematic it says it is an ATMEGA328, I am fairly new to microcontrollers, is there any difference between the ATMEGA328P and the ATMEGA328. I have been looking around on Digikey and was wondering since they list several part number such as the ATMEGA328P-AU-ND, ATMEGA328P-AURCT-ND and such, are each of these the same chip and programmable identically with the exception of the package type?

    1. The P means picoPower, it helps reduce power consumption in sleep mode by allowing you to disable brown out detection, but that feature isn’t used in this project. The P version counts as a different controller when you program for it, but the same code will work on both P and non-P, you will just have to remove any extra power saving features when you compile for the non-P version. The rest of the extra letters are the package type and how they are packaged, in a reel or tray, and don’t count as different controllers. All the ICs are programmed the same way, by SPI or if you’re using a boot loader then by UART.

    • Freddy on January 12, 2013 at 3:25 pm
    • Reply

    Nice one =) But where did you find the information, how to address such a display?

    1. The eBay seller for the LCD had a link to an Ardunio library called TFT18 which appears to use code by Rossum to get the display initialized (can’t find an official link, a bit more info about the display and the lib here), then to send image data its just a matter of setting a pin high and sending 2 bytes for each pixel.

        • Freddy on January 12, 2013 at 4:30 pm
        • Reply

        Ty =)

    • Bob H on January 14, 2013 at 12:48 pm
    • Reply

    You mention the script runs on your Debian router, I suppose you could easily run the script on the OpenWRT box directly and use the serial port on the router? Was just the lack of BT on the router the reason for this?

    1. The script could run on the OpenWRT modem and have the BT module connected to the serial port, but I think all the output when it starts up is also printed to the serial connection so I’m not sure what will happen there. It would still have to get some data from the router like the WAN IP and the PPP end point IP for it to ping. The router is also a full PC compaired to the low powered modem. If it’s just a normal modem/router with OpenWRT then gettting it working with the internal serial port shouldn’t be a problem.

    • Daniel Moore on January 14, 2013 at 12:55 pm
    • Reply

    What was the build time on this and can you make these for sale.

    1. Getting it built took less than a day since it was only drilling holes in the plastic for the screws and soldering the board, the part which took the most time was designing, coding and waiting for parts to arrive. I first came up with the idea way back in May 2012, but didn’t start on it until October and finally finished in January.
      These aren’t for sale, or at least not yet, see the comment about a Kickstarter below.

    • Daniel Moore on January 14, 2013 at 12:57 pm
    • Reply

    Reason i’m asking is I’m 72 years and that’s beyond my expertise and I like that.

    • ThatGuy on January 14, 2013 at 1:32 pm
    • Reply

    Hi forgive me i know very little about electronics but if i were to build such a project how would i go about adding a bigger display? im assuming its not as simple as just swapping them out?

    1. Yeah not quite that simple, the code and images are meant for a 160×128 display and the commands the display uses (for things like colour mode) will probably be different. A display with a higher resolution will also take longer to process things for. There are only a few files that would need changing though, lcd.c & .h and display.c

    • mike on January 14, 2013 at 2:16 pm
    • Reply

    Zak, have you thought of making this into a Kickstarter project and selling it? You’d have to find a way to make it work with the popular routers out there (most don’t offer shell access), but I’d buy one.

    1. Well, a Kickstarter definitely wasn’t something I was look at doing, I think I’ll have to spend a lot time getting it into a state where it can be manufactured which I don’t have at the moment because of university, but I finish in ~4 months so maybe then.

  3. Hi,

    nice little project. For me the biggest problem is smd! 🙂 How was your experience? Especially soldering the hole stuff.

    Keep on hacking,

    Mucki

    1. The IC was the first thing I tried to solder, trying to solder each pin individually didn’t work out well at all lol, so off to youtube to watch some videos about SMD soldering… putting loads of solder all over the IC pins then use a solder sucker or wick to get the excess solder off and you’re usually left with a nice set of soldered pins, sometimes the solder will bridge some pins and won’t want to come off, add a load more solder to the bridged pins and use the sucker/wick again.

      Use very small amounts of solder on the resistors and capacitors.

      A pair of tweezers helps a lot!

        • Freddy on January 14, 2013 at 6:51 pm
        • Reply

        Adding a lot of soldering flux can help, too. Solder two pins on diagonal sides, then add the flux and pull the soldering iron over the pins while adding solder to it =)

        1. Ah yes, but I didn’t have any flux around, I’ll be buying some for next time :p

    • Diego on January 14, 2013 at 3:47 pm
    • Reply

    Hello,

    Great project. Can you post some details about the specific bluetooth module you used?

    Thanks

    1. This post has more info about the modules, they’re from eBay from a Chinese seller.

    • darkvoid on January 27, 2013 at 1:09 pm
    • Reply

    Is there away to upload the files to the chip using windows?

    1. AVRDUDE is what I use to upload, it’s cross-platform.

        • darkvoid on January 28, 2013 at 12:20 pm
        • Reply

        Im new to this uploading to chips. I got Avrdude download. So is it the hex file im uploading? How does all the rest of the files get loaded?

        1. Yep, just the hex file needs to be uploaded, the rest of the files are the source files so you can change stuff.

          AVRDUDE command to upload hex file and set fuses:
          avrdude.exe -B 16 -c usbasp -p atmega328p -U lfuse:w:0xff:m -U hfuse:w:0xdf:m -U efuse:w:0xfc:m -U flash:w:(location of hex file)

            • darkvoid on January 28, 2013 at 4:00 pm

            So the avrdude you using is running in cmd? I found one called avrdude-gui. Seem it not locating the chip when i run hex file.

            Thanks for your help :D. It a start for me.

          1. Yeah avrdude is ran from cmd, but there are GUI programs for it as you found. Not finding the chip could be for a number of reasons (incorrectly wired, no crystal), have a look at some tutorials like this one.

            • darkvoid on January 28, 2013 at 4:28 pm

            actuall found a nice xloader v1.00. saying it uploaded the file, so now im wondering my wiring maybe wrong. nothing but white screen.

    • darkvoid on January 29, 2013 at 10:41 am
    • Reply

    Yeah no clue.. rewired it and still white screen….. 🙁

    1. Do you have a crystal connected? Maybe post a picture of your set up.

    • Somone on January 30, 2013 at 2:17 am
    • Reply

    Can I make this off the standerd Arduino board?

    1. Yes, it should work, however I’m not sure if using the UART port for the Bluetooth module will work or not, since normally you can only connect 1 thing to the UART port and for Arduino boards that would be the FTDI chip.

        • someone on January 30, 2013 at 2:49 pm
        • Reply

        I saw this and was like I just have to have it dammit! Im getting a starter kit, but I cant seem to find the LCD.

    1. The LCD linked doesn’t have 5V to 3.3V level conversion for the inputs, but you can add that yourself using some resistors and optionally zener diodes. You can also find it cheaper on ebay – http://www.ebay.com/itm/370677515951

      This is the LCD I used, which has level conversion built in – http://www.ebay.com/itm/270866804157

    • darkvoid on February 8, 2013 at 9:32 am
    • Reply

    http://i48.tinypic.com/2nsltzc.jpg
    http://i45.tinypic.com/2e1alj8.jpg
    http://i46.tinypic.com/rr2lfo.jpg

    here some pictures of how i got it layout. on the plus side, i now getting a dimmer affect on the screen, but still a blank screen.

    1. It doesn’t look like the LCD VCC is connected to 5V.
      I think you have LCD RST connected to nano RESET, they are different things, LCD RST should go to D7.
      LCD SDA looks like its connected to GND.
      It looks like you have the BT module GND connected to VIN on the nano and VCC connected to GND, VCC should go to +5V and GND to GND, a red LED should be flashing on the Bluetooth module if its working.
      You don’t need to connect the pins for the SD card.
      There may be other mistakes, but its difficult to see where exactly the wires are going.

        • darkvoid on February 8, 2013 at 12:17 pm
        • Reply

        Thanks, yeah realize bluetooth was backwards.

        as for lcd:
        SCL to d5
        SDA to d4
        lcd rst to d7
        grnd to grnd
        vcc to 5v pin.

        does res and cs need to be connected?

        my bluetooth blink read light like you stated.
        still white lite screen only. :/

        1. Yeah, RES and CS need to be connected.
          SCL -> D13
          SDA -> D11
          RST -> D7
          RES -> D9
          CS -> D10

            • darkvoid on February 8, 2013 at 12:55 pm

            Thanks,

            Only option to check would be to make sure software loaded right.

            I got everything else working.

    • darkvoid on February 12, 2013 at 4:17 pm
    • Reply

    -F -v -pm328p -cstk500v1 -P\\.\COM3 -b19200 -D -Uflash:w:”C:\Users\Desktop\New folder (4)\firmware\hex\btNetMon.hex”:i

    Im using arp uploader. this is the parmas it showing.
    when i click upload, i get this:

    avrdue.exe: stk500_getsycn(): not in sync: resp=0x00

    i tried changing what you had told me earlier, nothing.
    what im doing wrong?

    http://www.ngcoders.com/downloads/arduino-hex-uploader-and-programmer/

    1. ARP uploader comes with an old version of avrdude, you’re better off getting the latest version and using command line to upload the hex.
      The official download for AVRDUDE doesn’t seem to be working at the moment, so I’ve uploaded it here – http://blog.zakkemble.co.uk/wp-content/uploads/2013/02/avrdude_5.11_win32.zip
      I’ve modified avrdude.conf to support ATmega328 non-P version, which the nano uses.

      Step-by-step:
      1. Unzip avrdude_5.11_win32.zip to desktop (should get avrdude.conf and avrdude.exe)
      2. Copy btNetMon.hex file to desktop
      3. Open cmd
      4. Enter: cd %userprofile%\desktop
      5. Enter: avrdude.exe -c arduino -p atmega328 -P COM3 -U lfuse:w:0xff:m -U hfuse:w:0xdf:m -U efuse:w:0xfc:m -U flash:w:btNetMon.hex

      You might have to change COM3 to whatever COM number your nano shows up as.

    • darkvoid on February 14, 2013 at 3:14 pm
    • Reply

    avrdude.exe -c arduino -p atmega328 -P COM3 -b57600 -U lfuse:w:0xff:m -U hfuse:w:0xdf:m -U efuse:w:0xfc:m -U flash:w:btNetMon.hex

    had to add the b57600 to get it to run.

    how will it read the other files? How does the images and stuff get loaded to the screen?
    Sorry for being a noob, never program a chip before.

    1. Ah good.
      The images are all stored in the .hex file, you don’t need to worry about getting any more stuff onto the chip.

    • darkvoid on February 14, 2013 at 4:15 pm
    • Reply

    Last question, then lay this to rest.
    http://1.bp.blogspot.com/-7IT-A5XrHfA/UITf9hrqx0I/AAAAAAAATRw/NGCKmhZ7eSk/s1600/arduino+pinout.png

    my board is similar to this.
    on my lcd i have these options:
    vcc
    gnd
    scl
    sda
    rs/dc
    res
    cs

    i wired it closely as possible to this diagram, and all i still get is white light screen.

    1. SCL and SDA on the nano diagram are for I2C, the LCD module uses the same names, but it uses SPI which are the SS/MISO/MOSI/SCK pins on the nano.

      VCC -> +5V
      GND -> GND
      SCL -> D13 (SCK)
      SDA -> D11 (MOSI)
      RS/DC -> D9
      RES -> D7
      CS -> D10 (SS)

        • darkvoid on February 14, 2013 at 6:38 pm
        • Reply

        thanks that worked.

        now just got to pair up a bluetooth and im done.

        1. Excellent, this post might be useful for the Bluetooth module

          I just realised the nano runs at 16MHz, but the hex file is compiled for 20MHz so the baud rate for the Bluetooth module will be incorrect. Heres the hex compiled for 16MHz.

            • darkvoid on February 15, 2013 at 1:48 pm

            Thanks for the help.

            made a simple schematic of the parts i used.

            http://www.speedyshare.com/gAPXE/BLUETOOTH-NET-MONITOR-SCHEMATIC.pdf

            • Zak Kemble on February 15, 2013 at 4:18 pm
              Author

            Red wire is connected to RST on the nano, should go to 5V.
            Bluetooth RXD/TXD are connected wrong,
            TXD -> RXD
            RXD -> TXD

            Everything else looks fine.

    • Jon Blaylock on February 19, 2013 at 5:49 pm
    • Reply

    really nice project. I’ll have to work on making one

    • darkvoid on February 20, 2013 at 11:44 am
    • Reply

    Download realterm.

    Only way i can see to type AT into the black box is to copy paste it in.
    But i dont get no yellow text to show up saying ok.

    Is there a better turtioral on this?

    1. Googling for ‘hc05’ and ‘linvor’ gives a number of results, but most only show how to setup a single module and connect your phone to it.

      Another console program you could try is Putty.

        • darkvoid on February 20, 2013 at 4:22 pm
        • Reply

        Yeah i tried putty, arduino, hyperterminal, and even realterm.
        When i type AT, nothing gets returned.

        Im using a jy-mcu module. Led is fiashing red.

        Wondering if module bad.

        1. Hmm, maybe it’s not running at the usual 9600 baud, try 4800, 38400, 115200 etc

  4. Hey Zak!

    Awesome Work!

    I think u can use a generic bluetooth dongle such as this(http://dx.com/p/super-mini-bluetooth-2-0-adapter-dongle-vista-compatible-11866) for the PC side transceiver instead of the CP2202+bt module combo. Almost all bluetooth dongles support SPP. ,and with some minor modifications (changing the port name! ) in the PC side script you can make any USB bluetooth dongle talk to the bluetooth module.

    Here’s how i managed to do it in windows.(http://murlidharshenoy.wordpress.com/2011/10/26/adding-bluetooth-to-your-microcontroller-projects/)

    Cheers,
    Murli

    1. Ah yeah, I forgot about those dongles while working on the project, I would have probably used those instead >.<

      • darkvoid on February 21, 2013 at 6:34 pm
      • Reply

      So with this, i could set my bluetooth module?

      Super Mini Bluetooth 2.0 Adapter Dongle

      1. You still have to use the JY module for the Arduino Nano part, but the module that plugs into the PC/router can be swapped for one of the mini USB dongles. If you’re using Linux you have to do some rfcomm stuff to set up the dongle.

          • darkvoid on March 5, 2013 at 12:24 pm
          • Reply

          I got me one of those dongles. It showing it pair up with my bluetooth module. Not seeing any output on the lcd display tho.

          1. You need to send it data, there is a Linux shell script in .zip/scripts/router which does all that, you can do a quick test by manually copy & pasting this into a serial terminal $|6100|1020|340|4|19|0|255.255.255.255|2|Wed 02 Jan 13|20:31:26|*

    • darkvoid on March 6, 2013 at 10:09 am
    • Reply

    Dam i got to install linux on my laptop :(.

    I guess this is a good time as any.

    thanks.

    1. You can run Linux in a virtual machine while running Windows, check out Virtual Box.

    • Rob Markowitz on March 7, 2013 at 3:58 am
    • Reply

    Until Zak starts selling these devices, does anyone know of a Windows or Mac program that emulates the look and function of this hardware? I really like the style!

    • phil on April 20, 2013 at 4:29 pm
    • Reply

    This is a great project , did yo think about using snmp as the protical to get the info out of the router , if you did that it would work with almost any router / modem on the market to day all you would need is a WiFi interface instead of a blue tooth etc .
    In my opion if you went this way it would make it ready for market .
    Also im interested in making an android app and a iphone app that does the same thing as this ( using snmp and that also has history )

    1. Hey, there doesn’t seem to be any cheap WiFi modules available at the moment, they all seem to be at least £40, otherwise I would have used that instead.

    • Alex Fideles on July 1, 2013 at 6:30 am
    • Reply

    Hi Zak, first of all, congratulations for the excellent job!

    I have a question for you.

    I did this board one year ago during a project course at university and now I’m trying to set up a slave bluetooth module on it.

    My board is equiped with an ATmega324PA and I’m using the AVR suite (avr-binutils, avr-gcc, avr-gcc-c++, avr-gdb, avr-libc, avr-libc-docs, avrdude).

    Do you have any idea what exactely I need to code to use this bluetooth module with my board? For now, I’m only able to plug the module on my board (VCC, GND only) and connect it with my MacBook. The connection LED stop flashing and stay solidly lit so I think I have a valid connection.

    I’m a little bit lost because all the examples that I found on Internet use the Arduino stuff.

    Thanks

    1. Hey, thanks 🙂

      The Bluetooth modules output serial data, connect the TX->RX and RX->TX lines together and you should be able to receive and transmit serial data. This post might be helpful.

    • Alex Fideles on July 1, 2013 at 6:32 am
    • Reply

    I forgot the link to my board…

    http://www.groupes.polymtl.ca/inf1995/materiel/carteMC/images/carteMC1.jpg

  5. Great project, great implementation ! this BT module is really a gem; cheap and reliable. It’s only drawback is the awful documentation !

    I am trying to connect/disconnect the module via an I/O output and I wonder if it is better to use a MOSFET switch (high or low side ?) or use the reset feature. Is it the same, i.e. does the module consume power in reset mode or not ? My first idea was this :

    http://i43.tinypic.com/11rryc6.jpg

    1. In reset the module consumes 60uA (or maybe a bit less, it was going through a regulator which draws some of its own current, but I’m not sure how much). So if you need it to use less than 60uA then use a high side MOSFET to turn it on and off like in your link, otherwise just use the reset.

      1. Great !!! 60 uA is nothing, I will go for the RESET thing, since it is equivalent to the power cycling needed to enter the AT mode @38400.

    • bWilson on March 4, 2014 at 5:40 am
    • Reply

    could this hardware setup be used to stream video?

    1. No, it’s much too slow for that.

    • bWilson on March 5, 2014 at 3:05 am
    • Reply

    would you have any ideas on how to create something similar to this in size possibly a little bigger that would have the speed to stream video?

    1. Sorry, all I know is that a fast ARM microcontroller is probably needed for that.

  1. […] needing to log into his router. Since his router was a PC running Debian Linux, he rigged up a Bluetooth Network Monitor to display the […]

  2. […] Bluetooth Net Monitor [Zak's Electronics Blog via Hack a Day] […]

  3. […] то ознакомиться с ним более подробно можно в соответствующей заметке на сайте Зака, ведь помимо ворклога по изготовлению данного […]

  4. […] For more info please go into the source. […]

Leave a Reply

Your email address will not be published.

Are you human? *