Hi
i have 8 custom code, all are in python, with mysql request.
all work fine, but sometime 1, or 2 or more of the code crash. sometime all.
My question is:
If a custom code not succeed, what append ?
autopi don’t care ? after X time go to sleep if so ? did I need to put a special code a the end like “break” or other code to ignore the error, and try the next cron job execute to do it again and again ?
another question:
If there is no connexion because 3/4 G connexion is bad, in country side for exemple, what append to atop ? go to sleep ? what is the delay ?
I am sorry to say that, and it may be depends of your needs, but i think you should use the classic implementation of the dongle & autopi.
I think, but correct me if i am wrong, you just want to get the pos of your dongle/car.
So, to do that, my advice should be to get a webserver, with kind of php or thing like that to receive the datas.
You should create an api nammed http/myWebsite/logbook/storage
In this page, you will take parse the data message sended from the dongle and connect to your db to save datas.
Why to do that? Because in case of connection error, the dongle will keep the data in cache and will try again until it succeed.
Hope it will help…
ok, thanks… but I try a lots of time to do that… I only succeed to have json data but was unable to do more. I am not a specialist of php and other code lol
so, i use python code, more simple for me, not the good way I know…
So the failure cases include failure to connect to the database and failure to read data from the car. I suppose in either case the script can’t complete its job, so not much point in letting it continue.
Maybe -
import mysql.connector
log = logging.getLogger(__name__)
def sendin():
try:
connection = mysql.connector.connect(host='xx.xx.xx.xxx', database='xxxxx', user='xxxxxxxx', password='xxxxxxx')
except:
log.warn('Unable to connect to database')
return
try:
tempin = get_tempin()
except:
log.warn('Unable to read data from car')
return
try:
sql_insert_query = """ INSERT INTO temp_in (tempin) VALUES (%s)"""
cursor = connection.cursor()
result = cursor.execute(sql_insert_query,(tempin,))
connection.commit()
except:
log.warn('Unable to update database')
return