Bottom Page

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))
       

Quote
#2
Pls post the errors you are getting.
In Python, time.sleep(n) sleeps for n seconds. So, your sleep command will sleep for 1000 seconds, or about 17 minutes. Was this your intent?
Quote
#3
the error is: finding 4 of the 9 variables. and the time.sleep is right, i will send around the 17 min the sensor data to the database
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Please check code Evgeniy2019 4 223 Apr-05-2019, 06:37 PM
Last Post: Evgeniy2019
  How to check an array exist in a file using Python fitrisibarani 17 677 Feb-27-2019, 04:16 PM
Last Post: ichabod801
  Hi how to take row 1 for every column and check the value what class is it kirito85 2 439 Nov-21-2018, 06:52 AM
Last Post: kirito85
  Code to use output from arduino as input (help) Updownrightleft 0 300 Nov-03-2018, 11:04 PM
Last Post: Updownrightleft
  Reformat csv data with Python ksdst1 8 917 Jul-25-2018, 09:39 PM
Last Post: Larz60+
  Check if string is uppercase or lowercase and eliminate Wolfpack2605 1 1,434 Jan-01-2018, 05:03 AM
Last Post: Mekire
  Check if integer is between two values Wolfpack2605 3 13,857 Dec-24-2017, 06:39 AM
Last Post: DeaD_EyE
  Iterating over pandas.df to check for values out of range Padowan 14 4,374 Nov-26-2017, 04:37 PM
Last Post: heiner55
  check conenction takes byte or not viens 1 762 Nov-01-2017, 06:45 PM
Last Post: nilamo
  "Call the subroutine in order to check..." misa_san 1 971 Sep-24-2017, 09:30 AM
Last Post: stranac

Forum Jump:


Users browsing this thread: 1 Guest(s)