Save sensor data in mysql to python

Hello I want to save sensor data in mysql to python. Sensor is connected to arduino and arduino send data to raspberry pi via bluetooth. So I construct python code in raspberry pi to receive sensor data and save in mysql. After I compile the code sensor data received but it’s not saved in mysql. Only ‘0’ is saved in mysql. And this is my code

#! /usr/bin/python

import bluetooth
import MySQLdb

bd_addr="MAC ADDRESS"
port=1
sock=bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((bd_addr,port))
data=""
db=MySQLdb.connect("localhost", "root", "1234", "testdb")
curs=dbcursor()
print 'Start Monitor'

while 1:
  try:
    data +=sock.recv(1024)
    data_end=data.find('\n')
    if data_end!=-1:
      rec=data[:data_end+1:]
      print data
      data=data[data_end+1:]
      strQuery="INSERT INTO weight (kg) VALUES(default, "+data+")"
      curs.execute(strQuery)
      db.commit()

  except KeyboardInterrupt:
    break
sock.close()
db.close

If I run this code appropriate sensor data is displayed in python terminal , but ‘0’ is saved in mysql. How can I fix it?

test your sql directly in mysql, not through an application language

this sql has a syntax error

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.