import serial
import time
import MySQLdb as mdb
arduino = serial.Serial('/dev/ttyACM1', baudrate=9600)
data = arduino.readline()
time.sleep(1)
data = arduino.readline()#read data from arduino
pieces = data.split("\t") #spl2t the data by the tab
temperature = pieces[0]
humidity = pieces[1]
flames = pieces[2]
if temperature > 0.00 and temperature <= 30.00 : temp = "Normal"
elif temperature > 30.00 and temperature <= 35.00 : temp = "Hot"
elif temperature > 35.00 : temp = "Dangerous"
if flames == 0 : flame = "Close fire"
elif flames == 1 : flame = "Distance fire"
elif flames == 2 : flame = "No fire"
con = mdb.connect("localhost", "root", "test", "FYPtest")or die ("could not connect to database")
with con:
cursor =con.cursor()
cursor.execute("INSERT INTO fyp (TEMP,HUM,T_STAT, F_STAT) VALUES (%s, %s,%s, %s)", (temperature,humidity,temp,flame ))
con.commit()
cursor.close()
Ok so basically this is the python code to let me get data from arduino and display in Raspberry Pi. Although i able to get the temperature value which is 30. However, the temp status is Dangerous, by right i should be “Normal” value is under 30. Can anyone help me to solve this issue? TQ