Basically I am trying to upload the data collected from my raspberry pi to MySQL, I have a table called DHT_data with columns 'datetime' using data type timestamp, 'temp' using data type numeric, 'hum' using data type numeric as well. However using my Python script shown below I keep getting errors like indentation error or syntax error. I am currently new to programming so I don't really know what's the problem. Would appreciate any help in finding the solution or rectifying any errors with the script since I am not sure if it works yet
import time
import Adafruit_DHT
import MySQLdb
import sys
from time import sleep
DHTpin = 4
try:
db = MySQLdb.connect("localhost", "root", "dmitiot", "IOTassignmentBobo")
curs = db.cursor()
print("Successfully connected to database!")
except:
print("Error connecting to mySQL database")
update = True
while update:
humidity, temperature = Adafruit_DHT.read_retry(11, DHTpin)
if humidity is not None and temperature is not None:
hum = round(humidity)
temp = round(temperature, 1)
print('Temp:{:.1f}C'.format(temp))
print('Hum:{:.1f}'.format(hum))
curs.execute("""INSERT INTO DHT_data(datetime,temp,hum)
VALUES(CURRENT_TIMESTAMP,temp,hum)""")
print("Inserted Record")
db.commit()
sleep(5)
except MySQLdb.Error as e:
update = False
curs.close()
db.close()