Data logging in Revolution Pi

Topics about the Software of Revolution Pi
Post Reply
Anil
Posts: 41
Joined: 24 Jul 2019, 09:13
Answers: 0

Data logging in Revolution Pi

Post by Anil »

Hello Kunbus Team,

As the Revolution pi has eMMC flash memory and I want to store/log data in RevPi (Modbus/Ethernet IP or data taken by using any other protocol ) in SQL or Mongo DB or any other database program. Is it possible to do so?


Thanks & Regards,
Anil Sarode
User avatar
dirk
KUNBUS
Posts: 1939
Joined: 15 Dec 2016, 13:19
Answers: 4

Re: Data logging in Revolution Pi

Post by dirk »

Hi Anil, well this is a question that is asked frequently. Have a look at this post.
Anil
Posts: 41
Joined: 24 Jul 2019, 09:13
Answers: 0

Re: Data logging in Revolution Pi

Post by Anil »

Thanks, Dirk for your response.

In Revolution Pi Connect I install the MySQL server.
Then created the database and in that database by creating the table I populate the values using python MySQL Connector.

Code: Select all


##################################################################################################
# This Example save the data of sensor values into RevPi using Mysql database.
# The sensor data is get/generated using the modsim  simulator.
# Author-Anil Ramesh Sarode TO@ULEPL
###################################################################################################


import time
import datetime
import mysql.connector
from mysql.connector import Error
from mysql.connector import errorcode
import revpimodio2                         # To read the pins of revPi

revpi = revpimodio2.RevPiModIO(autorefresh=True) # Instance to access to the IOs of the RevPiimport revpimodio2

connection = mysql.connector.connect(host='localhost',
                                     database='sensor',
                                     user='root',
                                     password='UL@123')

ti = time.gmtime()


def dateTime(): #get UNIX time
        secs = time.asctime(ti)
#        secs = secs*1000
        return secs

def tempRead(): #read temperature, return float with 3 decimal places
        degrees = float('{0:.3f}'.format(revpi.io.Input_Word_1.value))
        return degrees

def pressRead():#read pressure, return float with 3 decimal places
        pascals = float('{0:.3f}'.format(revpi.io.Input_Word_2.value/100))
        return pascals

def humidityRead(): #read humidity, return float with 3 decimal places
        humidity = float('{0:.3f}'.format(revpi.io.Input_Word_3.value))
        return humidity


secs = dateTime()
temperature = tempRead()
pressure = pressRead()
humidity = humidityRead()
#ID_number=1


try:
        mySql_insert_query= """INSERT INTO Sensor_Modbus_TCP_Data (datetime,temperature,pressure,humidity) VALUES (%s,%s,%s,%s)"""
        args =(secs, temperature, pressure, humidity)

        cursor = connection.cursor()
#       result = cursor.execute(mySql_Create_Table_Query)
#       print("Sensor_ModbusTCP_Data Table created successfully ")

        cursor.execute(mySql_insert_query,args)
        connection.commit()
        print(cursor.rowcount, "Record inserted successfully into Sensor_ModbusTCP_Data  table")
        cursor.close()

except mysql.connector.Error as error:
#    print("Failed to create table in MySQL: {}".format(error))
     print("Failed to insert record into Sensor_ModbusTCP_Data  table {}".format(error))

finally:
    if (connection.is_connected()):
        cursor.close()
        connection.close()
        print("MySQL connection is closed")

print (secs)
print (temperature)
print (pressure)
print (humidity)
Before executing this code, I configured the RevPi Connect as Modbus TCP master and enable the data logging to eMMC as per this guide https://revolution.kunbus.de/tutorials/ ... r-stretch/
So my question is very simple does this way to log the data is the correct method or way?
If this is the correct way how can we make it Real-Time?
User avatar
dirk
KUNBUS
Posts: 1939
Joined: 15 Dec 2016, 13:19
Answers: 4

Re: Data logging in Revolution Pi

Post by dirk »

Hi Anil, the eMMC has a limited life time so our aim was to provide you with a feature that prevents exhautive eMMC writes. But the trade-off is that you log to the RAM instead. So there is no right or not here as you have to examine what happens to your mysql database if you write your data to RAM and have to reboot.
So maybe you consider alternative ways i.e. sqlite or rsyslog.
Post Reply