Python Forum
sending arduino data to python and use a parity check
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sending arduino data to python and use a parity check
#1
hello,
i will read sensordata in my arduino(automatic greenhouse), this data will be sent to my rpi. With a python code i will send this arduino data to my database (mysql)
but i have a problem with the reading of the arduino data because this isn't send data around the 10 secondes. for this problem i will use parity check but i don't know how to use this. Can someone help me?
thank you
import serial
import csv
import mysql.connector
from mysql.connector import Error
import time
import datetime as dt
from time import sleep
localtime = time.localtime(time.time())
ser = serial.Serial('/dev/ttyACM0', 9600)
ser.flushInput()
dat = ser.readline().decode()

try:
    connection = mysql.connector.connect(host='localhost',
                             database='Xterus_Hortus',
                             user='root',
                             password='Xterus')
    if connection.is_connected():
       db_Info = connection.get_server_info()
       print("Connected to MySQL database... MySQL Server version on ",db_Info)      
    while 1:
        dat = ser.readline().decode()
        localtime = time.asctime(time.localtime(time.time()))
        print(dat)
        print(localtime)
        a,b,c,d,e,f,g,h = dat.split(" ; ")
        print(a)
        print(b)
        
        sql_insert_query = """ INSERT INTO `alle sensoren`(`tijd`, `temperatuurbinnen`,`vochtigheidbinnen`,`temperatuurbuiten`,`vochtigheidbuiten`,`pHwaarde`,`vochtigheidbodem`,
`hoeveelheidwater`,`co2`) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s)"""
        cursor = connection.cursor()
        result  = cursor.execute(sql_insert_query, (localtime,a,b,c,d,e,f,g,h,i))
        connection.commit()
        print ("Record inserted successfully into python_users table")
        time.sleep(1000)
except mysql.connector.Error as error :
    connection.rollback() #rollback if any exception occured
    print("Failed inserting record into python_users table {}".format(error))
       
Reply


Messages In This Thread
sending arduino data to python and use a parity check - by 10_Lucas - Jul-08-2019, 10:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  send a byte of data by bluetooth to arduino using python. x1cygnus 1 6,279 Mar-13-2020, 04:54 PM
Last Post: VerlaHiltz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020