# ky_026_flame.py - report presence of IR light from flame to serial
# (c) BotBook.com - Karvinen, Karvinen, Valtokari
# modified 6 Oct 2017

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

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


def main():

	broker_address="10.0.0.5"
	client = mqtt.Client("P1")	
	client.connect(broker_address)
	topic = "nuotiovahti_flame"
	flamePin = 8
	gpio.mode(flamePin, "in")

	#small wait to be sure
	print ("starting flame sensor...")
	time.sleep(0.5)
	
	while(True):
		flame = gpio.read(flamePin)
		if(flame == gpio.LOW):
			client.publish(topic,"Flame detected" + time.ctime())
			print ("Flame detected " + time.ctime())
		else:
			client.publish(topic,"NO flame detected" + time.ctime())
			print ("NO flame detected " + time.ctime())
		time.sleep(2)

if __name__ == "__main__":
	main()



@@ -259,17 +259,24 @@
 n():%0D%0A%0D%0A
-%09
+        
 broker_a
@@ -288,19 +288,32 @@
 s=%221
-0.0.0.5%22%0D%0A%09
+39.59.140.158%22%0D%0A        
 clie
@@ -335,15 +335,27 @@
 t(%22P
-1%22)%09%0D%0A%09
+2%22)      %0D%0A        
 clie
@@ -382,17 +382,24 @@
 dress)%0D%0A
-%09
+        
 topic = 
@@ -414,18 +414,19 @@
 ahti
-_flame%22%0D%0A%09
+%22%0D%0A        
 flam
@@ -435,17 +435,24 @@
 in = 8%0D%0A
-%09
+        
 gpio.mod
@@ -476,34 +476,43 @@
 %0D%0A%0D%0A
-%09#small wait to be sure%0D%0A%09
+        #Learning period%0D%0A        #
 prin
@@ -547,30 +547,20 @@
 %22)%0D%0A
-%09time.sleep(0.5)
 %0D%0A
-%09
 %0D%0A
-%09
+        
 whil
@@ -569,18 +569,32 @@
 True):%0D%0A
-%09%09
+                
 flame = 
@@ -614,18 +614,32 @@
 mePin)%0D%0A
-%09%09
+                
 if(flame
@@ -654,19 +654,40 @@
 .LOW):%0D%0A
-%09%09%09
+                        
 client.p
@@ -725,35 +725,57 @@
  time.ctime())%0D%0A
-%09%09%09
+                        #
 print (%22Flame de
@@ -804,20 +804,55 @@
 ))%0D%0A
-%09%09else:%0D%0A%09%09%09
+                else:%0D%0A                        
 clie
@@ -909,11 +909,33 @@
 ))%0D%0A
-%09%09%09
+                        #
 prin
@@ -979,10 +979,24 @@
 ))%0D%0A
-%09%09
+                
 time
@@ -1002,17 +1002,17 @@
 e.sleep(
-2
+3
 )%0D%0A%0D%0Aif 
@@ -1040,17 +1040,24 @@
 %22:%0D%0A
-%09
+        
 main()%0D%0A
 %0D%0A%0D%0A
@@ -1052,12 +1052,8 @@
 main()%0D%0A
-%0D%0A%0D%0A

Update mqtt_flame.py