Software

The software takes the form of a BASH script running as a service on the Raspberry Pi. The script auto runs at start up allowing the system to operate without keyboard or mouse and ensuring automatic recovery from power outages.

A number of active web pages interact with the BASH script enabling remote control over the internet. The web pages are HTML with PHP, and use the jQTouch JavaScript plugin to provide animated graphics and page transitions. This give the web app the look and feel of a native iPhone app. The creators of the plugin are in the process of re-branded to jQT, so I’ll refer to it by the new name.

It’s worth pointing out that the software is not dependant on the circuit board, so can be evaluated in isolation. All the source code for the system is available on the Git Hub: https://github.com/oddwires/alarm-system

The rest of this page details the process to get the code from the Git Hub and onto your RasPi / iPhone.

Build details

The items below are sufficient to build the system to work over a local network.

Things you will need…

  • Raspberry Pi, monitor, keyboard, power supply
  • Network port (with Internet access)
  • The IP address of the RasPi
  • 8GB class 10 SD card
  • Windows 7 PC running terminal emulator software (eg PuTTY)
  • iPhone SE or Safari browser

The additional items below are required to access the system over the internet.

  • Router configured to provide address reservation for Raspberry PI
  • Router configured to forward Raspberry PI port 80
  • Email account and email server connection details (stages 6 & 7 assume this is a gmail.com account).

Linux build

The Linux build is based on the current Raspbian wheezy image. The image, and full instructions on how to load it to the SD card can be found at: http://www.raspberrypi.org/downloads

Don’t forget to use the config utility at first boot to expand the file system.

Update 25/05/2014 – I’ve just pushed ver 2.00 code to the GitHub.

Version 2.00 started after I upgraded my iPhone to IOS7, and found some issues with the jQT animations going a bit jittery. So I’ve completely re-worked the GUI using the latest version of jQT, and incorporated some fun new features, such as support of colour themes, ability to view log files, my own experimental colour theme ( khaki ), along with the new theme from jQT ( Innsbruck ). I’ve also made the interface much more of an ‘I’ thing by removing a lot of the unecessary buttons. Additionally there are all sorts of code enhancements, like moving away from ad-hock JavaScript routines, to using a single jQuery module, this gets all the supporting code together in one place. Hopefully this will make it easier to understand the operation of the code.

Update 10/01/2015 – Ver 3.00 code pushed to the GitHub.

Version 3.00 code is in the new ‘alarm-system’ repositry, and works with the new circuit board providing a more profesional solution to switching the remote control channels. It also provides an additional 4 Alarm Zone inputs, and numerous code improvements, and can be made to run on any Debian system, not just a Raspberry Pi. I’ve mopped up most of the previous issues spotted by Adilet and Ezio and fixed the file permissions in the install process. But I’m sure there is probably a shed load of new issues just waiting to be found. I’ll create some new pages with further details over the next few weeks.

Update 17/10/2015 – Ver 4.00 code pushed to the GitHub.

So many changes I created a dedicated page to explain them all.

Update 11/10/2017 – Ver 5.00 code pushed to the GitHub.

This has a new GUI based around the JQuery mobile framework. Also updates to control radiator valves. And the Operating System has been re-aligned to the current version of Raspian ( Stretch ).

Warning – The YouTube video is out of date – the current application is based around a standard menu bar structure, rather than the earlier rotating 3D cube. I’ve also made use of Action Bars to clear up the interface. But it should all be fairly intuitive. If you have any questions, just leave a comment and I’ll get back to you as soon as possible.

Configuration and Application install

I’ve removed the V2 build instructions from this page, as there where a few issues with that release. All the issues have been fixed in the V3 code, and the install instructions can be found on the Github wiki.

57 Responses to Software

  1. I’m trying to simplify your alarm.sh to only use the available GPIOs (as opposed to a GPIO array). Is that easy enough to do? I’m a n00b when it comes to bash scripting.

    • Hi John,

      Thanks for the interest in the software. I think I should start with the reason behind the array of GPIO’s.

      I started the project soon after the Raspberry Pi was released, and my live system is running on an early revision 1 board. This board has 128M memory and physical pin 13 on the GPIO header responds in software as /sys/class/gpio/gpio21. A few months later, I bought a second Pi to run alongside the live unit, but to use purely for code development. This second unit was the later model with 256M memory and annoyingly, physical pin 13 on the GPIO header responds in software as /sys/class/gpio/gpio27. So I coded the array to detect the Raspbery Pi hardware, and drive the GPIO ports consistently on either version.

      Also the BASH code driving the header pins works in terms of gpio numbers, which bear no resemblance to the physical pin numbers found on the GPIO header, so I also included this mapping in the array. So when you read my code and it says $PIN_7, it means physical pin 7 on the GPIO header. If you remove the array, you will need to refer to physical pin 7 as /sys/class/gpio/gpio4
      The full list of mappings is…
      $PIN_7 –> /sys/class/gpio/gpio4
      $PIN_26 –> /sys/class/gpio/gpio7
      $PIN_24 –> /sys/class/gpio/gpio8
      $PIN_21 –> /sys/class/gpio/gpio9
      $PIN_23 –> /sys/class/gpio/gpio11
      $PIN_11 –> /sys/class/gpio/gpio17
      $PIN_12 –> /sys/class/gpio/gpio18
      $PIN_15 –> /sys/class/gpio/gpio22
      $PIN_16 –> /sys/class/gpio/gpio23
      $PIN_18 –> /sys/class/gpio/gpio24
      $PIN_22 –> /sys/class/gpio/gpio25
      Then if you are running a rev 2 Pi:
      $PIN_13 –> /sys/class/gpio/gpio27
      But if you are running an earlier rev 1 Pi:
      $PIN_13 –> /sys/class/gpio/gpio21

      So there are six types of GPIO operation…
      1) Initialise ports:
      echo 4 > /sys/class/gpio/export – this won’t need changing. I haven’t used physical pin numbers in this section.

      2) Initialise pin as output:
      echo “out” > $PIN_26/direction would become echo “out” > /sys/class/gpio/gpio7/direction

      3) Initialise pin as input:
      echo “in” > $PIN_24/direction would become: echo “in” > /sys/class/gpio/gpio8/direction

      4) Set output to 0:
      echo “0” > $PIN_21/value would become: echo “0” > /sys/class/gpio/gpio9/value

      5) Set output to 1:
      echo “1” > $PIN_23/value would become: echo “1” > /sys/class/gpio/gpio11/value

      6) Read value from input:
      cat $PIN_11/value would become: cat /sys/class/gpio17/value

      So going back to your original question ’Is it easy to do?’ – I suppose the simple answer is ‘no’. But it isn’t impossible either.

      • Thanks Tony. That does clear things up a bit. I guess where I’m coming from is I’d like to use the optos to protect the PI but I wanted to create a direct relationship between GPIO and “alarm zone”, because the opto array idea is confusing me at the moment. So I guess I’ll just do something like this for reading the values. (still need to revise which pins I can/cant use)

        sw1=$(cat $PIN_7/value) # read first input
        if [[ “$sw1” -ne “$sw1_old” ]]; then input_change=true; fi # flag any changes
        sw2=$(cat $PIN_11/value) # read second input
        if [[ “$sw2” -ne “$sw2_old” ]]; then input_change=true; fi # flag any changes
        sw3=$(cat $PIN_12/value) # read third input
        if [[ “$sw3” -ne “$sw3_old” ]]; then input_change=true; fi # flag any changes
        sw4=$(cat $PIN_13/value) # read fourth input
        if [[ “$sw4” -ne “$sw4_old” ]]; then input_change=true; fi # flag any changes
        sw5=$(cat $PIN_15/value) # read fifth input
        if [[ “$sw5” -ne “$sw5_old” ]]; then input_change=true; fi # flag any changes
        sw6=$(cat $PIN_16/value) # read sixth input
        if [[ “$sw6” -ne “$sw6_old” ]]; then input_change=true; fi # flag any changes
        sw7=$(cat $PIN_18/value) # read seventh input
        if [[ “$sw7” -ne “$sw7_old” ]]; then input_change=true; fi # flag any changes
        sw8=$(cat $PIN_21/value) # read eigth input
        if [[ “$sw8” -ne “$sw8_old” ]]; then input_change=true; fi # flag any changes

        I’m not planning on using it for any automation at this stage. Just a basic alarm system. So there should be enough GPIOs for that.

        Thanks for sharing your work, and inspiring the rest of us. I really appreciate it!

        • Hi John,

          I’ve just had another thought on this. If you are using one opto-isolator per GPIO channel, then it should be possible to use the GPIO interrupts. This would mean that any GPIO changing state would trigger a hardware interrupt, which in turn calls a subroutine to take the appropriate action. So you wouldn’t need to keep track of the previous state of the pins, and all the $swX_old variables and the $input_change variables could be done away with.

          Also you wouldn’t need a continual loop scanning the inputs and calculating if anything has changed. The Pi would just know that something has changed, and execute the relavent code.

          So the downside is that you would have to completely re-work the alarm.sh BASH shell script – but the end result could be very efficient code.

          Tony

  2. Hi Tony,

    First of all, let me say a massive thank you on this great project, and also thanks for sharing it. If you ever in shropshire i’ll buy you a beer 🙂

    Just like John in the above comment, I’m also trying to simplify your php and alarm.sh code to my needs. Which is very minimum, i’ve already got an Accenta gen4 alarm system, but without any monitoring tools. My project is to get rid of the Accenta box and use the existing PIRs and door contacts and connect them to the RPi. Alternatively, just add the RPi to the alarm system as a monitoring tool, so when the alarm goes off then i get notification, the con there is that i can control the alarm remotely i can only use the Pi to monitor the system. I’ve also added a webcam, so in case i’m out and i get an email notification then i can quickly check the live feed, or when the alarm is triggered the RPi sends me snapshots so i know whether its a false alarm or a real one.

    My question is why do i loose my setting every time a reboot the RPi. I change all zone names etc. and every time i log back in i loose all the settings. I’m i doing something very wrong… :-/ I’ve setup a new user that which stays active even after a restart, but the actual settings always disappear.

    Thanks in advance and thanks again for your hard work on this project!!!

    • Hi Joe,

      Thanks for the comments – if I’m ever in Shropshire I’ll take you up on that beer.

      I’ve had a quick look at the Accenture gen4 panel, there doesn’t seem to be any easy way to interface the Rasapberry Pi to monitor the output. I used to have a similar system myself (central control unit linking to a smaller control panel over a proprietary serial interface). It might have been possible to hack the serial interface and get the Raspberry Pi to emulate the control panel – but I decided it would be easier, and more fun, to just build a new system from scratch.

      But in answer to your question…..
      ….the root cause of your issue is my interface, it still needs a lot of tidying up. Several of the screens have a ‘save’ button, and with a proper iPhone interface, they just wouldn’t be there.

      So currently, all the ‘save’ buttons take the information entered at the iphone, and send it back to the Raspberry Pi alarm service. So it only saves the information as far as sending it back to memory of the Pi. So there is another button – which actually takes all the settings from the Pi memory, adds any scheduled tasks, and writes it all to a file on the SD card.

      So on your iPhone, logon to the app, mnavigate to the ‘Setup‘ page, tap on ‘Defaults‘ and select ‘Save user defaults‘. This will dump the current state of the alarm service from memory to the text file /var/www/defaults.txt. At startup, the alarm service looks for this file, and if present, loads it back into memory. If the file isn’t present, it reverts to the default configuration by reading alternative data from the file /var/www/factory.txt. So if you are changing your SD card, or about to perform a rebuild, you will want to back up the defaults.txt file.

      Hope this helps sort your problem. If not, please let me know, as that would imply another issue which I would need to track down.

      Cheers

      Tony

  3. Thanks for your reply Tony.

    I’ve actually figured it out last night. What i did was i saved all my default settings into the factory.txt and i always get those on boot up. But i’ll try your method with the default.txt file.

    You’re right about the Gen4 panel. I think i’m going to ignore that and use the RPi as a control box. One thing i need to do is to have an alternative power source in case of a power cut. Similar system like the Accenta Gen4 has, chargeable battery. If i could figure out how the LCD keypad works on it that would be a bonus, but as you said, it might be easier to just get rid of it and use the RPi.

    I’ve got rid of the CheckIP function in your code as i’ve installed NO-IP client on my RPi which does the same job for me, and i’ve got a free host name to my system so i can access it over the internet. Although i need to change the code slightly, because at the moment the username and the password is in an unencrypted txt file and that could be exploited quite easy. I’ll try to save the passwords in the passwd, but unfortunately i’m not a great programmer, i’ve studied Network security so not much programming gone on there, apart from a bit of python and BASH. I guess i have to make the most of my free time until i’m back to work 🙂

    By the way, do you sell the PCB the one is connected to your Pi? Or do you know any good online company who can make one for me?

    Thanks
    Joe

    • Hi Joe,

      Sorry for the delay getting back to you – I’ve been back in the office this week – so spare time is a bit of a luxury.

      A quick note on Dynamic DNS (NO-IP): When I purchased my security cameras a few years back, I tried to register an address with DYDNS.COM. So I tried to set up something like MYHOUSE.DYNDNS.COM, but someone already had it. So I was curious and went and had a look. Then I got wondering if they had left the default password, then I realised what I was doing and what a great big advertisement having an URL was. So I like to think of it as ‘security through anonimty’ and access my system using the IP address without a Dynamic DNS entry. I regularly monitor the access logs on the Pi, and over the last year, no one has even found the system. But its up to you. Having your own little bit of the Internet is always quite appealing (says the guy with his own domain).

      You also asked about the circuit boards – that’s always a tough one to answer, so I’ve been giving it some thought.

      I used a local company P&M Services to make the PCB. The bulk of the cost is in the tooling up for the job. So you tend to get a quote for something like £150 for one, or £170 for five. So I went for five, which has left me a live system, a dev system, and three spare. Unfortunately there are issues with the hole size around the jack socket and some of the pad sizes (my fault for trusting the CAD package and not checking). This makes it an absolute swine to assemble the board, so I’m not keen on selling just the PCB board.

      So what I’m trying to do is assemble the three spares and then offer them at cost, on a sale or return basis. That way, if you don’t like it, ship it back and I’ll refund the cost. The cost would be £60, which is for the fully poulated PCB, so you would still need to source all cables, remote controls, power suplies etc.

      Cheers

      Tony

  4. Hi Tony,

    Hope you’re well. I’ve got a problem with my webserver. All of a sudden the website stopped working, i mean i get the login page but a soon as you try to login or even want to check the status it goes to the ‘fault’ page. I’ve reformatted the SD card put the latest rasbian on, reinstalled the whole alarm system as per above, but still nothing 🙁 Do you have any idea why is this happening??

    Thanks in advance
    Joe

    • Hi Joe,

      Usually the ‘fault’ page appears if the alarm service isn’t running. I’ll give a bit more explanation…..

      Each time the web page changes, it reads data from the file /var/www/uploads/status.txt. This file contains all the variables for the GUI, so things like the alarm channel names, scheduled tasks, the RC switch states etc. They are all contained in this file.
      But the file has a second use. It acts as a flag to prevent the web page re-loading before the Raspbery Pi has had a chance to perform the requested task. So when a command is sent from the iphone, the status.txt file gets deleted. This flags to the web page that it shouldn’t re-load just yet as the Raspberry Pi is still processing the command. When the Raspberry Pi has completed the command, it creates a new status.txt file, which flags to the web page that it should continue loading. This keeps the web page data in sync with the alarm service data.

      But if the status.txt file doesn’t get created within the timeout period, the web pages jumps to the ‘fault’ page, which is what you are seeing. In my experience, this happens when I’ve been writing new code, and I’ve somehow managed to crash the alarm service. So one of the things I’ve done on the Ver 2 code is to ensure that an alarm service restart ( sudo service alarm restart ) forces the creation of a new status.txt file to ensure a clean startup.

      So things to check are…
      1) The alarm service is actually running – you can do this with a sudo service alarm restart
      2) The SD card – slower or older cards can affect the performance of the Raspberry Pi and slow it down to the point that the status.txt file doesn’t get created within the timeout. You should be using a class 10 card, but I think they also specify that on the Raspberry Pi website. I’ve also seen a card ‘go bad’. This was my own fault, I messed up the code and left a loop running continually deleting and creating a file. I left it running for a couple of hours, and it reduced the card speed to the point that it could no longer run the alarm service.

      But there is also the possibility that I’ve messed up on the GitHub repositry for the Ver 2 code. One of the many changes I’ve put in is to tighten up on the file permissions and ownership, but I may have overtightened it.

      So I’m trying to work out if this could be an install issue. Can you confirm that you are using the Ver 2 code ? and if so, has it ever worked on your system.

      Cheers

      Tony

  5. Hi Tony,

    Thanks for your reply. It’s working now. I’ve just reinstall the whole system again.

    Another question: do you have one of those pre-assembeled circuit boards for sale. I’ve asked you few months back, not sure if you still have any left. I’d love to buy one from you if possible.

    Thanks
    Joe

    • Hi Joe,

      Glad to hear you got it all going. When you say you re-installed, are you still using the old code, or have you got the new version from the GitHub ? ( I’m just trying to confirm the current build on the GitHub is ok )

      I’m afraid the circuit boards just never happened. They are still on my list of stuff to do, but work keeps getting in the way. I’ll give you a shout if the situation changes.

      Cheers

      Tony

      • The github code is perfect. I’ve reinstalled wheezy on the SD card and i’ve just used your install method and it worked. I’ve tried to customise it as i haven’t got the same circuit as you have, but i’ve realised my coding skills a way to poor :(… I’m still working on it though…

        What i’m trying to do is to use 15 pins on the GPIO, 10 for controlling the light remote, 4 for PIRs and door sensors (i only have 3 PIRs and front door sensor) and 1 pin to trigger my bell box outside through a 12v relay. It seems simple enough, but i just couldn’t get it working :(… I’m using the existing alarm panel to keep the pi in which already has a UPS built in. The only thing i need is to mod the code but i need more self-study. That’s why i thought may as well buy one of the circuit boards from you and leave the code as it is.

        Cheers
        Joe

  6. Hi Tony,
    Thank you very march for your application. But, I’ve some problems with my web server. Alarm deamon was stopped on next strings
    “21:03:07,(alarm),(RasPi),Sound drivers initialised
    21:03:07,(alarm),(RasPi),GPIO ports initialised for Raspberry Pi Rev 2.0
    loading
    21:03:07,(alarm),(RasPi),Loading user credentials.
    load status file
    21:03:07,(alarm),(RasPi),Settings: Restoring last session.
    21:03:07,(alarm),(RasPi),Invalid email credentials or no circulation list – email not sent
    21:03:07,(task),(RasPi),Check router IP – no change
    21:03:10,(alarm),(RasPi),Zone 8 open

    and I can’t logon to the web page. I’ve ‘fault’ page.

    • Hi Adilet,

      Thanks for leaving the post. The messages show the alarm Daemon has started ok, and has started scanning for inputs and commands from the web page.

      The web page shows ‘fault’ when the file /var/www/uploads/status.txt is missing. Usually the simple fix is to restart the Daemon: From a terminal session run ‘sudo service alarm restart’ – this should force the alarm daemon to re-create the file, and fix the web page.

      If that doesn’t get it, then run through the full install process again. The directory structure and permissions are important, and may have gone wrong if you try to install over a prvious build.

      Let me know what happens either way. If the issue persists, I will try to re-create it here, and come up with a fix.

      Tony

      • Hi Tony,
        Thank you for your prompt reply.
        I have reinstall all my system (Wheezy and Alarm System), and i do not change any features (installed by default) but
        Alarm System still does not work :-(.

        • My SD cards class 10

          • Hi Adilet,
            A class 10 SD card should do the job. I’m wondering if we may have a region issue going on here. I’ve tested the software install here in the UK, but I gather thats not where you are based. Can you send me a copy of your /var/www/uploads/status.txt file ? That way I can see if we have any non-uk characters preventing the page from loading.
            Thanks
            Tony

  7. I’m sorry for my English. 🙂
    Tony can you share your previous code?

    Thanks,
    Adilet

    • Sorry Adilet – the old code has gone, and I didn’t keep a copy. The new version is much better, so I’d rather run with the new version ( and as per your last post ) fix any issues that may exist.

      • Hi Tony,
        I solved my problem. It was related to permissions. After the “sudo chmod -R 755 /var/www” command, web page become available.
        I will keep you informed about my installation process.
        Thank you for help.

        • Adilet,

          Glad to hear you got it going.

          One of the changes I made on the Version 2 code was to separate the files. So all web pages and scripts are read only files and are all stored in /var/www. I set the permissions on this directory to read and execute only. Also all these files belong to the root account. The idea is to protect them from being deleted or modified by anyone accessing through the web page. But there are a number of files ( only four or five ) that need to be modified directly by the web page. So I created the sub directory /var/www/uploads. The permissions on this folder allow anyone using the web page to create / delete files. But somehow this structure isn’t working on your instalation. So by opening up all the files to read/right/execute you have managed to fix it.

          So I’m trying to work out what could be trying to write to the /var/www folder ?. If I find it, I’ll get it fixed.

          Tony

  8. Tony,
    One more comment, when I click menu button, after set email features, I have a message ” call to xx.xx.xx.xx or cancel”? and these numbers are at the top of menu.

    • Yep OK – thats a bug !
      I remeber reading somewhere about an HTML statement that instructs the iPhone to not automatically dial every number it sees.
      I’ll add it to my list of stuff to fix.

      ( I’ve removed the link to your screenshot because it had your IP address in – you might have ended up with some unwanted traffic ! )

  9. Hi Tony,
    It’s me again :-).
    Unfortunately, I can’t configure alarm system by web page. When I add some settings on web pages then click “Back”, settings are not saved. Also sometimes “Back” button returns to the same page. For example: I add User and set his e-mail, his password and when try to go Back, i return to Set Password page again and can not close it or exit it.
    Please see below screenshot of a listing alarm.sh : https://www.dropbox.com/
    Thanks,
    Adilet

      • Hi Adilet,

        It looks like I still have some issues with the ‘back’ buttons. The JQT framework comes with a very basic ‘Back’ button, that just takes you back one page in the browser history. This is ok if you only ever drill down one level of menu. But a lot of my pages drill down two levels, and as you have found, you sometimes get stuck in a loop at the bottom. One of the changes I have made to the JQT framework is to add a new class of ‘back2div’, which goes back to a specified division, rather than relying on the browser history. So it looks like I still need to change some JQT ‘back’ buttons to the ‘back2div’ buttons.
        Cheers
        Tony

  10. Tony,
    below screenshot when i was try to add e-mail settings on setup pages. Then I just wanted to see “Defaults” page, and the settings (user defaults) have already been applied, although I did not choose this option.
    https://www.dropbox.com/s/kz66opvhz9wet0i/%D0%A4%D0%BE%D1%82%D0%BE%2002.07.14%2C%200%2036%2054.jpg

    Thanks.

  11. Hi Tony, sorry for my english.
    I did many times a fresh installation of 2014-06-20-wheezy-raspbian.img on 8GB class 10 SDHC card following your CONFIGURATION AND APPLICATION INSTALL guide without any issue.
    I rebooted the whole system and the alarm service and web server is running but after the login it always goes to the fault page.
    Please can you help me?

    Thanks,

    Ezio

    • Hi Tony,
      I found the problem, I’ll try to explain.
      The install script did not set the www-data group to the whole Web site files but only to the /var/www directory. All the files had root as group. I fixed it with the same command in the install script, sudo chgrp -R www-data /var/www/ and now it works.
      I already saw some little bug in the web interface (the Back button doesn’t work well in some pages) but I’ll let you know after my tests.

      Thanks,

      Ezio

    • Hi Ezio,

      Glad to hear you’ve got it going.

      It looks like there is a problem with the install script and the permissions on the web folder.
      I’ll have another look at it when I get a chance. I’d be interested to find out which buttons you are having issues with.

      Tony

      • Hi Tony,
        Thanks for your reply and for this great project.
        The install script sets before the rights to the directory and then it copy the file inside, that’s why.
        About the Back button and web interface, I’m testing it on iPhone 5S.
        In Edit user, Set password, it enters in loop and it’s no way to exit. If you don’t put the password, the old one will be deleted (is blank).
        In App Setup Duration, any choice goes back to App Setup page then the Back button goes back again to Duration page. The duration button have an arrow “>” like if it should go to another page but it’s just a choice button.
        The buttons on Menu page stay in green after a choice.
        In Edit Zone it doesn’t save the changes, just sometime, random.

        I don’t found any /sys/class/gpio/gpioXX files on my system, I don’t know why.

        This is my experience,

        Ezio

        • The Raspberry revision check in the alarm.sh file have a mistake.

          # Now check if we are on a Raspberry Pi….
          tmp=$(cat /proc/cpuinfo | grep Revision | awk ‘{print $3}’)
          if [[ $tmp = “0002” ]] || [[ $hardware = “0003” ]]; then
          hardware=’Raspberry Pi Rev 1.0′
          InitPorts # we are on a PI so initialise the ports
          fi
          if [[ $tmp = “000d” ]] || [[ $tmp = “000e” ]] || [[ $hardware = “000f” ]]; then
          hardware=’Raspberry Pi Rev 2.0′
          InitPorts # we are on a PI so initialise the ports
          fi

          In the two lines with $hardware = “0003” and $hardware = “000f”, should be $tmp = “0003” and $tmp = “000f”

          Final result:
          # Now check if we are on a Raspberry Pi….
          tmp=$(cat /proc/cpuinfo | grep Revision | awk ‘{print $3}’)
          if [[ $tmp = “0002” ]] || [[ $tmp = “0003” ]]; then
          hardware=’Raspberry Pi Rev 1.0′
          InitPorts # we are on a PI so initialise the ports
          fi
          if [[ $tmp = “000d” ]] || [[ $tmp = “000e” ]] || [[ $tmp = “000f” ]]; then
          hardware=’Raspberry Pi Rev 2.0′
          InitPorts # we are on a PI so initialise the ports
          fi

          Now it works,

          Ezio

        • Hi Ezio,

          Well spotted on the permissions issue. I’ve just changed the script on the Github to reverse the order, so it copies the files, then assigns the folder permissions recursively, but I’ve not had time to test it.
          Your observations on the back button match Adilet experience, so I definitely need to have another look at that section of code ( I’ve just posted him a reply giving a bit more detail ).
          And the green menu buttons thing, I’ve seen that myself. It seems to be coming straight out of the JQT framework, so I need to dig into their JQuery code and see if I can fix it. But to be honest, that bit isn’t my code, so I was going to live with it for a while and hope the guys over at SenchaLabs fix it for me.

          I’ve also noted your comment about detecting the hardware type. I need to update this section anyway to accomodate the new Raspberry Pi B+.

          So it looks like I need to put a weekend (or two) aside and try to fix some of these issues, and keep up with the changing hardware.

          Cheers
          Tony

  12. Hi Tony
    Website looks good and your alarm project is fantastic.
    How can i run the alarm menu on my iphone in demo mode only
    Many Thanks
    Tony

    • Hi Tony,

      To get the code to work in demo mode, you will need to run through the install process on this page. All the alarm zones will show as permanently open, and you won’t be able to use any of the radio control functions.

      But you (should) be able to create scheduled tasks, create user accounts, confiure alarm and radio chanels and check the logs. I say ‘should’ because there are a few issues with some of the pages which need a bit of tidying up.

      Cheers

      Tony

  13. Hi Tony,

    This project looks interesting and it is certainly a credit to your skills and effort.

    I have a couple of questions. Firstly, how difficult would it be to port the interface to Android? My wife is an Apple fan and I am Android. Is there a way we can both manage the alarm system from our respective phones? Secondly I would like to add the light control to be triggered by PIR so the lights follow you around the house but which also triggered the alarm in ARMED mode. Theoretically this wouldn’t be too tricky to incorporate but as you know the code better than most I was wondering if you knew of any limitations that might give me issues?

    Cheers in advance!

    • Hi Matt,

      I’ve never tried running the code on anything other than an iPhone 4. But the web pages are created through the jQT framework, which claims to operate under Android. So I guess you would just have to give it a go (and let us know what happens). Full details of jQT can be found at http://jqtjs.com. They have a link on the page that allows you to ‘preview on your phone’ so that would be an excellent starting point.

      As for your second question, yes its do-able. You could probably get it working by just altering the BASH shell scrip (alarm.sh). You would need to define a new operating mode similar to ‘standby’ – maybe ‘standby2’, and define some countdown timer variables. So every time the alarm goes around the main loop, it decrements the variable. When the variable gets to zero it turns the light off. Then in function ‘alarm_tests()’, you would need something similar to the section checking for chimes. So when a movement is detected, and the system is in mode ‘standby2’, the counter variable gets initialised. Then the last bit is when the variable is getting initialised, if the previous value was zero, then the lights should be turned on.

      Cheers

      Tony

  14. Hi Tony,

    Thanks for the info. I will have a look at all that and let you know how I get on. It will certainly be interesting to see if I can get it going.

    I have a couple of weeks off so I will get my Pi in action then. Now to source some bits in preparation!

    Yours aye,

    Matt

  15. Hi Tony, my email is above if you want me to have a play with the code for your phone app

    Cheers

  16. Hi Oddwires,

    I have downloaded and installed the latest version 3 and I am having some difficulties once I launch the service. This is a capture of the screen output:

    pi@AlarmPi ~/Download $ 12:33:51,(alarm),(RasPi),Zone 6 closed
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    12:33:52,(alarm),(RasPi),Zone 2 closed
    grep: /var/www/temp2.txt: No such file or directory
    rm: cannot remove `/var/www/temp2.txt’: No such file or directory
    12:33:53,(alarm),(RasPi),Zone 4 open
    sudo service alarm start12:33:55,(alarm),(RasPi),Zone 1 closed
    12:33:55,(alarm),(RasPi),Zone 8 open sed: can’t read /var/www/temp2.txt: No such file or directory
    grep: /var/www/temp2.txt: No such file or directory
    rm: cannot remove `/var/www/temp2.txt’: No such file or directory 12:33:57,(alarm),(RasPi),Zone 1 closed
    12:33:57,(alarm),(RasPi),Zone 8 closed
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    grep: /var/www/temp2.txt: No such file or directory
    rm: cannot remove `/var/www/temp2.txt’: No such file or directory 12:33:58,(alarm),(RasPi),Zone 5 open 12:33:58,(alarm),(RasPi),Zone 2 open
    stsed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    osed: can’t read /var/www/temp2.txt: No such file or directory
    psed: can’t read /var/www/temp2.txt: No such file or directory
    grep: /var/www/temp2.txt: No such file or directory
    rm: cannot remove `/var/www/temp2.txt’: No such file or directory

    I don’t have any hardware connected at the moment but I have also checked the files and /var/www/temp2.txt does not exist at all. There are other files in there:

    root@AlarmPi:/var# cd www
    root@AlarmPi:/var/www# ls
    about.png auto.php factory.txt jQTouch notfound.php setupscroll.php task.php user.php
    alarm.js autoscroll.php fault.php logs readvars.php smb.conf taskscroll.php user.txt
    alarm.php dologin.php icon.png logscroll.php Scripts sounds uploads writedata.php
    alarmscroll.php dostatus.php index.html logs.php setup.php startup.png userlist.php

    Any pointers?

    • Hi Matt,

      Thanks for the post and the feedback.

      I think I can see whats going on. The error message “sed: can’t read /var/www/temp2.txt: No such file or directory” is the first clue. This is coming from the ver 2 alarm service (the ver 3 code doesn’t use SED any more, I’ve re-worked it to use an array of variables, which simplifies the code, and speeds up operation).

      Then looking at the directory listing the “sounds” directory is also from Ver 2 not Ver 3.

      So I’m guessing you are trying to upgrade from Ver 2 code to Ver 3. Only I’ve not really built this functionality into the installer – the installer will go from a clean image to the final install, but only makes a token effort at clearing out previous installs, and as you’ve just spotted, it fails.

      So its an easy fix. Wipe the disk, re-apply the Wheezy image and re-run the installer.

      It looks like you’ve found the install instructions for Ver 3 which I have moved to wiki on the github…

      https://github.com/oddwires/alarm-system/wiki/Installing-the-Alarm-System

      I’ve just run through the install on my system using the 2014-09-09 Wheezy image and it works ok. There is a later Wheezy version, but its only a couple of days old, so the servers hosting it are getting hammered and I haven’t been able to download a copy yet.

      Let me know how it goes, as this version of code has a lot going for it, so I’m keen to get the installer running smoothly.

      Cheers

      Tony

  17. Hi Tony,

    You were right, I used a clean image and it worked.

    I also did the clean install on a RPi 2 and the latest wheezy and I can confirm that it works. Probably computing power overkill for the alarm but I plan on adding other services to the same Pi. I already have Plex running on another and a VPN running on a U3 odroid (because of the separate USB bus for ethernet) and both of those need 100% of the overhead on those devices.

    Now I just need to sort out my curcuit 🙂

  18. Ok, I spoke too soon. I stop and restarted a couple of times and I started getting this again:

    rm: cannot remove `/var/www/temp2.txt’: No such file or directory
    mv: cannot move `/var/www/temp1.txt’ to `/var/www/uploads/status.txt’: No such file or directory
    13:55:26,(alarm),(RasPi),Zone 8 open
    sed: can’t read /var/www/temp2.txt: No such file or directory
    grep: /var/www/temp2.txt: No such file or directory
    rm: cannot remove `/var/www/temp2.txt’: No such file or directory
    13:55:26,(alarm),(RasPi),Zone 8 closed
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    grep: /var/www/temp2.txt: No such file or directory
    rm: cannot remove `/var/www/temp2.txt’: No such file or directory
    13:55:27,(alarm),(RasPi),Zone 6 closed
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    sed: can’t read /var/www/temp2.txt: No such file or directory
    grep: /var/www/temp2.txt: No such file or directory
    rm: cannot remove `/var/www/temp2.txt’: No such file or directory
    13:55:27,(alarm),(RasPi),Zone 6 closed

    A reboot doesn’t help. 🙁

  19. Ah I have found out that by following the instructions on this page I download version 2 and not the most up to date V3.

    I shall do a manual download.

  20. Hi Matt,

    Thanks for checking the code on the RPi 2 – nice to know that it works on the new hardware. But I agree with your comment about computing power over kill, the code practically flies along on the original RasPi’s, so even more computing power is nice, but not essential.
    Glad to hear you sorted out the install issues. I’ve completely removed the V2 install instructions from this page, and replaced them with a pointer to the V3 instructions on the Github – hopefully this will avoid any more confusion.

    You mentioned sorting out your circuit. I have a couple of spare circuit boards if your interested.

    Cheers

    Tony

  21. hi there can you email me the steps as been trying but keeps saying timed out when i do the git thing

    from peter

  22. Hi there still no look i know i am not behind an firewall as i done stuff befor with out any prob but its all the time the same prob

    • I’ve just managed to download the software from the Github without any issues – so it looks like your network is playing up.

  23. Thank you for this, cant believe that me just finding it, been looking for something like this for a long time, cant wait to get started

  24. Hi with all the new GPIO on the Pi2 can you w=have an update that will just use the GPIO as they are and can you tell me what GPIO does what ? thanks

  25. Hi Tony,
    Thank for the information. I’m getting started on a project and looking to use your system as a starting point. Can you provide more info on the circuit board? Such as information on the design/components? Or more background on what the function/purpose of it is would be very helpful.
    Thanks in advance,
    Tom

  26. Hi Tom,
    The circuit board is the interface between the 12 volt alarm circuits and the Pi GPIO ports. The output circuits (alarm, strobe and sounder) are based on a domestic alarm panel that I reverse engineered. The input circuits use opto isolators to step the 12volts sensor levels down to levels suitable for the Pi. I have a short YouTube video explaining how they work. Then the final part is the PIC chip and radio transmitter module. These allow the device to control standard radio control power sockets around the house.
    I’m not intending to publish the design, as programming the PIC chip and matching the transmitter modules is rather complicate.
    But now and again I do have spare circuit boards if you are interested.
    Tony

Leave a Reply

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


6 × three =