
# parallax_pir_reva.py - write to screen when movement detected
# (c) BotBook.com - Karvinen, Karvinen, Valtokari
# modified from original 27.9.2017

#-*- coding: utf-8 -*-

import time
import botbook_gpio as gpio
import paho.mqtt.client as mqtt


learningPeriod = 30

def main():

	broker_address="172.28.172.185" 
	client = mqtt.Client("P1") #create new instance
	client.connect(broker_address) #connect to broker

	pirPin = 7	
	gpio.mode(pirPin,"in")
	#Learning period
	print ("learning... " + str(learningPeriod) + " seconds")
	time.sleep(learningPeriod) # <1>
	while (True):	
		movement = gpio.read(pirPin) # <2>	
		if(movement == gpio.HIGH):
			client.publish("nuotiovahti","Movement detected" + time.ctime())
			print ("Movement detected " + time.ctime())
		else:
			client.publish("nuotiovahti","NO movement detected " + time.ctime())
			print ("No movement detected " + time.ctime())
		time.sleep(2)	


if __name__ == "__main__":
	main()

@@ -1,9 +1,8 @@
-%0A
 # parall
@@ -275,17 +275,24 @@
 ain():%0A%0A
-%09
+        
 broker_a
@@ -304,25 +304,32 @@
 s=%221
-72.28.172.185%22 %0A%09
+39.59.140.158%22 %0A        
 clie
@@ -372,17 +372,24 @@
 nstance%0A
-%09
+        
 client.c
@@ -431,17 +431,24 @@
 broker%0A%0A
-%09
+        
 pirPin =
@@ -449,19 +449,25 @@
 rPin = 7
-%09%0A%09
+%0A        
 gpio.mod
@@ -481,17 +481,24 @@
 n,%22in%22)%0A
-%09
+        
 #Learnin
@@ -506,17 +506,24 @@
  period%0A
-%09
+        
 print (%22
@@ -572,17 +572,24 @@
 conds%22)%0A
-%09
+        
 time.sle
@@ -613,17 +613,24 @@
 ) # %3C1%3E%0A
-%09
+        
 while (T
@@ -634,20 +634,33 @@
  (True):
-%09%0A%09%09
+%0A                
 movement
@@ -689,12 +689,25 @@
  %3C2%3E
-%09%0A%09%09
+%0A                
 if(m
@@ -729,19 +729,40 @@
 .HIGH):%0A
-%09%09%09
+                        
 client.p
@@ -810,35 +810,57 @@
 + time.ctime())%0A
-%09%09%09
+                        #
 print (%22Movement
@@ -891,19 +891,54 @@
 ())%0A
-%09%09else:%0A%09%09%09
+                else:%0A                        
 clie
@@ -1006,11 +1006,33 @@
 ())%0A
-%09%09%09
+                        #
 prin
@@ -1078,10 +1078,24 @@
 ())%0A
-%09%09
+                
 time
@@ -1105,11 +1105,10 @@
 eep(
-2)%09
+1)
 %0A%0A%0Ai
@@ -1137,9 +1137,16 @@
 _%22:%0A
-%09
+        
 main

Update mqtt_pir_test.py