Friday 7 March 2014

New App available for iPhone and iPod

My 11yr old son has written his first apple app, and it is called 'Clic it!'.

If you have any problems using the app, or find bugs, please let us know. Updates to follow.

His app is available here

Friday 28 December 2012

Raspi python script on startup


Attempting to get a Python script to run on bootup


Door Bell
Raspberry Pi door bell, with X-Mini as amp

I used the following code to get doorbell.py to run on boot up.


sudo bash
sudo nano /etc/init.d/doorboot

### BEGIN INIT INFO
# Provides: doorboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start door bell python script at boot time
# Description: Start doorbell at boot time.
### END INIT INFO
#! /bin/sh
# /etc/init.d/doorboot
case "$1" in
 start)
   echo "Starting DoorBell"
   python /home/pi/doorbell.py &
   ;;
 stop)
   echo "Stopping DoorBell"
   python -kill :0
   ;;
 *)
   echo "Usage: /etc/init.d/doorboot {start|stop}"
   exit 1
   ;;
esac
exit 0

chmod 755 /etc/init.d/doorboot
update-rc.d doorboot defaults

It doesn't appear to work, but this does start the app
sudo /etc/init.d/doorboot start

Anybody got any ideas?
and what is a .logon file and where would I find it?


Door Bell


First attempt to build a raspberry Pi door bell

Having just bought a Raspberry Pi for my 10 year old son, I thought I'd better get one step ahead of him and find out how it works.

So I have set out to create a Python program that emails my Iphone when a GPIO input is grounded.

So far I have broken that task down into 5 sections

  1. Email
  2. GPIO
  3. Play doorbell sound via audio jack
  4. Join all sections tidy like
  5. Auto start python in background mode

Email


My first simple python program to send a single msg from the Raspi






#!/usr/bin/python

import smtplib


gmail_user = <gmail user name>
gmail_pwd = <gmail password>
fromaddrs="doorbell"
toaddrs = <to my iphone email address>

msg="Subject: doorbell, there is somebody at the door"
server = smtplib.SMTP("smtp.gmail.com:587")
server.starttls()
server.login(gmail_user,gmail_pwd)
server.sendmail(fromaddrs, toaddrs, msg)
server.quit()
print("Sent: ", msg)




GPIO



Uses wiringpi



#!/usr/bin/python
import wiringpi
from time import sleep
##ensure that pin 17 is set as input
## and pull up is set
call (["gpio", "export 17 in"])
call (["gpio","-g","mode 17 up"])
# to use Raspberry Pi board pin numbers
#GPIO.setmode(GPIO.BOARD)
io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_SYS)
io.pinMode(17,io.INPUT)
#Read input pin and print current value
while True:
    # input from RPi board pin 17
    input_value = io.digitalRead(17)
    print(input_value)
    sleep(0.1)


AUDIO OUT 


#!/usr/bin/python

from subprocess import call

print('ding dong')call(["mplayer","Ding Dong.mp3"])  


Final tidy version



#!/usr/bin/python
## Changed call to Popen to get the mp3 player to run as a subprocess
## Opened a google account just for my doorbell
## Set up a the doorbell as a VIP on my Iphone with doorbell sound
import wiringpi
from time import sleep
import smtplib
import string
from subprocess import Popen
msg="There is somebody at the door"
##ensure that pin 17 is set as input
## and pull up is set
call(['gpio','export','17','in'])call(['gpio','-g','mode','17','up'])
     
# to use Raspberry Pi board pin numbers
io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_SYS)
io.pinMode(17,io.INPUT)

#This function sends an email message to toaddrs
def sendmsg(msg):
    gmail_user = "**********"
    gmail_pwd = "**********"    fromaddrs = "frontdoor"
    toaddrs ="iPhone1, iPhone2, Ipod3"
    subject = "Doorbell"    body=[]
    body='\n'.join([
        "From: %s" % fromaddrs,
        "To: %s" % toaddrs,
        "Subject: %s" % subject,
        " ",
        msg
        ,'\r\n'])
            
    server = smtplib.SMTP("smtp.gmail.com:587")
    server.starttls()
    server.login(gmail_user,gmail_pwd)
    server.sendmail(fromaddrs, toaddrs.split(","), body)
    server.quit()
    return

#Run a continuous loop checking for bell push
while True:
   # get input from GPIO
    input_value = io.digitalRead(17)
   #Let RasPi rest for a bit  
    sleep(0.1)
    if input_value==False:
        # if pin is grounded sound bell and send email        p=Popen(["mpg123","-q","Ding Dong.mp3"])        sendmsg(msg)


RUNNING PYTHON SCRIPT AT START UP