PI_newbee
Posts: 172
Joined: Mon Aug 26, 2013 7:41 pm

Code reorganisation :-) --> test sample

Thu Dec 01, 2016 10:12 am

Hi to all.
As python newbee i will try to describe my situation as best as i can :-)
In fact, it's not so complicated but like i wrote am still learning.

Device function:
- doorbell intercom

Scenario:
- User presses tactile button
- sound is played
- read the value from external javascript ( extrabacon is installed for that purposes )
---> if user has answered
--------> send hasAnswered from JS to this python script
-------> starting javascript file for voip communication
-------> when the communication is done --> JS sends hangup value
- wait for nest button press
---> if user has NOT answered
-------> take picture
-------> delay for writing picture to file ( 3 sec )
-------> email with attached picture is send to owner
DONE

This is just ultra simple test code without JS part:

Code: Select all

import RPi.GPIO as GPIO
import  subprocess
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.IN) 

state = 0
while True:
      input = GPIO.input(40)
      if (input == False): 
              if (state == 1):  
                    state = 0
 		   # player.stdin.write("q")
	       
	      elif (state == 0):
	            subprocess.Popen(["aplay", "DoorBell.wav"]);
		   
		# chech for call state 

		# if not accepted
   	            subprocess.Popen(["fswebcam","-r 640x480", "testPic.jpg"]);
		    # delay  
                    subprocess.call(["python", "sender.py"])
                #-----------------------------------------    	        
                     state = 1
The code is working and im getting mail with photo ( always the one before the last one :-) ).
I need to reorganize the code so i can set the countdown and delay time, and exit the loop when the button was pressed.
Basically, main part is to detect this button press and according to that, make some action.

Any suggestion is welcome !
PIN

in-ven-tor
Posts: 3
Joined: Sun Jan 22, 2017 5:58 pm

Re: Code reorganisation :-) --> test sample

Mon Jan 23, 2017 12:37 pm

Hi thanks for ur post,

In fact I don't have an answer for ur problem, I'm a nweebie as well, but I'd like to ask u, if u don't mind that, to tell me the hardware u used for this and if u have a picture of the circuit.

I'm working on a similar project, I'd like to make a voip doorbell intercom (tha has a camera, speaker, and microphone) and it should be working like this:

first : the camera is always on, records the video and streams it to a website.
second:
-someone presses the doorbell------->>one or more devices ( that are connected to internet, and that rasberry recognizes through their Ip adress) ring.
-a user(A) on one of the devices answers------>>he starts watching the video streaming of the camera, and can talk with the person(B) in front of the door that is:
(A) talks----->>voice sent from device(A) to rasberry through internet----->>voice sent from rasbery to speaker through internet.
(B) talks----->>voice sent from microphone (intercom) to rasberry through internet----->>voice sent from rasbery to device(A) through internet.

I have another question if u don't mind; do u think we can send the voice directly from phone to intercom and vice versa without the medium of rsp?
Thank u

Return to “General discussion”