Home/Support/Support Forum/RF python insert mysql db
New and improved user forum site going live on 12/6 (All users will need to reset their password when the new forum is active)

RF python insert mysql db

0 votes
Hi, I'm having an issue trying to do an insert into mysql from Digi HP900 RF modem. I can grad the data from the device but it won't read the data correctly to do the insert. Does anyone see any issues with this syntax here :

import mysql.connector;
from digi.xbee.devices import XBeeDevice

# TODO: Replace with the serial port where your local module is connected to.
PORT = "/dev/ttyUSB1"
# TODO: Replace with the baud rate of your local module.
BAUD_RATE = 115200


def main():
print(" +
+")
print(" | XBee Python Library Receive Data Sample |")
print(" +
+\n")

device = XBeeDevice(PORT, BAUD_RATE)

try:
device.open()

def data_receive_callback(xbee_message):
print("From %s >> %s" % (xbee_message.remote_device.get_64bit_addr(),
xbee_message.data.decode()))

device.add_data_received_callback(data_receive_callback)
xbee_message = device.read_data()
connection = mysql.connector.connect(host='localhost',database='dbcapture',user='root',password='XXXX')
cur = connection.cursor()
cur.execute("insert INTO dbtable (`post_id`, `tempdata`, `split0`, `status`, `lastupdate`, `text`, `content`, `likes`) VALUES ('1', %s, 'split0', '2', CURRENT_TIMESTAMP, 'mynkey', 'joe', 'hello'),(xbee_message);")
connection.commit()
connection.close()
print("Success")
input()
print("Waiting for data...\n")

finally:
if device is not None and device.is_open():
device.close()


if __name__ == '__main__':
main()
asked Jul 25 in XBee Programmable Development by matyodesign New to the Community (1 point)
OKAY I HAD SAME DOUBT

Please log in or register to answer this question.

1 Answer

0 votes
You might want to look at the several different Libraries and examples that exists for this.
answered Aug 4 by mvut Veteran of the Digi Community (15,515 points)
...