Ok thank you for your usefull answers,
i have an other critical problem too
this is full of my python code
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import socket
import os
import threading
import mysql.connector
import time
import datetime
import requests
import sys
#
Dconn = mysql.connector.connect(user='root',password='aaaaa',host='aaaaa',database='aaaa',charset='utf8',autocommit=True)
cursor = Dconn.cursor(buffered=True)
cursor2 = Dconn.cursor(buffered=True)
print('databased stablished.')
def sendData(protocol,server,port,sig):
print((str(datetime.datetime.now()))+' -> ( '+format(protocol)+' ) '+format(server)+':'+format(port)+' - dbId : '+format(sig[0])+' tId : '+threading.current_thread().name)
cursor2.execute("select * from raw join devices on devices.dvid=raw.device where raw.rdid='"+format(sig[1])+"' limit 1;")
sendSig = cursor2.fetchone()
# print(sendSig)
timedata = datetime.datetime.fromtimestamp(int(sendSig[12]))
devimei = sendSig[18]
devdate = timedata.strftime("%d%m%y")
devtime = timedata.strftime("%H%M%S")
lat= format(sendSig[2])
lon= format(sendSig[3])
satcount = format(sendSig[5])
speed = format(sendSig[4])
batery = format(sendSig[8])
band = format(sendSig[10])
if protocol=='tcp':
try:
sistr='$MGV002,'+devimei+',12345,S,'+devdate+','+devtime+',A,'+lat+',N,'+lon+',E,0,'+satcount+',00,1.95,'+speed+',0,,,432,35,0,0,5,,,,,,,,,0'+band+','+batery+',Timer;!'
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = clientsocket.connect((server,port))
# clientsocket.settimeout(4)
clientsocket.send(sistr)
data = clientsocket.recv(1024)
print(str(datetime.datetime.now())+' -> send completed :'+format(sig[0]))
clientsocket.close()
except:
print(str(datetime.datetime.now())+' -> connection to tcp server failed!!')
elif protocol=='http':
try:
sistr='***'+devimei+';123;'+devdate+';'+devtime+';'+lat+';N;'+lon+';E;'+speed+';NA;159;'+satcount+';NA;5;'+batery+';[inputs];[outputs];[adc];[ibutton];[params];***'
#r = requests.post(server, data={'action': 'update','dev': 'log','ver': '1','val': sistr})
#r = requests.post(server+'&data='+sistr, data={})
r = requests.post('http://psimap.ir/WBSRV.php?action=update&dev=log&ver=1&data='+sistr, data={})
print(str(datetime.datetime.now())+ ' -> Send completed :'+format(sig[0])+' | Response:'+format(r.text))
except:
print(str(datetime.datetime.now())+' -> connection to http server failed!!')
try:
sqlobject = "UPDATE `row_sent` SET `send_date`=CURRENT_TIMESTAMP WHERE `rsid`='"+format(sig[0])+"' limit 1;"
cursor2.execute(sqlobject)
except:
print(str(datetime.datetime.now())+' -> database rid!!')
sys.exit(1)
#main
while True:
cursor.execute("select * from row_sent join servers on servers.sid = row_sent.server_id where result='pending' order by rsid DESC limit 1;")
if cursor.rowcount>0 :
waitedSig = cursor.fetchone()
sqlobject2 = "UPDATE `row_sent` SET `result`='succes' WHERE `rsid`='"+ format(waitedSig[0]) +"' limit 1;"
cursor.execute(sqlobject2)
time.sleep(0.2)
t = threading.Thread(target=sendData , args=((waitedSig[8]),(waitedSig[9]),(waitedSig[10]),(waitedSig),))
t.start()
time.sleep(0.5)
else:
time.sleep(1)
the script working good at all
read records from database and send data to gurtam server
but sometimes it crashes with out any error and until i run it again manually it dont send anything to gurtam!!
is there in problem in gurtam side?!
is there any solution or useful trick to avoid script break!!?