iOS Notifications with Arduino

ancs

One of the few things I really like about my Blackberry was the red blinky light that let me know if anything new happened. The iPhone is a great device, but it is easy miss that you have a new email or text. Apple has create a centralized place to collect all of these new things you might want to know about, called the Notification Center. However, there is still no red blinky light. If you miss the screen turning on when something comes in, you wouldn’t know that you had anything new.

Apple has added something that can help fix this, Apple Notification Center Services (ANCS). This allows for devices to connect over Bluetooth LE  (BLE), also known as Bluetooth Smart, and receive notifications from the iOS device. It is in iOS 7.0 and most recent iPhones and iPads. ANCS is behind a lot of the new smart watches and fitness bands that do stuff when you have a new email. All this is great, but wouldn’t it be fun if you could do something really big when you get something new?

I thought it would, so I looked for a way to build a Arduino power device that would connect to iOS ANCS. There is a BLE Arduino shield that plugs right in and comes with lots of great code. AdaFruit also has a BLE Breakout Board. They are both based on the great nRF 8001 Chip from Nordic Semiconductor. They provide an Arduino library for their chip and a free software package that makes it easy to configure the features of the chip.

I also came across some great ANCS code for AVRs & Arduinos that was 95% there. I updated it the be compatible with the latest version of the Noridc library, made it easier to pair and rolled it into an Arduino library. I am going to work on getting my code Pulled back up, but until then use my branch to pull down the latest updates.

ANCS Arduino Library

Things are still a little messy, but the overall functionality seems to be pretty stable. You pair the devices once and after that, they automatically join. That alone could be used for some cool functionality. It would be easy to build a box that automatically unlocks when you are near-by or have it play a trumpet sound. This part about ANCS compared to other BLE profiles, is that it works natively and doesn’t require any Apps to be installed on the iOS device. With the BLE Proximity stuff, you need to have an App running on the device to make the initial connection.

Of course the reason for going through this trouble is to get notifications. ANCS pass along all of the Notifications from iOS, including 3rd party ones. You can filter them based on type or source, so you can have a different response depending on what it is. For example, you could do something really annoying for incoming calls, but more subtle for a Twitter mention.

The library works arounds Call Backs and will call the function you specify when a device Connects/Disconnects and sends a Notification.

I have included an example I am working on that displays Notifications on an LCD and turns on the Backlight.

Memory is a problem, so I have some notification fields turned off in order to have a smaller cache.

Also, is Notif a good name? Any thoughts on a better one for the library?

Using a HackRF to Capture an Entire Radio System

openmhz

OpenMHz.com

After a bit of work, I have put together a system that lets you monitor the radio system for DC Fire, EMS & City Services. Everything gets recorded and can be played back through a website. Thanks to the magic websockets, any new call that comes in gets added to the top of the list. Better yet, if you hit the Autoplay button in the upper left hand corner, it will automatically play through the list of calls. You can narrow the list of calls display to specific group using the filters.

Anyhow, give it a try at openmhz.com and let me know what you think. If you want more background on how it works, read on…

HackRF
Software Defined Radios are pretty awesome. For the uninitiated, they let you receive a lot of radio signal over a wide range of frequencies. It pass you the raw information and you use a computer to filter out a transmission and process the signal. There is tons of flexibility… and that is also a challenge. There are a lot of rough edges and ways you can mess things up. That is half the fun though, boldly coding where few have coded before.

I was one of the lucky recipients of a great SDR, the HackRF Jawbreaker. It is an amazing piece of Hardware, capable of sending or receiving 20MHz of spectrum between ~13MHz – 6GHz. It is Open Source Hardware too, so if you are wicked smart you can build your own boards. The design work for it was funded by DARPA and I got one of the boards from that pre-production run. In order to go into production, a Kickstarter project was put together. The original target amount was $80k and it quickly blew through that and ended up raising $600k. One of the most impressive stats is that the target price is $300.

You can do a lot of things with this board. It use the popular Osmosdr drivers, so it works with a lot of existing things and plugs right into GNURadio.

There are an endless number of things to try. What I have been focusing on is trying to monitor the radio system that the Washington, DC Fire/EMS & City Services use. Of course monitoring a radio system is nothing new. Radio Shack sells a bunch of different scanners that can do it. However, these scanners can only follow one conversation on a system on a time. Since an SDR can receive a wide swatch a spectrum at once and all the processing happens on the computer, you can decode multiple transmissions. Since you are doing the processing on a computer you can easily save and archive the transmissions, which you sort of needed since you could be getting a couple at once.

Luckily for me, a couple of people have already setup systems that do exactly that. The code from Nick Foster, GR-SmartNet, seems to be the first out there, and the only publicly available code. The Super Trunking Scanner took it a step further and made it playable over the web. It monitor a trunked system with analog channels. The Radio Capture system took a similar approach, except made it work for a system with digital voice channels.

How Trunking Works
Here is a little background on trunking radio systems, for those not familiar. In a Trunking system, one of the radio channels is set aside for to manage the assignment of radio channels to talkgroups. When someone wants to talk, they send a message on the control channel. The system then assigns them a channel and sends a Channel Grant message on the control channel. This lets the talker know what channel to transmit on and anyone who is a member of the talkgroup know that they should listen to that channel.

In order to follow all of the transmissions, this system constantly listens to and decodes the control channel. When a channel is granted to a talkgroup, the system creates a monitoring process. This process will start to process and decode the part of the radio spectrum for that channel which the SDR is already pulling in. In the DC system, the audio is digitally encoded using the P25 CAI process. Decoding it is a bit of pain. I am taking a quick and dirty approach right now and have shoe horned in the DSD program. In the future I would like to try using the code from the OP25 project and a hardware dongle for the decoding. Unfortunately, the dongle is $500, so that might not be happening too soon.

No message is transmitted on the control channel when a talkgroup’s conversation is over. So instead the monitoring process keeps track of transmissions and if there has been no activity for 5 seconds, it ends the recording and uploads to the webserver. I convert the WAV file that gets recorder into an MP3 file. Since the audio is original converted to digital by the radio system, put it through another lossy digital conversion is probably not a good idea, but sending the full-size WAV file ate up too much space.

My Setup
The monitoring and recording is being run off of a laptop in my apartment and uses a crappy antenna. The website is run off a VPS I have running up in the magical cloud.

The webserver is pretty simple. It is written in NodeJs. The audio is stored as WAV files and indexed using MongoDB. The server simply watches for new files being placed in a directory and then moves them and adds them to the DB. Socket.io is used to updated all of the browsers visiting the site that a new transmission has been added.

The Code
The recorder portion of the system is C++ code that uses GnuRadio 3.6.5.1.

The recorder uses DSD to decode the digital audio. Unfortunately DSD isn’t supported or being developed, isn’t designed to work with GNURadio or SDR. Luckily someone wrapped DSD into a GNURadio block. It works, but it isn’t pretty. I had to futz with it a bit to run concurrently. My version is here.

The final portion is the website for listening to the recordings. The code for that is available here.

The Punch List
Right now, I think everything is pretty much stable. I have a small memory leak somewhere, but I can keep it up for long time without it being a problem.

  •  Upgrade everything to GNURadio 3.7. Right now I am on the 3.6 branch and it will take a bit of work to switch.
  • Get OP25 working nicely. The code is designed to work with GR and is being actively developed.

Receving P25 CAI Using a HackRF

I have been playing around a bit and found an easy way to receive and playback digital LMR. More and more of the radio systems are going from narrow band FM to Digital. This makes it tough to listen to them on GQRX. DSD is a great program which can decoded the audio you get when you tune in a system in GQRX, but you either have to run it on another machine with a audio cable in between or figure out how to do a virtual audio cable on your machine.

Luckily, someone wrapped the DSD libraries so they can be accessed as GRC blocks. I have put together a GRC file and a Python program that make it a little easier to use the block.

The files and write-up are here: https://github.com/robotastic/gr-dsd

If you have a chance, give them a try and let me know if they work. There is a good chance I have messed up the values in the filters or else where, but I have gotten clean audio out of it.

HackRF SDR on OSX

I was one of the lucky recipients of Mike Ossmann‘s awesome HackRF Jawbreaker boards. I have a Ubuntu laptop I can play around with at work, but MacBook at home. I am not complaining! I wish I had a Mac at work too.

Anyhow I wanted to get it up and running on my Mac, so I could use it both at work and home. Luckily I found someone had already written up how to install GNURadio and an RTLSDR (a similar SDR) on OSX. All I had to do was fork it and extend it to add in support for HackRF.

I have a write up over at my GitHub. Give it a try and let me know if it works for you!

Linux Driver For Sure Electronics DE-DD22111

In addition to offering cool LED modules, Sure Electionics also offers a nice Demo / Driver board to go along with them. The only bummer is that the driver board needs a Windows Java program to run if you want to send text to it, to be displayed.

I did some backwards engineering and looked through the design documents, and was able to come up with a couple of Linux programs that let you display text using you computer. It is actually a really cool board and it looks like it is all based on a PIC microchip and could easily be reprogrammed. The PCB board has the traces for a clock, temperature sensor and wireless connection, so it was clearly meant to be added on to.

The board communicates with a computer over USB using a CP2102 USB to UART Bridge. The great is that most newer Linux kernels have driver support baked right in. That means that when you connect the board to your computer, it just shows up as a serial device.

To send Text to the board you need to send it through the serial port ( ttyUSB0 ). Before doing that you have to send the command for write mode. To send text to the first bank of up to 4 boards, you send “0xFE,0x47,0x01,0x01”, followed by 16 characters. You have to send 16 characters, even if you have less than 4 boards or else it goes screwy. All of the scrolling has to be done in your program and you simply change which 16 characters are currently being displayed.

I have my code up on GitHub

and here:

led.tar.gz

$100 Internet Enabled LED Message Board

The Raspberry Pi is a lot of fun to play with but I wanted to do something “useful” with it. The obvious solution was of course to connect something fun to it. I have always wanted to have a message board all to my own so I can display my wisdom and entertain my co-workers.

I could of course cough up a bunch of money and buy an assembled message board or just get a miniature “toy” version, but what fun would that be. Instead I decided to order the different components I needed to build my own.

Sure Electronics is a component manufacturer that sells straight from China. They have great prices and decent documentation. There are of course some rough edges on the documentation and demo code. They are not Spark Fun or Ada Fruit, but neither are their prices.

They sell a number of different LED Matrix. The big differences seem to be the number of LEDs, the size of the LEDs and whether they are single color or capable of multiple colors. I went with the smallest LEDs, 3mm, in green. The modules can be connected together in serial and communicate using SPI. You can have a max of 4 modules, so I got 4.

While the Raspberry Pi supports easily outputting SPI, it still takes a bit of work. In order to get going quickly, I also got a Demo Driver board that lets you control the modules using USB.

Here is what I got:

4 – 8 x 32 LED Matrix, 3mm green ( DE-DP13111 )
1 – Demo Driver Board ( DE-DD22111 )

It took about 4 weeks for the hardware to arrive, but I went with the cheapest shipping option. I am happy with the 3mm LED size. I am just setting it up in a hallway and it is easily readable 10feet away. The larger sized LEDs might have actually been worse because it would have been tougher to read the text close up.

The driver board comes with a number of test functions. It takes in 12v, and provides 5v for the LED boards. I luckily had a Radio Shack variable voltage power supply lying around. I hooked up all of the boards to make sure everything works and I didn’t have any problems.

You can also use the driver board to display scrolling messages by connect it to your computer over USB. The program to do this is available for download here. The problem is that it says it is a .zip file when in fact it is a .rar file. I tried renaming and un-rar the file after I saw another similar file on their site… and it worked. To make your life easier, I have correctly zipped it up and uploaded it.

Sure_LED_1.0.zip

Even though it is a Java program, it only seems to work on Windows computers. In order to get a better sense of what it was doing, I ran the .jar file that is include through a decompiler. Here it is:

NewLcd.src.zip

With the knowledge I gained from that I wrote my one version of the program in Linux. It should work on the Mac, but I think you need to have a serial driver loaded. I will put together a follow-up post on how to write programs to communicate with the Driver Board.