How to get personal CCTV MMS’d to your phone

I left the setup in the last post with a system that would email photos of the burgular off site and then an SMS message. This is a prety good solution but since nearly everybody has a phone capable of receiving picture messages it seamed like the next step is to not just email the photos off site, but to also send them as a picture message so they can be checked for false alarms even when I’m not at my computer.

I went back to searching the net for a package that would supply MMS capability using a cell phone attached to a computer, not a direct connection to a bulk messaging provider. There is project called Mbuni that is a fully functional MMS gateway and relaying service as run by the cell phone providers. Normally this would run on the providers network and or at a company providing paid for content via MMS. Hidden away in the CVS for the latest version there is a add on to one of the components which will allow the sending of MMS messages via a phone.


In the last post I had discounted Kannel for sending SMS messages because of the complexity. But Mbuni prereqs it so it was time to have another look at the setup. Mbuni also request a specific level of Kannel (CVS 2008-07-28 download) so because I was planning on using some very new function in Mbuni I decided to build this Kannel version from source to make sure it all matched up.

tar -zxf kannel-snapshot.tar.gz
cd kannel-snapshot
su -c "make install"

Kannel is made up of a number of separate programs that provide different bits of functionality

  • bearerbox
  • smsbox
  • wapbox

In order to be able to send and receive SMS messages we are going to need the frist two on the list. Wapbox is only used if you want to provide a dial up WAPgateway.

Setting up Kannel is not hard, the docs are very good and can be found here and there is a copy of my config files as a guide in the resources section


There is some good documentation for setting up the full MMS gateway version of Mbuni, but because the cell phone plugin is stil only in the development stream there is only a small sample config file and the source code. I have tried to document what I have learned setting it up here.

Since this is a bleeding edge function you will need to build Mbuni from the src in cvs. There are instructions on how to do this on the web site here, but here is a short version

cvs login
cvs -z3 co -P
cd mbuni
cd extras/mmsbox-mm1
cd ../..
su -c "make install"

The change of directory to the extras/mmsbox-mm1 is to build the extra library needed to work with the phone. If you are running on a machine that has SELINUX enabled you will need to run the following command to allow the library to work

su -c "chcon -t texrel_shlib_t /usr/local/lib/"

Like Kannel, Mbuni is made up of a collection of applications

  • mmsc
  • mmsproxy
  • mmsrelay
  • mmsbox

To send MMS messages via a phone we only need mmsbox which is what is known as a VAS gateway. So we need to create a Mbuni config file, there is a sample file shipped with the src in the doc/examples directory. Here is my version modified to work with O2 UKs MMS service

group = core
log-file = /var/log/kannel/mmsbox.log
access-log = /var/log/kannel/mmsbox-access.log
log-level = 0

group = mbuni
storage-directory = /usr/local/var/spool/mbuni
max-send-threads = 5
maximum-send-attempts = 50
default-message-expiry = 360000
queue-run-interval = 5
send-attempt-back-off = 300
sendmms-port = 10001
sendsms-url = http://localhost:13013/cgi-bin/sendsms
sendsms-username = tester
sendsms-password = foobar

# Sample conf for MMSBox using a modem (MM1)
group = mmsc
id = modem
type = custom
custom-settings = "smsc-on=lynx -dump 'http://localhost:13000/start-smsc?
 smsc-off=lynx -dump 'http://localhost:13000/stop-smsc?password=bar&smsc=w880i'; 
 gprs-on=/usr/bin/pon o2; 
 gprs-pid=cat /var/run/ | head -1;port=13014;
mmsc-library = /usr/local/lib/

group = send-mms-user
username = tester
password = foobar
faked-sender = 100

The interesting bits are the sendsms-url and the custom-settings lines. The sendsms-url points to the bearerbox/smsbox URL from setting up Kannel earlier which Mbuni uses to send the notification about the new mail.

The custom-settings line is a lot more complicated, it is basically a mini config file all of it’s own. The two entries that start with smsc-on and smsc-off are commands that the custom library built earlier uses to stop and start the sms gateway while the MMS message is sent. gprs-on is used to start a PPP session via the phone. This can be either gprs or 3G. The code implies that this command should not return until it’s killed at shutdown, but using /usr/bin/pon on Ubuntu seams to work.

The next few bits depend on which cell phone provider your using. The mmsc-url and proxy are the addresses for the machines on their network you need to use to
send MMS messages. I found the following page has a good list of the settings for UK provider


So now we’ve got the set up working we need some content to send. MMS messages are defined using SMIL markup. The following is the simple SMIL file I am using to send a short video clip and text caption. The first half divides the display in half, with the video in the top half and the text in the lower. The second section contains the details of the links to where Mbuni can find the content to
fill those areas and how long to display them. This is a very simple example, much more complex messages can be assembled with

         <root-layout />
         <region id="Image" top="0" left="0" height="50%" width="100%" fit="hidden" />

         <region id="Text" top="50%" left="0" height="50%" width="100%" fit="hidden" />
      <par dur="5000ms">
         <video src="http://tiefighter.loc/cam1/intruder.3gp" region="Image"></

         <text src="http://tiefighter.loc/cam1/message.txt" region="Text"></text>


So far we have been just sending static images, next comes converting the avis created by Motion to mpeg4 in a 3gp container that should be playable on any MMS capable phones. The following ffmpeg command will convert the file to the right format.

ffmpeg -i 07-20090916100019.avi -s qcif -vcodec h263 -y intruder.3gp

Where “-i 07-20090916100019.avi” is the file created by motion, “-s qcif” tells ffmpeg to use an output file that is 176×144 and conforms to a standard that all phones should understand, “-vcodec h263″ is the video codec to use. “-y intruder.3gp” tells ffmpeg to overwrite the file if it already exists.

Here is an example of the Motion output.

After transformation:

When viewed on a 2 inch screen the drop in quality is not noticeable and it is still possible to tell if it is somebody you know.

Actually sending the MMS

So now we have actually created the content for the MMS message we need to put it somewhere mbuni can find it. In this case I put the video and text files into the /cam1 directory being server up by http server. The URLs match the entries in the SMIL file created earlier.

Now we need to send the SMIL file to Mbuni along with the phone number to send it to. The following curl command will send the SMIL file and the rest of it.

curl  --data "username=tester&password=foobar&to=07703xxxxxx&subject=Possible+Intruder&from=07543xxxxxx" --data-urlencode "smil@/var/www/html/cam1/intruder.smil"  http://x-wing.loc:1000

In this case Mbuni is running on the a machine called x-wing and listening on port 10001 (as set with the sendmms-port in the config above). The frist half is the urlencoded version of the username, password, the senders and recipients numbers and the subject of the message. The second section, after the –data-urlencode loads the SMIL file and encodes it before sending it.

Putting it together

Now we need a to collect all of this up in a scrip to attach to the movie end action of motion. The following script first helps to prevent false alarms by ensuring that any video has at least 15 frames. Assuming that test is satisfied the orginal version of the video is emailed offsite for safe keeping, before converting the it to the 3gp format. It then adds the time and date to the message.txt before sending the SMIL to Mbuni.


FRAME_COUNT=`/home/hardillb/bin/frameCounter $1`

if [ $FRAME_COUNT -gt 14 ]; then

    uuenview -a -m $1 <<EOF
Subject: Movement detected video $2 $3


    /home/hardillb/bin/sendMessage SMS/Outbound "TO: +447703xxxxxx MESSAGE: possible intruder"

    ffmpeg -i $1 -s qcif -vcodec h263 -y /var/www/html/cam1/intruder.3gp

    echo "$2 $3" > /var/www/html/cam1/message.txt

    curl  --data "username=tester&password=foobar&to=07703xxxxxx&subject=Possible+Intruder&from=07543xxxxxx" 
        --data-urlencode "smil@/var/www/html/cam1/intruder.smil"  http://x-wing.loc:10001

The frameCounter was a script I had run up earlier for a different project, made sense to reuse it here.

mplayer -v $1 -nosound -vo null -frames 0 2> /dev/null | grep "frames  t" | awk ' { print $3 } '

So that’s about it, I have a motion activated CCTV system that will log off site and send alerts to me anywhere in the world with enough detail to decided if it’s a false alarm


11 thoughts on “How to get personal CCTV MMS’d to your phone”

  1. Hello,

    Thanks for the informative projects posted on you blog. I managed to cofigure mbuni so that when i excute the curl –data command it shows no error in the logs but i dont seem to receive the notification on the destined phone.
    My question would be… im not using a modem but a short code SMPP connection from one of my local service providers, how should i configure the mmsc. This is part of the .conf that i have currently.

    group = mbuni
    storage-directory = /var/spool/mbuni
    max-send-threads = 5
    maximum-send-attempts = 50
    default-message-expiry = 360000
    queue-run-interval = 5
    send-attempt-back-off = 300
    sendmms-port = 10001

    group = mmsc
    id = local
    incoming-username = user
    incoming-password = pass
    incoming-port = 12345
    type = soap

    group = send-mms-user
    username = tester
    password = foobar
    faked-sender = 3302

    im i forgeting anything.

    Thanks in advance

  2. Hi Jefkine,

    I must admit I’ve not looked at this since I got it all working back at the start of the year and I was only interested in getting it to work with a modem.

    If you’ve not found it yet there is a good mailing list linked to from the mbuni home page where I got a fair bit of help when I was working on this. The link to subscribe is here:

    There will be somebody on the list who can help you.

  3. Hello,

    Im trying to get my modem to work with my linux susse 11.1 but im getting this error at the connect stage’

    –> Carrier detected. Waiting for prompt.
    –> Don’t know what to do! Starting pppd and hoping for the best.
    –> Starting pppd at Fri Oct 15 00:25:49 2010
    –> Pid of pppd: 30957
    –> Disconnecting at Fri Oct 15 00:25:49 2010
    –> The PPP daemon has died: pppd options error (exit code = 2)
    –> man pppd explains pppd error codes in more detail.
    –> I guess that’s it for now, exiting
    –> The PPP daemon has died. (exit code = 2)

    I just wanted to know was this a problem for u, could this be down to my linux version

    My modem is Huwaei e160


    1. /etc/ppp/peers

      # This optionfile was generated by pppconfig 2.3.18.
      connect “/usr/sbin/chat -v -f /etc/chatscripts/o2″
      user “payandgo”
      remotename payandgo


      # This chatfile was generated by pppconfig 2.3.18.
      # Please do not delete any of the comments. Pppconfig needs them.
      # ispauth PAP
      # abortstring
      # modeminit
      ” ATZ
      OK AT+CGDCONT=1,”IP”,””
      # ispnumber
      OK-AT-OK “ATDT*99***1#”
      # ispconnect
      CONNECT dc
      # prelogin
      # ispname
      # isppassword
      # postlogin

      # end of pppconfig stuff

      I also have the following script which sets a fixed route to O2’s MMS proxy to ensure the traffic goes out over the PPP link

      route add -host dev ppp0

Leave a Reply

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

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=""> <s> <strike> <strong>