import time
import pika
import json
import signal
import os
import RPi.GPIO as GPIO
import time
def getSensorData(object):
	while object.getLoopState():
		time.sleep(1)
		if object.getMessageSignal() == True:
			print 'Visiter message received'
			message = json.dumps(object.getMessage(), indent = 2)
			print message
			MessageBroker = pika.BlockingConnection(pika.ConnectionParameters(host = '127.0.0.1',
											virtual_host="mycomputer",
											credentials=pika.PlainCredentials("arun","rai",True)))
			""" Setup the exchange """
			channel = MessageBroker.channel()
			channel.exchange_declare(exchange="HomeGuard",type="fanout")

			""" Send the message """
			channel.basic_publish(exchange="HomeGuard",
						  routing_key="Detection", body= message)

			""" Close the connection """ 
			MessageBroker.close()
			object.setMessageSignal(False)

@@ -89,16 +89,888 @@
 rt time%0A
+GPIO.setmode(GPIO.BCM)%0A%0ATRIG = 23%0AECHO = 24%0A#assign pins%0AGPIO.setup(TRIG,GPIO.OUT)%0AGPIO.setup(ECHO,GPIO.IN)%0Asignal.signal(signal.SIGUSR1,restart)%0Awaitstart=time.time()%0Adef collectsensordata():%0A%09print %22Program Started%22%0A %09try:%0A%09%09pause=0%0A%09%09while 1:%0A%09%09%09#reset the sensor%0A%09%09%09GPIO.output(TRIG, False)%0A%09%09%09time.sleep(2) %0A%09%09%09#trigger the sensor%0A%09%09%09GPIO.output(TRIG, True)%0A%09%09%09time.sleep(0.00001)%0A%09%09%09GPIO.output(TRIG, False)%09%0A%09%09%09%0A%09%09%09while GPIO.input(ECHO)==0:%0A%09%09%09%09pulse_start = time.time()%0A%09%09%09while GPIO.input(ECHO)==1:%0A%09%09%09%09pulse_end = time.time() %0A%09%09%09pulse_duration = pulse_end - pulse_start%0A%09%09%09distance = pulse_duration * 17150%0A%09%09%09distance = round(distance, 2)%0A%09%09%09if pause==0 and distance%3E2:%0A%09%09%09%09pause=1 %0A%09%09%09%09waitstart=time.time()%0A%09%09%09elif pause==1 and distance%3E400:%0A%09%09%09%09pause=0%0A%09%09%09elif time.time()-waitstart%3E300:%0A%09%09%09%09pause=0%09%09%09%09%0A%0A%09%09%09%0A%09except KeyboardInterrupt: %0A%09%09GPIO.cleanup()%0A%0A%0A
 def getS

Update getSensorData.py