«

»

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.

Downloads
Latest downloads can be found here.

OLD
Download
btNetMonitor_20130109.zip (731.77 kB)
Sources, scripts, EAGLE schematic and board layout files
Downloaded 1377 times
MD5: F540F7B7C19333BDA33983D8AA035798


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. Micah Wyatt

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

    1. Zak Kemble

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

  2. Konrad

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

    1. Zak Kemble

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

  3. Matt M

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

    1. Zak Kemble

      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.

  4. naPS

    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!

  5. Trav

    Looks great – what font did you use?

    1. Zak Kemble

      Thanks, I used this font in bold italic.

  6. James

    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. Zak Kemble

      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.

  7. Freddy

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

    1. Zak Kemble

      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.

      1. Freddy

        Ty =)

  8. Bob H

    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. Zak Kemble

      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.

  9. Daniel Moore

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

    1. Zak Kemble

      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.

  10. Daniel Moore

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

  11. ThatGuy

    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. Zak Kemble

      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

  12. mike

    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. Zak Kemble

      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.

  13. Mucki

    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. Zak Kemble

      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!

      1. Freddy

        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. Zak Kemble

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

  14. Diego

    Hello,

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

    Thanks

    1. Zak Kemble

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

  15. darkvoid

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

    1. Zak Kemble

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

      1. darkvoid

        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. Zak Kemble

          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)

          1. darkvoid

            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.

          2. Zak Kemble

            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.

          3. darkvoid

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

  16. darkvoid

    Yeah no clue.. rewired it and still white screen….. :(

    1. Zak Kemble

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

  17. Somone

    Can I make this off the standerd Arduino board?

    1. Zak Kemble

      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.

      1. someone

        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. Zak Kemble

      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

  18. darkvoid

    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. Zak Kemble

      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.

      1. darkvoid

        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. Zak Kemble

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

          1. darkvoid

            Thanks,

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

            I got everything else working.

  19. darkvoid

    -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. Zak Kemble

      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.

  20. darkvoid

    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. Zak Kemble

      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.

  21. darkvoid

    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. Zak Kemble

      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)

      1. darkvoid

        thanks that worked.

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

        1. Zak Kemble

          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.

          1. darkvoid

            Thanks for the help.

            made a simple schematic of the parts i used.

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

          2. Zak Kemble

            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.

  22. Jon Blaylock

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

  23. darkvoid

    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. Zak Kemble

      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.

      1. darkvoid

        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. Zak Kemble

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

  24. Muralidhar Shenoy

    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. Zak Kemble

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

    2. darkvoid

      So with this, i could set my bluetooth module?

      Super Mini Bluetooth 2.0 Adapter Dongle

      1. Zak Kemble

        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.

        1. darkvoid

          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. Zak Kemble

            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|*

  25. darkvoid

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

    I guess this is a good time as any.

    thanks.

    1. Zak Kemble

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

  26. Rob Markowitz

    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!

  27. phil

    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. Zak Kemble

      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.

  28. Alex Fideles

    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. Zak Kemble

      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.

  29. Alex Fideles

    I forgot the link to my board…

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

  30. vpapanik

    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. Zak Kemble

      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. vpapanik

        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.

  31. bWilson

    could this hardware setup be used to stream video?

    1. Zak Kemble

      No, it’s much too slow for that.

  32. bWilson

    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. Zak Kemble

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

  1. Bluetooth Network Monitor

    [...] 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. Build Your Own Bluetooth Network Monitor And Keep Tabs On Your Internet Connection | Lifehacker Australia

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

  3. Монитор сетевой информации с bluetooth подключением | Лучший моддинг сайт

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

  4. Bluetooth Net Monitor | A Maker's Dream Factory

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

Leave a Reply

Your email address will not be published. Required fields are marked *


− 6 = 2

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>