How to do that the best way?
How to autostart and run the script every 5 seconds? (i read something from a rs232 device)
I want to write some values every 5 seconds to a postgresql database and for this is it ok to open the database connection every 5 seconds and close it or can it be stay opend?
thanks in advance
I think the best way is to have a constantly running script that reads the value, sends to db, and sleeps for the remainer of the interval and keep the connection open. This way you can monitor and react if a read, write or both take too long for example. And then to have a separate script just to check if the main one is alive and notify you or restart the main one. I had some success with this model when reading from a bitcoin exchange api and inserting into mariadb every 6 seconds
Best and most efficient way to execute a Python script at Raspberry Pi (Raspbian Buster) every 5 seconds and store in PostgreSQL?