0

As a side project I have been interested in energy consumption. I have written and executed a program on a raspberry pi 3; this uses external hardware to gather data over Ethernet using ModbusTCP.

Within my program that is a data logging feature that creates and saves a CSV file with the values collected for that day. Every day at midnight a new CSV file is created and marked with the new day's date. This CSV file is saved locally on the raspberry pi and as it runs headless I’ve had to set up a cronjob to move the files onto a Thumb drive to allow me to view and assess the CSV file.

The modification I am trying to attempt is: I currently have a PostgreSQL database on a separate server; I am trying to get the Raspberry Pi to connect to the database and populate it with data as soon as the Pi has recorded it.

I have searched the internet, both this site and many others, but most of what I have found is tutorials and guides on how to set the Raspberry Pi up as a PostgreSQL server, which is not what I want to achieve.

Any advice and help is greatly appreciated.

Carl

Update : the programming language i am using is python 3

  • You should tell us what language you use. Most languages have libraries allowing to write to a remote database... – mdag02 May 24 '18 at 15:14
  • You can install the postgres client on the pi and then [run a command to have the database consume the csv](https://stackoverflow.com/questions/33353997/how-to-insert-csv-data-into-postgresql-database-remote-database?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) – JNevill May 24 '18 at 15:21
  • Although there a lot of other ways to do this. You could rsync the data over to the server's file system or NFS mount a PI folder on the server and have cron on the psql server consume the file using `psql` command or use whatever library is available in whataever language you are using to connect and INSERT the data into the database. – JNevill May 24 '18 at 15:22

1 Answers1

0

I would investigate using ssh. You can transfer the csv, and then invoke a script on the target machine, wait for a cron or just call pgctl at the remote command line. That will avoid the necessity of setting up a client on the PI, and opening the firewall at port 5432, configuring pg_hba.conf, etc.

Curt Evans
  • 346
  • 2
  • 4
  • Thank you for your help, I currently have SSH set up and can do it through this method, but this set-up is a prototype and i plan on replicating this more times that's why a database would be better suited to collect the data and allow me to display it all in one place. – Carl Steel May 25 '18 at 07:19